In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to set JAVA_HOME in Ubuntu". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to set up JAVA_HOME in Ubuntu" can help you solve the problem.
The value of JAVA_HOME is the directory where Java is located. Some Java software and some Java tools need to use this variable. When setting PATH and CLASSPATH, you can also use this variable to facilitate setting.
Step 1: check whether JDK has been installed
The easiest way to check that the Java Development Kit (JDK) is installed on your Linux system is to run this command:
Javac-version
The above command checks the version of the Java compiler. If the Java compiler is already installed, it displays the Java version:
If the above command displays an error message that the javac command was not found like this, you have to install JDK first:
If you do not have a Java compiler installed on your system, use this command to install the Java Development Kit (JDK):
Sudo apt install default-jdk
This will install the default Java version in your current Ubuntu version. If you need some other version of Java, you must specify the version of Java when you install it in Ubuntu.
After you make sure that the Java compiler exists on your system, it's time to find its location.
Step 2: get the location of the JDK executable file (Java compiler)
Executable files are usually located in the / usr/lib/jvm directory. But I won't let you play a guessing game, let's find out the path to the Java executable.
Use the which command to get the location of the Java compiler executable:
Which javac
The problem here is that the location it gives is actually a symbolic link. You will need to follow the following figure several times:
The easiest way is to follow the symbolic link directly using the following command to get the actual executable file:
Readlink-f `which java`
The readlink command follows a symbolic link. Using readlink on the outside of which java will replace the symbolic link to be checked with the output of which java, which is called command substitution. Therefore, in this example, the above command is roughly equivalent to readlink-f / usr/bin/java.
In my example, the location of the executable is / usr/lib/jvm/java-11-openjdk-amd64/bin/java. It might be different for you. On your system, copy the correct path obtained by the above command. You know, you can copy and paste in the Ubuntu terminal.
Step 3: set the JAVA_HOME variable
Now that you have the location, use it to set the JAVA_HOME environment variable:
Export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/bin/java
Check the values of the JAVA_HOME directory:
Echo $JAVA_HOME
Try running your Java program or project on the same terminal and see if it works.
It's not over yet. The JAVA_HOME environment variable you just declared is temporary. If you close this terminal or start a new session, it will become empty again.
To set the JAVA_HOME variable "permanently", you should add it to the .bashrc file in your home directory.
You can use the Nano editor in the Linux terminal to edit the file. If you don't want to use it and want to take a simple copy and paste method, use the following command:
Back up your .bashrc file first (in case you break it, you can restore it again):
Cp / .bashrc ~ / .bashrc.bak
Next, use the echo command to append the export command used at the beginning of this section. You should change the following command appropriately so that it uses the path shown by your system correctly.
Echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/bin/java" > > ~ / .bashrc
Verify that it has been correctly added to the end of the file:
Tail-3 ~ / .bashrc
The above tail command displays the last three lines of the specified file.
Here is the full output of the above three commands:
Now, even if you exit the session or restart the system, the JAVA_HOME environment variable will still be set to the value you specified. That's what you want, right?
Note that if you change the default Java version in the future, you will need to change the value of the JAVA_HOME environment variable and point it to the correct path to the executable.
This is the end of the introduction on "how to set up JAVA_HOME for Ubuntu". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.