Install Java on CentOS

Install Oracle Java

1, install curl

sudo yum install curl

2, install Oracle Java

curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/jdk-8u162-linux-x64.rpm
sudo yum localinstall jdk-8u162-linux-x64.rpm

3, check the default Java version

java -version

4, if you have multiple Java versions installed, you can choose the default version by the following codes

First, type the following line

sudo alternatives --config java

The output should be something like the following:

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/java/jdk1.8.0_162/jre/bin/java
   2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/bin/java)
   3           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.0.el7_4.x86_64/jre/bin/java)
*+ 4           /usr/java/jdk-9.0.4/bin/java

Enter to keep the current selection[+], or type selection number:

You can type the selection number for the default Java version you want to use.

猜你喜欢

转载自blog.csdn.net/qq_25527791/article/details/88060103