Install Java 17 (OpenJDK 17) on Amazon Linux 2

Posted on 218 views

The most frequently used object-oriented programming language is Java. Java is popular and frequently utilized because of its security features. Many Java aficionados utilize it for various purposes. We can create a wide range of apps using Java, including corporate applications, network applications, desktop applications, online applications, and many others.

Uses of Java Programming Language

The following apps may be created with Java technology:

  • Web-based Applications
  • Gaming Applications
  • Big Data Technologies
  • Distributed Applications
  • IoT Applications
  • Mobile App Development
  • Desktop GUI Applications
  • Cloud-based Applications

In this tutorial, we are going to cover how to Install Java 17 (OpenJDK 17) on Amazon Linux 2. Oracle released Java 17 LTS on September 14, 2021, which is the most recent long-term support update for the Java SE platform. Under the Oracle No-Fee Terms and Conditions License, JDK 17 binaries are free to use in production and redistribute at no cost.

New Features in Java 17

Java 17 have the following features:

  • In response to Apple’s plan to move its Macintosh machines from x64 to AArch64, the JDK was ported to MacOS/AArch64.
  • JDK internals are well-encapsulated.
  • Deserialization filters that are context-specific.
  • Remove the AOT and JIT Compiler Experiments.
  • Other classes and interfaces are not allowed to extend or implement sealed classes and interfaces.
  • The Remote Method Invocation (RMI) Activation method has been removed.
  • Applet API is being phased out.
  • Java applications may interact with code and data outside of the Java runtime using the foreign function and memory API.

Install Java 17 (OpenJDK 17) on Amazon Linux 2

There are two methods of installing Java 17 on Amazon Linux 2:

  1. Install OpenJDK 17
  2. Install Java SE Development Kit 17 (JDK 17)

Method 1: Install OpenJDK 17 on Amazon Linux 2

The GNU General Public License version 2 applies to OpenJDK, which is a free and open-source implementation of the Java Platform, Standard Edition.

To get the most recent archive, go to the JDK 17 releases page.


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

tar xvf openjdk-17_linux-x64_bin.tar.gz

Place the resultant folder in the /opt directory.

sudo mv jdk-17 /opt/

Now, configure Java environment:

sudo tee /etc/profile.d/ <

Source your profile file:

source /etc/profile.d/

Check the java command JAVA_HOME:

$ echo $JAVA_HOME

Confirm Java version:

$ java -version
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment (build 17+35-2724)
OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)

Method 2: Install Java SE Development Kit 17 (JDK 17) on Amazon Linux 2

Visit JDK 17 Download page to download .rpm file for installation.

wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie"

Now, install the file with .rpm extension:

$ sudo rpm -Uvh jdk-17_linux-x64_bin.rpm 
warning: jdk-17_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk-17-2000:17-ga                ################################# [100%]

Confirm Java version installed:

$ java -version
java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

Configuring Java 17 (OpenJDK 17) on Amazon Linux 2

Configure Java 17 as follows.

Setting Java Default Version

If you have different JDK versions installed, you may change your default Java as follows.

sudo alternatives --list
sudo alternatives --config java

Select Java version to use as default:

$ sudo alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
*+ 1           /usr/java/jdk-17/bin/java
   2           /usr/java/jdk-11.0.12/bin/java

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

This will change the system’s Java binary to the one you’ve chosen, i.e. Java 11. Because java and javac are handled separately, do the same for them.

sudo alternatives --config javac

Test Java installation on Amazon Linux 2

To test Java 17, we’ll create a Hello World program.

cat > <Hello World!");


Run the code as follows:

$ java
Hello World!


Finally, Java 17 is installed on the Amazon Linux 2 server. We hope you found this tutorial to be useful. Java coding is a lot of fun.


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