Switch with CentOS7 series + JDK-9.0.1 + JDK1.8.0 + alternatives

Introduction

environment

--ASCIIux7 (* Equivalent to CentOS 7.2) * Introduced a trial version to WinPC to easily try things that cannot be tried in the guest OS and production environment. --Windows10 Professional * Host OS

Purpose of this article

I came up with a JDK installation to make a little program in java. I want to use the latest java9 version, but I also want to include java8 for insurance so that it can be easily switched. I've used alternatives before, so I'll post it as a reminder when working while remembering.

About alternatives

This command allows you to manage and switch between multiple versions of software and multiple software with the same functions.

Reference URL

All you have to do is look at the following sites and work (you don't need this article). Many thanks. Java version control with CentOS alternatives

I have the impression that there are not many sites that explain alternatives in detail, but the following documents of VINE LINUX (RPM series) are detailed. Switching standard commands with alternatives

Work memo

Download the JDK

Drop it from the Oracle site. If you want to get it with wget, the method described in the above reference URL is good (although I have not tried it). I downloaded it on the host OS (Windows10pro) and uploaded it to the guest OS (linux) with WinSCP.

Download it referring to the capture. Oracle Technology Network/Java/Java SE/Downloads

image.png

Check the license terms and click the file. This time, I downloaded jdk-9.0.1_linux-x64_bin.rpm and jdk-8u152-linux-x64.rpm.

image.png

JDK installation

I worked as root. I put the rpm file directly under / root.

rpm file confirmation


[root@asianux7 ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  jdk-8u152-linux-x64.rpm  jdk-9.0.1_linux-x64_bin.rpm

Install by adding -i to the rpm command and specifying the file name.

:JDK-9.0.1 installation


[root@asianux7 ~]# rpm -ihv /root/jdk-9.0.1_linux-x64_bin.rpm
Preparing...              ################################# [100%]
Updating/During installation...
   1:jdk-9.0.1-2000:9.0.1-ga          ################################# [100%]
Unpacking JAR files...
        plugin.jar...
        javaws.jar...
        deploy.jar...

:JDK1.8.0 installation


[root@asianux7 ~]# rpm -ihv /root/jdk-8u152-linux-x64.rpm
Preparing...              ################################# [100%]
Updating/During installation...
   1:jdk1.8-2000:1.8.0_152-fcs        ################################# [100%]
Unpacking JAR files...
        tools.jar...
        plugin.jar...
        javaws.jar...
        deploy.jar...
        rt.jar...
        jsse.jar...
        charsets.jar...
        localedata.jar...

You now have both versions of the JDK directory.

Confirm installation destination


[root@asianux7 ~]# ls /usr/java/
default/      jdk-9.0.1/    jdk1.8.0_152/ latest/

Register java in alternatives

Register each version of java so that you can switch with alternatives. The last 1 and 2 are priorities. This time, java9 was ranked first. This ranking is meaningful in auto mode. In manual mode, the specified version will be the current version.

alternatives registration


[root@asianux7 ~]# alternatives --install /usr/bin/java java /usr/java/jdk-9.0.1/bin/java 1
[root@asianux7 ~]# alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_152/bin/java 2

Check the list of java versions registered in alternatives and the current java version. The version with + is the current version.

List of versions, check current version


[root@asianux7 ~]# alternatives --config java

There are 5 programs'java'To provide.

Select command
-----------------------------------------------
   1           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.151-2.6.11.1.el7_4.x86_64/jre/bin/java)
*  2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/java)
 + 3           /usr/java/jdk-9.0.1/bin/java
   4           /usr/java/jdk1.8.0_152/jre/bin/java
   5           /usr/java/jdk1.8.0_152/bin/java

Press Enter to select the current[+]Or enter the selection number:
[root@asianux7 ~]# java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

Remove the indigenous people (openjdk) and jre that you do not plan to use from the list of alternatives.

Remove openjdk, jre from list


[root@asianux7 ~]# alternatives --remove java /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.151-2.6.11.1.el7_4.x86_64/jre/bin/java
[root@asianux7 ~]# alternatives --remove java /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/java
[root@asianux7 ~]# alternatives --remove java /usr/java/jdk1.8.0_152/jre/bin/java

I feel refreshed.

List of versions


[root@asianux7 ~]# alternatives --config java

There are 2 programs'java'To provide.

Select command
-----------------------------------------------
*  1           /usr/java/jdk1.8.0_152/bin/java
 + 2           /usr/java/jdk-9.0.1/bin/java

Press Enter to select the current[+]Or enter the selection number:

Switching java_home

java_home can also be switched between java9 series and java8 series.

[root@asianux7 ~]# alternatives --install /usr/local/java_home java_home /usr/java/jdk-9.0.1 1
[root@asianux7 ~]# alternatives --install /usr/local/java_home java_home /usr/java/jdk1.8.0_152 2
[root@asianux7 ~]# alternatives --config java_home

There are 2 programs'java_home'To provide.

Select command
-----------------------------------------------
   1           /usr/java/jdk-9.0.1
*+ 2           /usr/java/jdk1.8.0_152

Press Enter to select the current[+]Or enter the selection number:

Check if java_home is created.

java_Home confirmation


[root@asianux7 ~]# ls /usr/local/java_home/
COPYRIGHT  README.html                         THIRDPARTYLICENSEREADME.txt  db       javafx-src.zip  lib  release
LICENSE    THIRDPARTYLICENSEREADME-JAVAFX.txt  bin                          include  jre             man  src.zip
[root@asianux7 ~]# /usr/local/java_home/bin/java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

Since the java version of java_home is 1.8.0, switch the version.

java_Home version switching


[root@asianux7 ~]# alternatives --config java_home

There are 2 programs'java_home'To provide.

Select command
-----------------------------------------------
   1           /usr/java/jdk-9.0.1
*+ 2           /usr/java/jdk1.8.0_152

Press Enter to select the current[+]Or enter the selection number:1 ←※`1`Specify

Make sure that the java version of java_home is 9.0.1.

java_Checking the java version of home


[root@asianux7 ~]# alternatives --config java_home

There are 2 programs'java_home'To provide.

Select command
-----------------------------------------------
 + 1           /usr/java/jdk-9.0.1
*  2           /usr/java/jdk1.8.0_152

Press Enter to select the current[+]Or enter the selection number:
[root@asianux7 ~]# /usr/local/java_home/bin/java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

Register the JAVA_HOME environment variable in /etc/profile.d/ if necessary.

JAVA_HOME environment variables


[root@asianux7 ~]# echo 'export JAVA_HOME=/usr/local/java_home' >> /etc/profile.d/jdk.sh

in conclusion

The alternatives command is not dedicated to java but general purpose, so I would like to try other software if I have a chance.

Recommended Posts

Switch with CentOS7 series + JDK-9.0.1 + JDK1.8.0 + alternatives
Switch versions with alternatives after yum install java
Use CentOS with LXD
Switch between JDK 7 and JDK 8
Build Growai with Centos7
Build softether VPN with Centos7.
Install Oracle JDK 8 with Ansible
Prepare Python3 environment with CentOS7
Seasonal display with Java switch