Install JDK in CentOS
Step 1: Check whether the built-in JDK of Linux is installed (uninstall centOS 1.6 installed)
The installed CentOS comes with OpenJdk and uses the java-version command. The following information is displayed:
Java version "1.6.0"
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)
It is best to uninstall openjdk first and install the jdk of sun.
Check rpm-qa | grep java first
The following information is displayed: (the information displayed for different versions is different)
Java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5
Uninstall: (uninstall different "packages" in red based on different information)
Rpm-e -- nodepsjava-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Rpm-e -- nodepsjava-1.6.0-openjdk-1.6.0.0-1.7.b09.el5
There are other commands
Rpm-qa | grep gcj
Rpm-qa | grep jdk
If openjdk source cannot be found, you can uninstall it like this.
Yum-y remove java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Yum-y remove java java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5
<1> # rpm-qa | grep jdk plugin to view jdk information or directly execute
Or
# Rpm-q jdk
Or
# Java-version
<2> # rpm-qa | grep gcj release confirm the gcj version number
<3> # yum-y remove java-1.4.2-gcj-compat uninstall gcj
Step 2: Install JDK
<1> download jdk-8u65-linux-x64.gz from sun.
Create a java folder under/usr and put the installation package in the/usr/java directory.
# Mkdir/usr/java
<2> install JDK
# Cd/usr/java
(1)decompress jdk-8u65-linux-x64.gz
Gunzipjdk-8u65-linux-x64.gz
If the folder is not displayed, try another decompressed command: tar.
Step 3: Configure Environment Variables
<1> # vi/etc/profile
<2> Add the following lines at the end:
Export JAVA_HOME =/usr/java/jdk1.8.0 _ 65
Export CLASSPATH =.: $ JAVA_HOME/jre/lib/rt. jar: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar
Export PATH = $ PATH: $ JAVA_HOME/bin
<3> # reboot restart restarts the machine and the configuration takes effect.
Running java and javac shows the same information as running java and javac in windows. If running java-version shows the information of openjdk, uninstall openjdk,
Check rpm-qa | grep java first
The following information is displayed: (the information displayed for different versions is different)
Java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5
Uninstall: (uninstall different "packages" in red based on different information)
Rpm-e -- nodepsjava-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Rpm-e -- nodepsjava-1.6.0-openjdk-1.6.0.0-1.7.b09.el5
Run javac. It is sun's jdk version.