madhusudanlive logo
Stay Zen!

Java 17 Installation Guide for Linux in 2 Ways

Install Java 17 on any Linux distribution in 2 ways using package manager as well as a tarball with this step by step installation guide, update your JAVA_HOME and PATH environment variables.
Banner that has a logo of java and reads 'install java 17 with ease'

Hello guys, today in this tutorial, we will cover how to install the Java 17 JDK on your machine in two different ways, this installation guide covers the steps for all the Linux distros Fedora, Debian, or Ubuntu.

Java is a popular programming language and Java 17 is a latest LTS (Long Term Support) version of it, installing java 17 JDK or Java development kit will allow you to use the new features introduced in the java 17.

This tutorial is specifically for Java 17 - OpenJDK 17, I'll explain each command in brief, and provide the necessary information, so let's open your terminals and get started.

How to install Java 17?

let's start by checking if Java is installed already, as there might be multiple versions of Java but the default is set to some other version, so we will check what versions of Java are installed in the system already.

open the terminal and run the following command to list the installed Java versions

update-alternatives --config java

This will list the installed Java versions as shown in the screenshot below.

Screenshot of update-alternatives command showing java versions
Screenshot of update-alternatives command showing java versions

The 3rd entry in this screenshot is java 17 (*+ 3 /usr/lib/jvm/jdk-17-oracle-x64/bin/java), if this is the case for you, then java 17 is already installed on your machine, but not set as default, to make it default, just enter the number in front of the java 17 entry and its done, but if you don't find any such entries, then follow this guide.

For Fedora/Redhat-based Linux OS

  • Download the JDK:
    run the following command in the terminal to download the latest Java 17 JDK
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
  • Install the downloaded RPM binary:
    You might need the superuser rights to execute the following command
sudo rpm -Uvh jdk-17_linux-x64_bin.rpm
  • Add/update the JAVA_HOME and PATH environment variables:
    The following command also needs superuser privileges, this command sets the JAVA_HOME variable and updates the PATH environment variable
cat <<EOF | sudo tee /etc/profile.d/jdk.sh
> export JAVA_HOME=/usr/java/default
> export PATH=$PATH:$JAVA_HOME/bin
> EOF
  • Source the newly created jdk.sh:
    to ensure the environment variables are set properly
source /etc/profile.d/jdk.sh
  • Update the default java executable:
    now run the following command again to verify the installation
update-alternatives --config java

type the number in front of the Java 17 entry and hit enter, in my case, it's 3 so I'll enter 3.

Screenshot of update-alternatives command showing java versions
Screenshot of update-alternatives command showing java versions
  • Verify the Installation:
    Lastly, check the Java version by running the following command
java -version
Screenshot: java -version command output showing java 17 installed
Screenshot: java -version command output showing java 17 installed

Congratulations, you've installed Java 17 on your system.

For Ubuntu-based OS

  • Update the packages repository:
    execute the following command to update the list of packages
sudo apt update
  • Install Java 17 by OpenJDK you need superuser access to run the following command
sudo apt install openjdk-17-jdk
  • Verify the Installation:
    Lastly, check the Java version by running the following command
java -version

Manual method - Non root

You can install Java 17 on your system, even without the root access, follow these steps to set up the Java 17 without superuser access in manual mode, in this approach we will download the tarball (.tar.gz, .tar) and set the environment variables to match our extracted tarball location, this method works for any directory with write access.

  • Navigate to a directory with write access:
    switch to a path where you would like to have your Java 17 installed, e.g.
cd ~/Desktop/setups
  • Download the Java 17 tarball
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
  • Extract the tarball
tar -xvzf jdk-17_linux-x64_bin.tar.gz
  • Set the environment variables:
    make sure to replace the ~/Desktop/setups with your actual JDK installation path
export JAVA_HOME=~/Desktop/setups/jdk-17_linux-x64_bin
export PATH=$PATH:$JAVA_HOME/bin
  • Verify the Installation:
    At last, verify the Java version by running the following command
java -version

conclusion

Java 17 can be installed easily with or without superuser access by following this step-by-step guide on your Linux machines, also the default versions can be managed by using the update-alternatives command to easily switch between different java versions.

Frequently Asked Questions:

  • How to install Java 17?

    Java 17 can be installed by following this easy to understand tutorial, just follow the steps based on your system and install the OpenJDK 17 on your machine, you can also install the Java 17 without superuser access.

  • What is the latest Java LTS Version?

    Java 17 is the latest LTS (Long Term Support) Version of the popular programming language Java.

Prev article Top 33 Best VS Code Extensions for Web Developers in 2024Next article Arduino UNO Features Explained: Shields, IDE: Nano, ESP32

photo of Madhusudan Babar
Say Hello

Thanks for visiting my site, if you have any questions or just want to say hello, feel free to reach out to me. You can also mail me directly at krypton@madhusudan.live