Install JDK under Linux and configure environment variables

Source: Internet
Author: User

Check JDK version, uninstall OPENJDK version (JDK and openjdk differences do not repeat here)

Check the java–version, javac–version command view version first (figure I)

After checking JDK version 1.7.0.45; then enter Rpm-qa|grep Java view (figure II)

Note: The OPENJDK version installed in different CentOS versions may differ; If there are no listings, look at step 4th directly.

Uninstall the above three files (requires root, login root to uninstall) (Figure III)

RPM-E--nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64

RPM-E--nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64

RPM-E--nodeps Tzdata-java-2013g-1.el6.noarch

View JDK information again (Figure IV)

You are now ready to install the Oracle version of the JDK.

or direct command download:

[Root@vm_16_4_centos home]# wget--no-check-certificate--no-cookies--header "cookie:oraclelicense= Accept-securebackup-cookie "http://download.oracle.com/otn-pub/java/jdk/8u162-b12/ 0da788060d494f5095bf8624735fa2f1/jdk-8u162-linux-x64.tar.gz

Extract JDK, extract command: Tar-xvzf jdk-7u25-linux-x64.tar.gz

JDK location:/home/codebrother/jdk/jdk-7u25-linux-x64.tar.gz, after the current path decompression, decompression, will appear JDK folder, access to the JDK directory, and view the contents of the content (such as Figure V)

Configuring JDK Environment variables

In a Linux system, you need to add the JDK's Bin directory in path, create Classpath, and add the JDK's lib directory.

Home directory for JDK:/home/codebrother/jdk/jdk1.7.0_25

JDK's Bin directory:/home/codebrother/jdk/jdk1.7.0_25/bin

Lib directory for JDK:/home/codebrother/jdk/jdk1.7.0_25/lib

Edit ~/.BASHRC File

Command:

VI ~/.BASHRC

Add the following variables (Figure VI)

Export java_home=/home/codebrother/jdk/jdk1.7.0_25
export java_bin= $JAVA _home/bin
Export java_lib= $JAVA _ Home/lib
export classpath=.: $JAVA _lib/tools.jar: $JAVA _lib/dt.jar
export path= $JAVA _bin: $PATH

Press ESC, and then: Wq Save exit

Make JDK environment variables effective, source ~/.BASHRC (Figure Seven)

View JDK version

Enter Java-version, javac-version (Figure Eight)

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.