How to install Java on Linux step by step

Last update: 25/06/2025
Author Isaac
  • Java can be easily installed on different distributions of Linux using your package manager.
  • There are different versions of Java: JRE for running applications and JDK for developing them.
  • Ubuntu, Debian, Fedora, and Arch Linux have specific methods for installing Java.
  • It is essential to correctly configure JAVA_HOME and verify the installation after completion.

java linux

Installing Java on Linux may seem complicated if it's your first time, but the truth is that, with the right steps, it's a quick and easy process. Whether you need Java to run applications or plan to develop software, having it properly installed and configured on your Linux system is key to avoiding errors and optimizing performance.

In this updated and detailed guide we explain How to install Java on Linux step by step, covering the most common distributions such as Ubuntu, Debian, Fedora, and Arch Linux. We also teach you how to choose between JRE and JDK, configure environment variables such as JAVA_HOME and select the default version if you have several installed.

What is Java and why do you need it on Linux?

Java is a language of programming object oriented widely used for its ability to run on multiple platforms. Thanks to the Java virtual machine (JVM), applications developed in this language can run on virtually any operating system, including Linux.

It is essential for programs like Apache Tomcat, Jenkins, Minecraft, Cassandra, Jetty and many others. Whether you're running or developing these applications, you need to install Java on your Linux distribution.

Package Types: JRE and JDK

Before installing Java, it is important to know that there are two main options:

  • JRE (Java Runtime Environment): Contains everything needed to run Java applications, but does not include development tools such as the compiler.
  • JDK (Java Development Kit): In addition to the JRE, these versions include everything needed to compile, debug, and develop Java software.

If you're just going to run programs, the JRE is sufficient. But if you're going to write Java code, you'll need the JDK.

  Find out how to turn off Autocorrect on iPhone and iPad

Install Java on Ubuntu and Debian

These two distributions share the package system APT, which makes installation easier.

Update repositories

Start by running these commands in the terminal To make sure you have the latest versions available:

sudo apt update
sudo apt upgrade

Install the default JRE

To install the basic runtime environment:

sudo apt install default-jre

Install the default JDK

If you are going to develop programs in Java:

sudo apt install default-jdk

Install a specific version of OpenJDK

To see the available versions:

apt search openjdk

You can then install, for example, Java 11 with:

sudo apt install openjdk-11-jdk

Installing the Oracle JDK

Oracle Java offers extended support and is required by some commercial applications. To install it, you must do so manually:

    1. Download the file .tar.gz from the official Oracle website.
    2. Upload it to your server using scp or a client like FileZilla:
scp jdk-version_linux-x64_bin.tar.gz usuario@IP:/tmp
    1. Extract the file:
tar -xzf jdk-version_linux-x64_bin.tar.gz
    1. Move the JDK folder to a permanent location:
sudo mv jdk-version /usr/lib/jvm/oracle-jdk-version

Install Java on Fedora

In Fedora the manager is used DNFTo install Java 17, currently recommended:

sudo dnf install java-17-openjdk

For the JDK:

sudo dnf install java-17-openjdk-devel

Install Java on Arch Linux

Arch Linux makes it easy to install different versions of Java from its repositories:

For the JRE:

sudo pacman -S jre-openjdk

For the JDK:

sudo pacman -S jdk-openjdk

Verify the installation

After installing Java, check that it works:

To see the Java version:

java -version

To view the Java compiler version:

javac -version

If you see something like openjdk version «17.0.2», everything is correct.

Choosing which Java version to use by default

On systems with multiple versions you can select the default with:

sudo update-alternatives --config java

You can also do it with other commands like javac, javadoc, keytool, etc.

Configure JAVA_HOME

Many tools like Maven require you to have the variable defined JAVA_HOME.

  21 Practical Ways to Save Money Fast

Find the installation path

Check where Java is installed using:

sudo update-alternatives --config java

You will see routes like /usr/lib/jvm/java-17-openjdk-amd64.

Setting JAVA_HOME for a user

Edit your file .bashrc:

nano ~/.bashrc

At the end he adds:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

Save and apply the changes:

source ~/.bashrc

Set JAVA_HOME system-wide

sudo nano /etc/environment

Add this line (adjusts the path):

JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"

Apply the changes:

source /etc/environment

How to remove or update Java

To update Java:

sudo apt update && sudo apt upgrade

To remove a specific installation:

sudo apt remove openjdk-17-jdk

And if you want to delete the settings too:

sudo apt purge openjdk-17-jdk

Installing Java on Linux isn't a complicated task, but it's important to understand the steps and differences between versions. In this article, we've gathered all the relevant information so you can easily install Java on Debian, Ubuntu, Fedora, and Arch Linux. We'll also show you how to properly configure the JAVA_HOME variable and select the version you want as the default. With this, you're ready to run or develop any Java application on your Linux system.

what-version-of-java-do-i-have
Related article:
Don't Know Which Java Version You Have? Find Out Which One Here

Leave a comment