sammlinux sammlinux
  • Ubuntu
    UbuntuShow More
    How To Install and Use Docker CE on Ubuntu 22.04
    26 Min Read
    How To Install and Secure phpMyAdmin on Ubuntu 22.04
    5 Min Read
    How To Secure SSH with Fail2Ban on Ubuntu 22.04
    8 Min Read
    How To Install Uptime Kuma on Ubuntu 22.04
    17 Min Read
    How To Install Ubuntu Server 22.04 LTS with Screenshots
    14 Min Read
  • Rocky Linux
    Rocky LinuxShow More
    How To Install phpMyAdmin on Rocky Linux 9
    15 Min Read
    How To Secure SSH with Fail2Ban on Rocky Linux 9
    12 Min Read
    How To Install Rocky Linux 9.2 Server with Screenshots
    12 Min Read
    How To Set Up a Firewall Using FirewallD on Rocky Linux 9
    8 Min Read
    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide
    10 Min Read
  • Debian
    DebianShow More
    How To Secure SSH with Fail2Ban on Debian 11
    8 Min Read
    How To Install Debian 11 (Bullseye) Server with Pictures
    12 Min Read
    How To Install and Setup Node.js on Debian 11
    6 Min Read
    How To Install PHP 8.2 on Debian 11
    12 Min Read
    How To Install Nginx on Debian 11: A Comprehensive Guide
    9 Min Read
  • Linux
    LinuxShow More
    Best Practices Linux Server Security for System Administrator
    8 Min Read
    A Simple Guide: How To Manage Groups on Linux
    5 Min Read
    How To Manage Log Files Using Logrotate In Linux
    7 Min Read
    The Easy Ways to Check File Size in Linux
    7 Min Read
    How To Backup Files From Remote Linux VPS Using Rsync Script
    12 Min Read
  • CentOS
    CentOSShow More
    How To Secure SSH with Fail2Ban on CentOS 7
    9 Min Read
    How To Install PHP 8.2 on CentOS 7 / RHEL 7
    18 Min Read
    How To Install Apache Web Server on CentOS 7
    11 Min Read
    How To Set Up a Firewall Using FirewallD on CentOS 7
    5 Min Read
    Initial Setup CentOS 7 Server: Secure and Efficient
    9 Min Read
  • DevOps
    DevOpsShow More
    How To Create AWS CloudFront: A Step-by-Step Guide
    10 Min Read
Reading: How To Install Java Using OpenJDK 17 on Ubuntu 22.04
Share
Font ResizerAa
Linux for BeginnersLinux for Beginners
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Search
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.

How To Install Java Using OpenJDK 17 on Ubuntu 22.04

Samuel Siahaan
By Samuel Siahaan
Last updated: April 3, 2023
SHARE

Introduction

Java is a widely-used and versatile programming language that powers numerous applications, from enterprise software to Android apps. Installing the latest version of Java ensures optimal performance, security, and access to the latest features. OpenJDK, an open-source implementation of the Java Platform, offers a reliable choice for Java development. This article will provide you with a step-by-step guide on how to install Java using OpenJDK 17 on Ubuntu 22.04, enabling you to harness the power of Java for your projects.

Contents
IntroductionTable of ContentsUnderstanding the Importance of JavaPrerequisitesInstall Java on Ubuntu 22.04Step 1: System UpdateStep 2: Install Java on Ubuntu 22.04Method 1: Install OpenJDK 17 with Ubuntu RepositoryMethod 2: Install OpenJDK 17 ManuallyStep 3: Set Default Java Version on Ubuntu 22.04Conclusion

Table of Contents

  • Introduction
  • Understanding the Importance of Java
  • Prerequisites
  • Install Java on Ubuntu 22.04
    • Step 1: System Update
    • Step 2: Install Java on Ubuntu 22.04
      • Method 1: Install OpenJDK 17 with Ubuntu Repository
      • Method 2: Install OpenJDK 17 Manually
    • Step 3: Set Default Java Version on Ubuntu 22.04
  • Conclusion

Understanding the Importance of Java

Java’s significance in the world of software development cannot be overstated. It’s a versatile language known for its platform independence and extensive libraries, making it suitable for applications ranging from web development to enterprise systems. OpenJDK, the open-source alternative to Oracle’s Java Development Kit (JDK), ensures a reliable and flexible development environment.

To develop and run Java applications, you need the Java Development Kit (JDK), which includes tools like the Java compiler (javac) for converting Java source code into bytecode and the Java Runtime Environment (JRE) to run Java applications on a computer. The JDK and JRE are available for different operating systems, including Windows, macOS, and various flavors of Linux.

Prerequisites

Below are the prerequisites for installing Java on Ubuntu 22.04.

- Advertisement -
  • A Ubuntu Server 22.04.
  • A non-root user account with sudo privileges set up on your system. You can learn how to do this by following the Initial Server Setup Guide with Ubuntu 22.04 tutorial.

Install Java on Ubuntu 22.04

Now that you’ve met the prerequisites, let’s delve into the installation process:

Step 1: System Update

Before installing OpenJDK, updating Ubuntu to ensure all system packages are current with the “apt update” command is essential. This helps to prevent any potential conflicts during the installation process. To update your Ubuntu system, run the following command in your terminal:

samm@java:~$ sudo apt update
samm@java:~$ sudo apt upgrade

Step 2: Install Java on Ubuntu 22.04

There are two main options for installing Java.

  • Method 1 – Install OpenJDK 17 with Ubuntu Repository
  • Method 2 – Install OpenJDK 17 Manually

Right off the bat, log into your server instance via SSH. To verify if Java is installed, run the following command:

samm@java:~$ java -version
Command 'java' not found, but can be installed with:
sudo apt install default-jre              # version 2:1.11-72build2, or
sudo apt install openjdk-11-jre-headless  # version 11.0.20+8-1ubuntu1~22.04
sudo apt install openjdk-17-jre-headless  # version 17.0.8+7-1~22.04
sudo apt install openjdk-18-jre-headless  # version 18.0.2+9-2~22.04
sudo apt install openjdk-19-jre-headless  # version 19.0.2+7-0ubuntu3~22.04
sudo apt install openjdk-8-jre-headless   # version 8u382-ga-1~22.04.1

The output clearly indicates that Java is not installed. In addition, you get a few suggestions on how to install Java.

- Advertisement -

As you have seen, there are multiple ways of installing Java. However, we recommend the installation of OpenJDK (Open Java Development Kit).

Method 1: Install OpenJDK 17 with Ubuntu Repository

The first and most recommended method for installing OpenJDK is through the default Ubuntu repository. You can search for available packages using the “grep” command. To do this, run the following command in your terminal:

samm@java:~$ apt-cache search openjdk | grep openjdk-17

Output :

- Advertisement -
openjdk-17-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-17-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-17-doc - OpenJDK Development Kit (JDK) documentation
openjdk-17-jdk - OpenJDK Development Kit (JDK)
openjdk-17-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-17-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-17-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-17-jre-zero - Alternative JVM for OpenJDK, using Zero
openjdk-17-source - OpenJDK Development Kit (JDK) source files

Depending on your version of Ubuntu, you may be able to install OpenJDK 17 JDE and JRE using the following command.

This is only applicable if these packages are available in your distribution. The easiest and quickest way is installation OpenJDK 17 on Ubuntu 22.04

samm@java:~$ sudo apt install openjdk-17-jdk

For JRE run the following commands to install

samm@java:~$ sudo apt install openjdk-17-jre

Check Java version to validate a successful installation:

samm@java:~$ java --version

Output:

openjdk 17.0.8 2023-07-18
OpenJDK Runtime Environment (build 17.0.8+7-Ubuntu-122.04)
OpenJDK 64-Bit Server VM (build 17.0.8+7-Ubuntu-122.04, mixed mode, sharing)

Updates are handled with the standard apt update and upgrade commands. However, you can remove them separately or altogether if you no longer require JDK or JRE.

samm@java:~$ sudo apt remove openjdk-17-jre openjdk-17-jdk --purge

Note : This will remove any unrequited leftover dependencies and thoroughly wipe the installation and data as much as possible from your system.

Method 2: Install OpenJDK 17 Manually

Java OpenJDK 17 is an open-source implementation of the Java SE platform. Since the OpenJDK versions available in the default repositories are not up to date, we will have to download the Open-source JDK 17 using the wget command.

Here’s an example of downloading OpenJDK 17 version 17.0.2 for x64 (however, it is recommended to obtain a new link from the downloads page rather than copying this example):

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

Process downloading:

Resolving download.java.net (download.java.net)... 23.207.184.97
Connecting to download.java.net (download.java.net)|23.207.184.97|: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.tar.g 100%[================================================================>] 178.37M  5.81MB/s    in 30s     

2023-08-08 04:31:11 (5.99 MB/s) - ‘openjdk-17.0.2_linux-x64_bin.tar.gz’ saved [187033144/187033144]

Once the download process is complete, extrac the downloaded tarball.

samm@java:~$ tar xvf openjdk-17.0.2_linux-x64_bin.tar.gz

Next, navigate to the directory.

samm@java:~$ cd jdk-17.0.2/

Run the following command to install the OpenJDK 17 files.

samm@java:~/jdk-17.0.2$ sudo mkdir -p /usr/local/openjdk-17
samm@java:~/jdk-17.0.2$ sudo mv * /usr/local/openjdk-17

The next step is to set up the environment variables by adding the following lines to your .bashrc or .bash_profile file.

export JAVA_HOME=/usr/local/openjdk-17
export PATH=$JAVA_HOME/bin:$PATH

Source the .bashrc or .bash_profile file to apply the changes.

samm@java:~/jdk-17.0.2$ source ~/.bashrc

To verify that the installation was successful, run the following command.

samm@java:~$ echo $JAVA_HOME

Output:

/usr/local/openjdk-17

After the installation, verify the active version of OpenJDK using the following command:

samm@java:~$ java --version

Output:

openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

Step 3: Set Default Java Version on Ubuntu 22.04

Setting the default Java version applies in instances where you have multiple Java versions installed on your system.

First, you need to list all the available versions.

samm@java:~$ sudo update-alternatives --config java

Output:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-17-openjdk-amd64/bin/java   1711      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      manual mode
  2            /usr/lib/jvm/java-17-openjdk-amd64/bin/java   1711      manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

As shown in the previous output, Java 17 is listed with the number “2”. To switch to this version, type the following and press the enter key and you should see a similar printout:

update-alternatives: using /usr/lib/jvm/java-17-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode

Once the switch is complete, you can verify the default version using the following command.

samm@java:~$ java --version

Output:

openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

To switch to any other installed versions, repeat the same process.

Conclusion

In conclusion, Java remains a cornerstone of modern software development, powering a vast array of applications. With OpenJDK 17, you have access to the latest advancements in the Java language. This guide has walked you through the installation process on Ubuntu 22.04, providing you with a solid foundation for your Java development journey. By successfully installing Java using OpenJDK 17, you’re now equipped to create, innovate, and contribute to the world of technology.

Also Read Our Other Guides :

  • How To Install Jenkins on Ubuntu Server 22.04
  • How To Install and Use TeamViewer on Ubuntu 22.04
  • How To Install Vagrant on Ubuntu 22.04
  • How To Install VirtualBox 7.0 on Ubuntu 22.04
  • How To Install Python 3.11 from Source on Ubuntu 22.04

Finally, now you have learned how to Install Java using OpenJDK 17 on Ubuntu 22.04.

TAGGED:JavaOpenJDKOracleProgramming LanguageUbuntu

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article How To Install Vagrant on Ubuntu 22.04
Next Article How To Install VirtualBox 7.0 on Ubuntu 22.04
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

How To Install and Secure phpMyAdmin on Ubuntu 22.04
Ubuntu
Install and Configure Docker Swarm Mode on Centos 7
CentOS
How To Install and Config Thumbor on Debian 10
Debian
How To Install MariaDB 10.6 on Debian 11 Server
Debian
How To Install MongoDB 6.0 on Debian 10 & 11
Debian

You Might Also Like

Ubuntu

How To Install Node.js on Ubuntu 22.04 With 3 Different Ways

20 Min Read
Ubuntu

How To Install Vagrant on Ubuntu 22.04

8 Min Read
Ubuntu

How To Secure SSH with Fail2Ban on Ubuntu 22.04

8 Min Read
Ubuntu

How To Install Snipe-IT Asset Management on Ubuntu 22.04

13 Min Read
Ubuntu

How To Install DBeaver Community on Ubuntu 22.04

7 Min Read
Rocky Linux

How To Install PHP 8.2 on Rocky Linux 9

9 Min Read
Ubuntu

How To Install MySQL 8.0 on Ubuntu Server 22.04

20 Min Read
CentOS

How To Install PHP 8.2 on CentOS 7 / RHEL 7

18 Min Read
Show More

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

sammlinux sammlinux

Providing beginner-friendly Linux tutorials and open-source guides to simplify your digital infrastructure.

www.sammlinux.com © 2026 | All Rights Reserved

Join Us!
Subscribe to our newsletter and never miss our latest news, podcasts etc.

Subscribe to our newsletter to get our newest articles instantly!

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?