Java is a popular, object-oriented, class-based programming language that was first released in 1995. It is a high-level language that allows developers to write portable code that can run on any device with a Java Virtual Machine (JVM) installed. Over the years, Java has become one of the world’s most widely used programming languages, with millions of developers utilizing it for various applications.
Java 17 is a long-term release of the Java programming language and was released in September 2021. This release includes several new features and improvements, including:
- Improved Performance and Security: OpenJDK 17 includes optimizations and security enhancements to enhance overall performance and better protection against malicious attacks. This makes it a more reliable and secure platform for developing and deploying applications.
- Improved Tooling and Developer Productivity: OpenJDK 17 includes several enhancements to the tools and libraries available to developers, making it easier to build and debug applications. This results in increased efficiency and improved developer productivity.
- Enhanced Support for Functional Programming: OpenJDK 17 introduces new features that make it easier for developers to write functional code, such as improved support for functional interfaces and the ability to use lambda expressions more effectively.
- Improved Support for Concurrent Programming: OpenJDK 17 includes several new features that make it easier for developers to write multi-threaded applications, such as improved support for atomic operations and better handling of synchronization.
- Enhanced Support for Modular Programming: OpenJDK 17 includes several enhancements to the Java Platform Module System (JPMS), making it easier for developers to build and manage modular applications. This results in improved code organization and better management of dependencies.
- Improved Support for Type Inference: OpenJDK 17 introduces new features that allow developers to write more concisely and easier to read, such as improved type inference and better handling of generics.
- Enhanced Support for Garbage Collection: OpenJDK 17 includes several enhancements to the garbage collector, making it more efficient and reducing the impact of garbage collection on application performance.
- Improved Support for Records: OpenJDK 17 introduces new features that make it easier for developers to write and manage records, such as improved support for pattern matching and improved handling of record components.
- Enhanced Support for Sealed Classes: OpenJDK 17 includes several enhancements to the support for sealed classes, making it easier for developers to define and manage the visibility of class members.
- Enhanced Support for Pattern Matching: OpenJDK 17 introduces new features that make it easier for developers to write code that uses pattern matching, such as improved support for instanceof and improved handling of patterns.
In this guide, you will discover two different methods for installing OpenJDK 17 (Java 17) on Ubuntu 22.04 Jammy Jellyfish LTS or Ubuntu 20.04 Focal Fossa. Whether you prefer to use the command line terminal or another method, this tutorial will provide the steps you need to install OpenJDK 17 on your Ubuntu system successfully.
For users wishing to install the Oracle Java 17 (JDK) version, please see the guide on How to Install Java 17 on Ubuntu 22.04 or 20.04.
Table of Contents
Before proceeding with the installation of OpenJDK, updating Ubuntu to ensure that 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:
sudo apt update && sudo apt upgrade
Method 1: Install OpenJDK 17 with Ubuntu Repository
The first and most recommended method for installing OpenJDK is through the default Ubuntu repository. To begin, you can search for available packages using the “grep” command. To do this, run the following command in your terminal:
apt-cache search openjdk | grep openjdk-17
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:
sudo apt install openjdk-17-jre
sudo apt install openjdk-17-jdk
Confirm the installation by running the following command.
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.
sudo apt remove openjdk-17-jre openjdk-17-jdk --purge
Note that 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 Manual Method
The second method for installing OpenJDK 17 is downloading the .tar.gz archive package. While this option is often more up-to-date than the version in the Ubuntu repository, it requires more manual maintenance, as you’ll need to keep an eye on new updates and repeat the installation process.
Visit the downloads page to obtain the latest build version link. Then, use the following wget command to download the package.
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):
Once the download process is complete, extracting the archive is next.
tar -xvf openjdk-17.*
Next, navigate to the directory.
Run the following command to install the OpenJDK 17 files.
sudo mkdir -p /usr/local/openjdk-17 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.
To verify that the installation was successful, run the following command.
java --version echo $JAVA_HOME
If installed correctly, you should see the following output:
As demonstrated, the version displayed is the latest OpenJDK 17 build.
Switching Alternative Java Versions
After installing Java, you may want to check for newer versions and switch to them if necessary. To do this, use the following command to list the available alternatives:
sudo update-alternatives --config java
As shown in the previous output, Java 11 is listed with the number “1”. 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-11-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.
To switch to any other installed versions, repeat the same process.
In conclusion, installing OpenJDK 17 on Ubuntu is a straightforward process that can be accomplished through a few different methods. Whether you use the default Ubuntu repository, download the .tar.gz archive package, or switch to a different version, the steps outlined in this article will help you successfully install and manage OpenJDK 17 on your Ubuntu system.
FAQs on Installing OpenJDK 17 on Ubuntu
Q: What is OpenJDK 17?
A: OpenJDK 17 is a popular open-source Java Development Kit (JDK) implementation. It is the latest version of the Java programming language, released in September 2021.
Q: Why should I install OpenJDK 17 on Ubuntu?
A: Installing OpenJDK 17 on Ubuntu provides access tomanyf applications and libraries built with Java and many popular tools and frameworks that require Java to be installed to run correctly. Additionally, OpenJDK 17 includes several new features and improvements that enhance the functionality and performance of the Java programming language.
Q: How can I switch to a different version of Java after installing OpenJDK 17?
A: To switch to a different version of Java after installing OpenJDK 17, you can use the update-alternatives command in the terminal. This command allows you to list the available alternatives and switch between them.
Q: Is it necessary to update Ubuntu before installing OpenJDK 17?
A: Yes, it is recommended to update Ubuntu before installing OpenJDK 17 to avoid any potential conflicts during the installation process.
Q: What are some of the new features and improvements in OpenJDK 17?
A: Some of the new features and improvements included in OpenJDK 17 are improved performance and security, enhanced support for functional programming, improved support for concurrent programming, enhanced support for modular programming, and improved support for type inference.
Q: What is the difference between OpenJDK and Oracle JDK?
A: OpenJDK is an open-source implementation of the Java Development Kit (JDK), while Oracle JDK is the official, commercially-supported version of the JDK from Oracle. OpenJDK is free to use and distribute, while Oracle JDK requires a commercial license for use in production environments.
Q: Can I use OpenJDK for commercial purposes?
A: Yes, OpenJDK is free and open-source software that can be used for commercial purposes.
Q: What are the system requirements for installing OpenJDK 17 on Ubuntu?
A: The system requirements for installing OpenJDK 17 on Ubuntu include a 64-bit Ubuntu system with at least 2 GB of RAM and 4 GB of storage.
Q: Is OpenJDK compatible with other programming languages?
A: Yes, OpenJDK is compatible with other programming languages and can be used to build applications in various programming languages, including Java, Scala, and Kotlin.
Q: Can I use OpenJDK 17 to run Java applications on Windows or macOS?
A: Yes, OpenJDK 17 can be installed on Windows or macOS and can be used to run Java applications on those platforms.
Q: What is the Java Virtual Machine (JVM)?
A: The Java Virtual Machine (JVM) is an abstract computing machine that enables a computer to run Java applications. The JVM interprets compiled Java code and executes it on the computer, and the JVM is required to run Java applications on any device.
Q: Is OpenJDK an LTS release like Java 17?
No, the OpenJDK team does not push long-term support compared to Oracle, with Java 17 for the most part. Typically using OpenJDK, you need to keep upgrading to the latest release.