Java is one of the highly used programming languages in the world. AdoptOpenJDK, also known as Eclipse Temurin is an open-source Java founded in 2017 following a lengthy discussion over the lack of an open-source and test system for OpenJDK. The Eclipse Adoptium group took this task with the main objective of producing a high-quality, TCK-certified technology and runtimes to be used across the Java ecosystem. Ever since its production, AdoptOpenJDK has grown immensely and is now the leading provider of OpenJDK-based binaries which can be used on desktops, modern cloud platforms, traditional servers, enterprises embedded systems, or even mainframes. This success has been achieved through multiple projects as well as a close partnership with external projects i.e OpenJDK to provide the required Java SE runtime implementation.
The AdoptOpenJDK can be installed on various platforms such as Windows,macOS, Linux, and many others. This guide takes an in-depth illustration of how to install Temurin OpenJDK 17 on CentOS 7| RHEL 7 | Oracle Linux 7
Getting Started.
Update your system packages to the latest stable versions.
sudo yum update -y
Install the required package and reboot the system for the changes made to apply.
sudo yum -y install wget curl
1 – Download the Temurin OpenJDK 17 Binary
To download the Temurin OpenJDK 17 binary file, visit the Adoptium downloads page. You can as well choose to pull the binary using Wget as shown.
wget https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_x64_linux_hotspot_17.0.2_8.tar.gz
Once the download is successful, extract the archive.
tar -xvf OpenJDK17U-jdk_x64_linux_hotspot_17.*.tar.gz
rm -f OpenJDK17U-jdk_x64_linux_hotspot_17.*.tar.gz
2 – Install Temurin OpenJDK 17 on CentOS 7| RHEL 7 | Oracle Linux 7
To install Temurin OpenJDK 17, we will simply move the extracted file above to the /opt/ directory.
sudo mv jdk-17.* /opt/jdk-17
Set the JAVA_HOME environment variables as below.
$ vi ~/.bashrc
export JAVA_HOME=/opt/jdk-17
export PATH=$PATH:$JAVA_HOME/bin
Souce the profile.
source ~/.bashrc
Verify the set PATH.
$ echo $JAVA_HOME
/opt/jdk-17
That is it, you have installed Temurin OpenJDK 17 on CentOS 7| RHEL 7 | Oracle Linux 7. Verify your installation using the command below.
$ java --version
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)
Set a Persistent JAVA_HOME Environment Variable.
Setting the JAVA_HOME Environment Variable using the above method is not persistent and is lost on system reboot. However, you can make this persistent by adding the PATH to /etc/profile
$ sudo vi /etc/profile
export JAVA_HOME=/opt/jdk-17
export PATH=$PATH:$JAVA_HOME/bin
Apply the made changes by either logging out then logging in again or sourcing the profile.
source /etc/profile
Verify the set PATH.
$ echo $JAVA_HOME
/opt/jdk-17
3 – Set Default Java Version On CentOS 7| RHEL 7 | Oracle Linux 7
With multiple Java versions installed on your system, you need to set a default Java version to be used when running Java applications.
First, add the Temurin OpenJDK 17 to the /usr/bin/java path.
sudo alternatives --install /usr/bin/java java /opt/jdk-17/bin/java 1
List the available Java installations.
sudo alternatives --config java
Sample output:
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.14.0.9-1.el7_9.x86_64/bin/java)
2 /opt/jdk-17/bin/java
Enter to keep the current selection[+], or type selection number: 2
We have set the default java to Temurin OpenJDK 17. Verify this as below.
$ java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)
4 – Test Temurin OpenJDK 17
Once installed, we need to verify if the Java installation is working correctly. We will create a sample file as below.
cat > HelloWorld.java <<EOF
public class helloworld {
public static void main(String[] args) {
System.out.println("Hello Java World from Kenya! Temurin OpenJDK is amazing!");
}
}
EOF
This is a sample HelloWorld application. Compile it as below.
java HelloWorld.java
Execution output:
$ java HelloWorld.java
Hello Java World from Kenya! Temurin OpenJDK is amazing!
That is it!
I hope this guide on how to install Temurin OpenJDK 17 on CentOS 7| RHEL 7 | Oracle Linux 7 was impactful.
See more on this page:
- 登录 发表评论