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.
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
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: 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
- Verify the Installation: Lastly, check the Java version by running the following command
java -version
Screenshot of java -version command output
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.
- 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.
Arduino UNO Features Explained: Shields, IDE: Nano, ESP32
Tags:
howto, linux, cli, installation
Top comments (0)