Mike Slinn

Installing JDK 17 on Ubuntu

Published 2023-09-28.
Time to read: 1 minutes.

This page is part of the posts collection, categorized under Java, Ubuntu.

The Java Development Kit (JDK) version 17 is compatible with v11 and v8. Installing the JDK also installs the JRE, as you can see from the highlighted dependency shown below:

Shell
$ apt show -a openjdk-17-jdk
Package: openjdk-17-jdk
  Version: 17.0.8.1+1~us1-0ubuntu1~23.04
  Priority: optional
  Section: java
  Source: openjdk-17
  Origin: Ubuntu
  Maintainer: Ubuntu Developers 
  Original-Maintainer: OpenJDK Team 
  Bugs: https://bugs.launchpad.net/ubuntu/+filebug
  Installed-Size: 1544 kB
  Provides: java-compiler, java-sdk (= 17), java10-sdk, java11-sdk, java12-sdk, java13-sdk, java14-sdk, java15-sdk, java16-sdk, java17-sdk, java2-sdk, java5-sdk, java6-sdk, java7-sdk, java8-sdk, java9-sdk
  Depends: openjdk-17-jre (= 17.0.8.1+1~us1-0ubuntu1~23.04), openjdk-17-jdk-headless (= 17.0.8.1+1~us1-0ubuntu1~23.04), libc6 (>= 2.34), zlib1g (>= 1:1.1.4)
  Recommends: libxt-dev
  Suggests: openjdk-17-demo, openjdk-17-source, visualvm
  Homepage: https://openjdk.java.net/
  Download-Size: 1486 kB
  APT-Sources: http://archive.ubuntu.com/ubuntu lunar-updates/main amd64 Packages
  Description: OpenJDK Development Kit (JDK)
    OpenJDK is a development environment for building applications,
    applets, and components using the Java programming language.
Package: openjdk-17-jdk Version: 17.0.6+10-1ubuntu2 Priority: optional Section: java Source: openjdk-17 Origin: Ubuntu Maintainer: Ubuntu Developers Original-Maintainer: OpenJDK Team Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 4732 kB Provides: java-compiler, java-sdk, java10-sdk, java11-sdk, java12-sdk, java13-sdk, java14-sdk, java15-sdk, java16-sdk, java17-sdk, java2-sdk, java5-sdk, java6-sdk, java7-sdk, java8-sdk, java9-sdk Depends: openjdk-17-jre (= 17.0.6+10-1ubuntu2), openjdk-17-jdk-headless (= 17.0.6+10-1ubuntu2), libc6 (>= 2.34) Recommends: libxt-dev Suggests: openjdk-17-demo, openjdk-17-source, visualvm Homepage: https://openjdk.java.net/ Download-Size: 4585 kB APT-Sources: http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages Description: OpenJDK Development Kit (JDK) OpenJDK is a development environment for building applications, applets, and components using the Java programming language.

Install OpenJDK 17 and its dependencies:

Shell
$ yes | sudo apt install openjdk-17-jdk

Setting the Default Java Version

The man page for update-java-alternatives is:

Shell
$ man update-java-alternatives
UPDATE-JAVA-ALTERNATIVESystem Manager's MUPDATE-JAVA-ALTERNATIVES(8)
NAME update-java-alternatives - update alternatives for jre/sdk installations
SYNOPSIS update-java-alternatives [--jre] [--plugin] [-v|--verbose] -l|--list [<jname>] -s|--set <jname> -a|--auto -h|-?|--help
DESCRIPTION update-java-alternatives updates all alternatives belonging to one runtime or development kit for the Java language. A package does provide these information of it's alternatives in /usr/lib/jvm/.<jname>.jinfo.
OPTIONS -l|--list [<jname>] List all installed packages (or just <jname>) provid‐ ing information to set a bunch of java alternatives. Verbose output shows each alternative provided by the packages.
-a|--auto Switch all alternatives of registered jre/sdk instal‐ lations to automatic mode.
-s|--set <jname> Set all alternatives of the registered jre/sdk instal‐ lation to the program path provided by the <jname> in‐ stallation.
--jre Limit the actions to alternatives belong to a runtime environment, not a development kit.
--jre-headless Limit the actions to alternatives belong to the head‐ less part of a runtime environment.
--plugin Limit the actions to alternatives providing browser plugins.
-h|--help Display a help message.
-v|--verbose Verbose output.
FILES /usr/lib/jvm/.*.jinfo A text file describing a jre/sdk installation. Con‐ sists of some variables of the form <var>=<value> and a list of alternatives of the form jre|jdk <name> <path>.
AUTHOR update-java-alternatives and this manual page was written by Matthias Klose <doko@ubuntu.com>.
May 2006 UPDATE-JAVA-ALTERNATIVES(8)

The above man page neglects to say that a package version’s priority is set from its version number. Thus a newer version would normally have a higher priority. To get a list of the installed Java versions, type:

Shell
$ sudo update-java-alternatives --list
java-1.11.0-openjdk-amd64      1111       /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.17.0-openjdk-amd64      1711       /usr/lib/jvm/java-1.17.0-openjdk-amd64 

As you can see, my machine had Java 11 and 17 installed. To set the newest version to be the default, type:

Shell
$ sudo update-java-alternatives -a

$ java -version
openjdk version "17.0.8.1" 2023-08-24
OpenJDK Runtime Environment (build 17.0.8.1+1-Ubuntu-0ubuntu123.04)
OpenJDK 64-Bit Server VM (build 17.0.8.1+1-Ubuntu-0ubuntu123.04, mixed mode, sharing) 
* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.