Install jdk in Ubuntu and configure the environment variables correctly.
As a beginner in Linux, jdk has been installed several times before writing this blog. Many times, it is caused by incorrect environment variable configuration, resulting in a failure to log on to the system. After several days of research, the new system is installed and configured from scratch.
System Version: Ubuntu 16.04
JDK version: JDK 1.8.0 _ 121
1.download the jdkfile jdk-8u121-linux-x64.tar.gz from the official website
The latest version is available for me. Other versions can also be used.
2. Create a directory as the JDK installation directory. My directory is/java
sudo mkdir /java
3. Move the file to the/java directory
sudo mv jdk-8u121-linux-x64.tar.gz /java
4. decompress the file
tar -zxvf jdk-8u121-linux-x64.tar.gz
5. Configure Environment Variables
sudo gedit /etc/environment
Add the following configuration at the end (the path after JAVA_HOME is the jdk file location)
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/libexport JAVA_HOME=/java/jdk1.8.0_121
Save and close after modification, and enter the following command to make the environment variable take effect immediately
source /etc/environment
6. Enter java-version to display the JDK version description. Congratulations, the environment variable is correctly configured.
7. But it is not over yet. According to the previous articles written by others, it is found that it cannot be used after each restart, so we still needConfigure environment variables for all users
sudo gedit /etc/profile
Add the following content at the end of the file:
#set Java environmentexport JAVA_HOME=/dengyang/jdk1.8.0_56export JRE_HOME=$JAVA_HOME/jreexport CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATHexport PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
8. Similarly, you must use commands to make the environment variables take effect immediately.
source /etc/profile
9. restart the computer and access the system normally. the java-version command is valid.