A memorandum when installing OpenJDK on CentOS7
It's the easiest because you just type the command. The installation destination is ``` / usr / lib / jrm /` ``. In addition, it is automatically registered in alternatives.
#java from yum repository-1.8.0-Search for openjdk packages
$ yum search java-1.8.0-openjdk
#Install OpenJDK runtime
$ sudo yum install java-1.8.0-openjdk
#Install OpenJDK development kit
$ sudo yum install java-1.8.0-openjdk-devel
This is a method of downloading and installing the rpm file from a distribution site, etc., and is effective when installation is not possible with the yum command, such as when the Internet is not connected (of course, downloading is done from a terminal connected to the Internet). However, depending on the installation environment, it may be necessary to install dependent packages other than Java in advance.
The rpm file is distributed at pkgs.org, so download it and then install it in the following order. Like the yum command, it is automatically registered in alternatives.
$ sudo rpm -ivh java-1.8.0-openjdk-headless-1.8.0.171-7.b10.el7.x86_64.rpm
$ sudo rpm -ivh java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64.rpm
$ sudo rpm -ivh java-1.8.0-openjdk-devel-1.8.0.181-3.b13.el7_5.x86_64.rpm
The rpm file can also be downloaded from the following.
For Java 9 or later, install from the OpenJDK binary file.
The binary file is published on jdk.java.net, so download and unzip it.
After decompressing, move it to any folder and register it in alternatives.
#Unzip the tar file
$ tar xzvf openjdk-11_linux-x64_bin.tar.gz
#Move to any folder
$ mv jdk-11 /usr/lib/java/
#Register the command to be used in alternatives
$ alternatives --install /usr/bin/java java /usr/lib/java/jdk-11/bin/java 1
$ alternatives --install /usr/bin/javac javac /usr/lib/java/jdk-11/bin/javac 1
If multiple versions are installed, you can switch the Java version to use with alternatives.
** java command **
#Confirm alternatives of java command&Change to the setting to use jdk11 by specifying "3"
$ alternatives --config java
There are 3 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.171-2.6.13.2.el7.x86_64/jre/bin/java)
*+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre/bin/java)
3 /usr/lib/java/jdk-11/bin/java
Press Enter to select the current[+]Or enter the selection number: 3
#Java version check
$ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
** javac command **
#Check alternatives for javac command&Change to the setting to use jdk11 by specifying "2"
$ alternatives --config javac
There are 2 programs'javac'To provide.
Select command
-----------------------------------------------
*+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/bin/javac)
2 /usr/lib/java/jdk-11/bin/javac
Press Enter to select the current[+]Or enter the selection number: 2
#Check javac version
$ javac -version
javac 11
Recommended Posts