Install jdk in Ubuntu and configure the environment variables correctly.

Source: Internet
Author: User

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.

  

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.