Install Java 17 On Linux in 2 Ways: Step-By-Step Guide
Tags: howto, linux, cli, installation
Published: 2024-01-27 19:16:09

---
title: Install Java 17 On Linux in 2 Ways: Step-By-Step Guide
published: true
date: 2024-01-26 03:47:00 UTC
tags: howto,linux,cli,installation
cover_image: https://res.cloudinary.com/krypt9/image/upload/f_avif,q_100,c_lfill,g_auto,w_1100,h_582/madhusudanlive/blog/java/install-java-17-with-ease.png
canonical_url: https://madhusudan.live/blog/install-java-17-in-linux-fedora-debian
---

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?](https://madhusudan.live/blog/install-java-17-in-linux-fedora-debian#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](https://res.cloudinary.com/krypt9/image/upload/f_avif,q_auto:good,c_lfill,g_auto,w_2400/madhusudanlive/blog/java/update-alternatives-command.png "Screenshot of update-alternatives command")
_Screenshot of update-alternatives command_

<meta itemprop="name" content="Madhusudan Babar">

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](https://madhusudan.live/blog/install-java-17-in-linux-fedora-debian#for-fedoraredhat-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](https://res.cloudinary.com/krypt9/image/upload/f_avif,q_auto:good,c_lfill,g_auto,w_2400/madhusudanlive/blog/java/update-alternatives-command.png "Screenshot of update-alternatives command")
_Screenshot of update-alternatives command_

<meta itemprop="name" content="Madhusudan Babar">

- Verify the Installation:  
Lastly, check the Java version by running the following command

```
java -version
```

![Screenshot of java -version command output](https://res.cloudinary.com/krypt9/image/upload/f_avif,q_auto:good,c_lfill,g_auto,w_2400/madhusudanlive/blog/java/java-version-command-output.png "Screenshot of java -version command output")
_Screenshot of java -version command output_

<meta itemprop="name" content="Madhusudan Babar">

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

## [For Ubuntu-based OS](/blog/install-java-17-in-linux-fedora-debian#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](https://madhusudan.live/blog/install-java-17-in-linux-fedora-debian#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](https://madhusudan.live/blog/install-java-17-in-linux-fedora-debian#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:](https://madhusudan.live/blog/install-java-17-in-linux-fedora-debian#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](https://madhusudan.live/blog/what-is-arduino-uno-boards-ide-programming-esp32-esp8266)


Tags:
[howto](https://madhusudan.live/tag/howto), [linux](https://madhusudan.live/tag/linux), [cli](https://madhusudan.live/tag/cli), [installation](https://madhusudan.live/tag/installation)
<meta itemprop="keywords" content="howto, linux, cli, installation" data-v-9e55ded7=""><meta itemprop="about" content="howto, linux, cli, installation" data-v-9e55ded7="">