# Java 17 installation on Linux (CentOS 8) - openjdk 17

In 
Published 2022-12-22

This tutorial shows you how to install openjdk 17 on Linux. For this demo I have chosen CentOS 8.

There are 3 ways to install Java 17:

  1. using rpm command
  2. using dnf command
  3. unzipping a tar file

# Java 17 installation on Linux (CentOS 8) using rpm command

You can use this procedure to install the Java Development Kit (JDK) for 64-bit RPM-based Linux platforms, such as Red Hat and SuSE, using an RPM binary file (.rpm) in the system location.

This installation method is used when you have the rpm package, or you can download it from a specific location. This method is more used when we are using Oracle Java (licensed).

  • First, install wget and curl
  yum -y install wget curl (_curl_ is optional)
  • Download the needed rpm package in the current directory
  wget https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-x64_bin.rpm

and you will see something like that

 wget https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-x64_bin.rpm
 
--2022-12-22 19:02:32--  https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-x64_bin.rpm
Resolving download.oracle.com (download.oracle.com)... 2.20.97.99
Connecting to download.oracle.com (download.oracle.com)|2.20.97.99|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 163101336 (156M) [application/x-redhat-package-manager]
Saving to: ‘jdk-17.0.5_linux-x64_bin.rpm.1’

jdk-17.0.5_linux-x64_ 100%[======================>] 155.54M  11.1MB/s    in 14s

2022-12-22 19:02:46 (11.2 MB/s) - ‘jdk-17.0.5_linux-x64_bin.rpm.1’ saved [163101336/163101336]
  • Install Java 17 from the rpm package
  rpm -ivh jdk-17.0.5_linux-x64_bin.rpm

and you will see something like that :

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

You can check the version using java -version or java --version command :

java -version
java version "17.0.5" 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)
[root@linux1 jenkins]# java --version
java 17.0.5 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)

For this type of installation is good to double-check the license agreement.

For this installation, the Java uninstall operation is done by rpm -e jdk-17 command.

# Java 17 installation on Linux (CentOS 8) using dnf command

  • First, install wget and curl (curl is optional)
  yum -y install wget curl
  • Install OpenJDK 17
dnf -y install java-17-openjdk java-17-openjdk-devel

and you will see something like this :

dnf -y install java-17-openjdk java-17-openjdk-devel

Last metadata expiration check: 0:39:17 ago on Thu 22 Dec 2022 09:08:13 PM EET.
Dependencies resolved.
=====================================================================================
Package                  Arch   Version                             Repo       Size
=====================================================================================
Installing:
java-17-openjdk          x86_64 1:17.0.5.0.8-2.el8                  appstream 450 k
java-17-openjdk-devel    x86_64 1:17.0.5.0.8-2.el8                  appstream 5.1 M
Installing dependencies:
copy-jdk-configs         noarch 4.0-2.el8                           appstream  31 k
java-17-openjdk-headless x86_64 1:17.0.5.0.8-2.el8                  appstream  43 M
javapackages-filesystem  noarch 5.3.0-1.module_el8.0.0+11+5b8c10bd  appstream  30 k
lksctp-tools             x86_64 1.0.18-3.el8                        baseos    100 k
ttmkfdir                 x86_64 3.0.9-54.el8                        appstream  62 k
tzdata-java              noarch 2022d-1.el8                         appstream 186 k
xorg-x11-fonts-Type1     noarch 7.5-19.el8                          appstream 522 k

Transaction Summary
=====================================================================================
Install  9 Packages

Total download size: 50 M
Installed size: 207 M
Downloading Packages:
(1/9): copy-jdk-configs-4.0-2.el8.noarch.rpm         118 kB/s |  31 kB     00:00
(2/9): java-17-openjdk-17.0.5.0.8-2.el8.x86_64.rpm   1.5 MB/s | 450 kB     00:00
(3/9): javapackages-filesystem-5.3.0-1.module_el8.0. 448 kB/s |  30 kB     00:00
(4/9): ttmkfdir-3.0.9-54.el8.x86_64.rpm              1.0 MB/s |  62 kB     00:00
(5/9): tzdata-java-2022d-1.el8.noarch.rpm            1.5 MB/s | 186 kB     00:00
(6/9): xorg-x11-fonts-Type1-7.5-19.el8.noarch.rpm    2.1 MB/s | 522 kB     00:00
(7/9): lksctp-tools-1.0.18-3.el8.x86_64.rpm          706 kB/s | 100 kB     00:00
(8/9): java-17-openjdk-devel-17.0.5.0.8-2.el8.x86_64 4.5 MB/s | 5.1 MB     00:01
(9/9): java-17-openjdk-headless-17.0.5.0.8-2.el8.x86 2.0 MB/s |  43 MB     00:21
-------------------------------------------------------------------------------------
Total                                                2.1 MB/s |  50 MB     00:23
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Running scriptlet: copy-jdk-configs-4.0-2.el8.noarch                           1/1
Running scriptlet: java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64          1/1
Preparing        :                                                             1/1
Installing       : lksctp-tools-1.0.18-3.el8.x86_64                            1/9
Running scriptlet: lksctp-tools-1.0.18-3.el8.x86_64                            1/9
Installing       : tzdata-java-2022d-1.el8.noarch                              2/9
Installing       : ttmkfdir-3.0.9-54.el8.x86_64                                3/9
Installing       : xorg-x11-fonts-Type1-7.5-19.el8.noarch                      4/9
Running scriptlet: xorg-x11-fonts-Type1-7.5-19.el8.noarch                      4/9
Installing       : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10b   5/9
Installing       : copy-jdk-configs-4.0-2.el8.noarch                           6/9
Installing       : java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64          7/9
Running scriptlet: java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64          7/9
Installing       : java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64                   8/9
Running scriptlet: java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64                   8/9
Installing       : java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64             9/9
Running scriptlet: java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64             9/9
Running scriptlet: copy-jdk-configs-4.0-2.el8.noarch                           9/9
Running scriptlet: java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64          9/9
Running scriptlet: java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64                   9/9
Running scriptlet: java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64             9/9
Verifying        : copy-jdk-configs-4.0-2.el8.noarch                           1/9
Verifying        : java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64                   2/9
Verifying        : java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64             3/9
Verifying        : java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64          4/9
Verifying        : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10b   5/9
Verifying        : ttmkfdir-3.0.9-54.el8.x86_64                                6/9
Verifying        : tzdata-java-2022d-1.el8.noarch                              7/9
Verifying        : xorg-x11-fonts-Type1-7.5-19.el8.noarch                      8/9
Verifying        : lksctp-tools-1.0.18-3.el8.x86_64                            9/9

Installed:
copy-jdk-configs-4.0-2.el8.noarch
java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64
java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64
java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64
javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch
lksctp-tools-1.0.18-3.el8.x86_64
ttmkfdir-3.0.9-54.el8.x86_64
tzdata-java-2022d-1.el8.noarch
xorg-x11-fonts-Type1-7.5-19.el8.noarch

Complete!
  • You can check the version using java -version or java --version command.

You can set JAVA_HOME using the following command:

export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))

# Java 17 installation on Linux (CentOS 8) from a tar file

We have to choose a location or create a directory for the installation if we want to install Java using archive binaries (.tar.gz). The installation for a 32 bit or 64 bit version is the same, supposing we have downloaded the right version.

  • Create /u01/java folder where the installation will be done and go into that folder
mkdir -p /u01/java
cd /u01/java
  • You can download manually (from the browser) openjdk-17.0.2_linux-x64_bin.tar.gz file from Java archive official location, or we can use wget command to download it in the current directory.
wget https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz

We can see something like this :

wget https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz

--2022-12-22 20:18:06--  https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz
Resolving download.java.net (download.java.net)... 2.20.97.99
Connecting to download.java.net (download.java.net)|2.20.97.99|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 187033144 (178M) [application/x-gzip]
Saving to: ‘openjdk-17.0.2_linux-x64_bin.tar.gz’

openjdk-17.0.2_linux-x64_bin.t 100%[=================================================>] 178.37M  11.3MB/s    in 16s

2022-12-22 15:18:23 (10.9 MB/s) - ‘openjdk-17.0.2_linux-x64_bin.tar.gz’ saved [187033144/187033144]

In the current folder we have the openjdk-17.0.2_linux-x64_bin.tar.gz file.

  • Extract the Java JDK from archive
tar xvf openjdk-17.0.2_linux-x64_bin.tar.gz

In the current directory we will see jdk-17.0.2 directory which is the new Java Home directory.

Here are some related articles: