How To Install Temurin OpenJDK 17 on Amazon Linux 2

Posted on 128 views

About Java Programming Language

Java is an object-oriented language of programming with multiple levels of abstraction and the fewest possible operational needs. It is a general-purpose programming language that allows developers to write once and run anywhere, meaning that compiled Java code can run on any platform that supports Java without the need to recompile.

Eclipse Adoptium

The primary goal of Eclipse Adoptium is to create high-quality runtimes and associated technology for usage in the Java Ecosystem. Close collaboration with external projects such as OpenJDK, which provides the Java SE runtime implementation, has enabled this.

Following a lengthy discussion regarding the lack of an open-source and reproducible build and test system for OpenJDK across different platforms, the AdoptOpenJDK project was established in 2017. Adoptium Temurin OpenJDK has grown rapidly since then, eventually becoming the primary vendor of high-quality OpenJDK for enterprise systems, traditional servers, workstations, and even big mainframes. AdoptJDK provides binary files for installation on a variety of platforms, including Windows, Linux, macOS, and others.

We’ll step through the installation of the fantastic Adoptium Temurin OpenJDK 17 on Amazon Linux 2 in this tutorial.

Eclipse Adoptium Projects Uniqueness

The following distinguishes Eclipse Adoptium projects:

  • TCK Testing Infrastructure: A large-scale initiative aimed at ensuring conformity and interoperability by executing Java SE TCKs.
  • Development Kits and Runtimes: Accessible on a wide range of processor core and system software combinations, and supporting the APIs defined by different Java SE editions.
  • Techniques for getting and controlling the installation of runtime technologies include system local installers, container images, download servers, a webpage, and artifact repositories.
  • JDK Mission Control is a set of low-cost Java Virtual Machine monitoring and debugging tools.

Install Temurin OpenJDK 17 on Amazon Linux 2

Installing Temurin OpenJDK 17 on Amazon Linux 2 is outlined in the steps below.

Step 1- Update Amazon Linux 2

Ensure that all the Amazon Linux 2 system packages are up to date.

Run the following command to update the packages:

sudo yum update -y

Step 2- Install Temurin OpenJDK 17 on Amazon Linux 2

To get the newest Temurin OpenJDK 17 archive, go to the Temurin OpenJDK 17 page.

You may also run the following command from your Amazon Linux 2 terminal to download the archive:

sudo yum install wget
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

Using the tar command, extract the Temurin OpenJDK 17 archive file.

tar xzf OpenJDK17U-jdk_x64_linux_hotspot_17.0.2_8.tar.gz

Step 3- Configure Java Environment Variables

After extraction, move the resulting folder to the /opt directory.

sudo mv jdk-17.0.2+8/ /opt/jdk-17

Configure the Java environment now:

$ vim ~/.bashrc
export JAVA_HOME=/opt/jdk-17
export PATH=$PATH:$JAVA_HOME/bin 

Then source your profile file:

source ~/.bashrc

Check Java version Installed:

$ echo $JAVA_HOME
/opt/jdk-17

$ 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)

Step 4- Setting Java default version

To make AdoptJDK 17 the default Java version, first add it to the /usr/bin/java path:

sudo update-alternatives --install /usr/bin/java java /opt/jdk-17/bin/java 1

Then run the following command to set the Java version as the default:

$ sudo update-alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /opt/jdk-17/bin/java
 + 2           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.amzn2.0.3.x86_64/bin/java)

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

Select the version to set as the default version from the above output by entering the choice number as shown above.

Verify Java Version:

$ 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)

Step 5- Setting Global JAVA_HOME Environment Variable

Java applications utilize this path to figure out where Java is installed on your Amazon Linux 2 system and which version to use when executing Java apps.

Now, identify the Java Path.

$ whereis java
java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /opt/jdk-17/bin/java

By altering the file below, we will create a persistent path.

sudo vim /etc/profile

Add the following line to the file, giving the exact path where your Java is installed, i.e.

JAVA_HOME="/path/to/java/install"

The line will look like the following:

export JAVA_HOME=/opt/jdk-17
export PATH=$PATH:$JAVA_HOME/bin

Apply the modifications by logging out and back in to your system, or by using the source command as shown below.

source /etc/profile

Now, Verify the set PATH variable:

$ echo $JAVA_HOME
/opt/jdk-17

Test Temurin OpenJDK 17 on Amazon Linux 2

To test Temurin OpenJDK 17, we’ll write a Hello World program.

cat > hello_world.java <

Run the following code after that:

$ java hello_world.java
Hello World! I LOVE Using Temurin in my Development because it is very POWERFUL

Conclusion

Finally, you’ve successfully installed Temurin OpenJDK 17 on Amazon Linux 2. This tutorial should have taught you something new. It’s a lot of fun to code in Java. Enjoy!

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.