简体   繁体   中英

CentOS7: Setting default JAVA as Oracle JDK and not openJDK

I have a machine with CentOS7. The default Java is

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)

I want to change this to

java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

To do so, I have so far followed the steps as given below.

  1. Download jdk-8u212-linux-x64.tar.gz file

  2. I could not untar the above using tar -zxvf jdk-8u212-linux64.tar.gz to a specified directory. Hence I used 7-zip and the extracted the JDK1.8.0_212 folder and copied the same to /usr/lib/jvm

  3. Then I made the necessary changes at /etc/profile . There I set the JAVA_HOME as export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_212 and followed by export PATH=$PATH:$JAVA_HOME\\bin

However, when I typed update-alternatives --config java I could not see jdk1.8.0_212/bin/java as path. Instead I saw only openjdk options.

My question is: How to set my default Java as Oracle Java as mentioned above. The reason I am asking is I have found that sqljdbc4-x.jar is not compatible with openJDK. I have already raised a query here

A simple approach would be to first remove Open JDK using purge then install Oracle jdk..if u are using apt-get it would automatically set the necessary Java Paths.

Here is what I meant.

yum list java*
sudo yum -y remove java*
java -version
cd
mkdir tmp
cd tmp
curl -u uftp:uftp ftp://192.168.2.115/path/developer/jdk-8u151-linux-x64.tar.gz -o jdk-8u151-linux-x64.tar.gz
tar zxvf jdk-8u151-linux-x64.tar.gz
sudo mv jdk1.8.0_151 /usr/share/
sudo vim /etc/profile
#add
export JAVA_HOME=/usr/share/jdk1.8.0_151
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
source /etc/profile
java -version
which java

cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM