- Install Java on Linux It is simpler to use OpenJDK from the official repositories of each distribution.
- Choosing between JRE or JDK depends on whether you only want to run Java applications or also develop and compile code.
- Managing multiple Java versions and configuring JAVA_HOME correctly is key to ensuring the tools function without errors.
- Keeping Java updated and removing obsolete versions improves the security and stability of the Linux system.

If you work with servers, develop applications, or simply want to run a program written in Java, sooner or later you'll have to. Install Java on Linux and understand which version suits you bestIt's not uncommon to find some confusion between JRE, JDK, OpenJDK, Oracle, LTS versions, and so on, but once you look at it calmly, the process is simpler than it seems.
In this guide we'll see step by step how to install java on linux in the most common Linux distributions (Ubuntu, Debian, Fedora, Arch and others)How to check what you have installed, how to switch between versions, update, uninstall, and even how to properly configure the environment variable JAVA_HOMEThe idea is that you end up with your system ready both to run Java applications and to develop for, if you need to.
What is Java and why is it important in Linux?
java is a language of programming object-oriented, widely used, and cross-platformThat is, the same program can run on Linux, Windows or macOS without code changes, provided a Java virtual machine is installed. Thanks to this, it's used in everything from web servers to line tools. commands and desktop applications.
In Linux environments, Java is especially common in application servers, management tools, automation systems, and background servicesIt is also the basis of development Android traditional, so if you want to compile applications or work with certain build tools, you'll need a properly configured JDK.
To run or develop in Java, your system requires at least one component: the Java Runtime Environment or JRE, which includes the JVM and core librariesIf you're also going to program, compile, and debug code, you'll need the JDK or Java Development Kitwhich includes the JRE and additional utilities such as the compiler Javac.
Modern Linux distributions typically offer several versions of Java, many of them open source under the Java project. OpenJDKThis makes installing Java on Linux fairly straightforward using your distribution's package manager, although you can also opt for the Oracle JDK if certain applications require it.
Prerequisites before installing Java on Linux
Before you start installing anything, it's advisable that you have Some familiarity with the Linux command line and with using the terminalYou don't need to be a systems expert, but you do need to know how to navigate directories and execute commands. sudo and edit some basic configuration files.
It is also important to have a Linux system that you can access with administrative privilegesOn a server, this usually involves connecting via SSH (for example, using PuTTY from Windows) with a user who has permissions sudoOn desktop, your usual user account with administrator privileges will suffice.
If you're going to set up something serious or in production, it's best if the distribution is a Long Term Support (LTS) versions such as Ubuntu 22.04 or stable versions of Debian, Fedora, or othersThis ensures long-term security updates and compatibility for both the system and the Java versions you install.
It's not mandatory, but it's good to have basic notions of Java programming and understanding what a JRE and a JDK areThis will help you choose the correct edition to install depending on whether you plan to run pre-made programs or develop your own applications.
Check if Java is already installed on Linux
Before installing anything, the most sensible thing to do is Check if you already have a version of Java installed on your Linux systemOften, especially on servers, a version is already available because it is part of other dependencies.
To verify this, open a terminal and run the command java -versionSimply type it in and press [button name]. Enter and review the output displayed on the screen. If Java is installed, you should see the version and some additional information about the virtual machine.
Typical output might look something like this openjdk version «17…» o Java version "21.0.2" followed by the type of runtime environment (OpenJDK, Oracle, etc.) and the JVM mode. If you see a message like “command not found” or “java: no se encontré la comando”, it means that Java is not installed or is not in the path.
If you're going to compile code, you'll also want to check the compiler by running javac-versionThis lets you see if you have a JDK available or only the JRE. An error indicating that the program cannot be found means that There are no development tools installed.
Install Java 17 and other versions with OpenJDK on Linux
The option recommended today for most users is Install OpenJDK, which is the free and maintained implementation of Java.It is available in virtually all Linux distributions and is integrated through the official repositories, making installation and updates very simple.
Java 17 is one of the versions Most commonly used LTS (long-term support)This is especially important for servers and projects that require stability. We'll see how to install Java 17 and other versions of OpenJDK on different distributions: Ubuntu/Debian, Fedora, Arch Linux, and finally, what to do on other distributions.
Install Java (OpenJDK) on Debian and Ubuntu
In Debian, Ubuntu and derivatives (such as Linux Mint) the first thing is Update the package index to avoid outdated version problemsFrom the terminal, run:
Update: sudo apt update
sudo apt upgrade
The command sudo apt update It connects to the repositories configured on your system and downloads the latest list of available packages, without installing anything yet. Then, sudo apt upgrade It applies pending updates, improving system security and compatibility.
If you only want Run Java applications without developmentYou can install the default JRE with:
Install: sudo apt install default-jre
This package installs the standard Java runtime environment chosen by the distributionIt is typically an LTS version of OpenJDK. It includes the virtual machine (JVM) and the necessary libraries, more than enough to run Java servers, console tools, or other applications.
On the other hand, if you need Compile and develop Java applicationsYou're interested in installing the JDK. For the default version recommended by Ubuntu, use:
Install (JDK): sudo apt install default-jdk
With this package you get the OpenJDK JDK along with the JRE, the compiler JavacThe debugger and other essential development utilities are included. This is the simplest option to start with if you don't need a specific version.
If you want a specific version for compatibility with certain applications, you can search for available OpenJDK versions with:
Search: apt search openjdk
The command will display a list of packages like openjdk-11-jdk, openjdk-17-jdk, openjdk-21-jdketc. Once you identify the version you want, for example Java 11, you can install it like this:
Install (11): sudo apt install openjdk-11-jdk
The process will be similar for other versions, only changing the number in the package name. This way you can have multiple versions installed for different projects.
Install Java 17 on Fedora
In Fedora and other RPM-based distributions, the package manager used is dnfAs with Debian/Ubuntu, it is recommended Have your system more or less up to date before installing Javaalthough it is not strictly mandatory.
To install OpenJDK 17 on Fedora, you can use packages from the official repositories with a command like this:
dnf: sudo dnf install java-17-openjdk
If your server or computer doesn't need a graphical interface and you want to save resources, you can opt for the "Heavyless" version of Java 17 on Fedorawhich omits the libraries related to the graphics component (AWT, Swing, etc.). The package is usually called something like:
Version without GUI: sudo dnf install java-17-openjdk-headless
For development tasks, you'll probably prefer to install the full OpenJDK 17 JDK instead of just the runtime environmentThis will give you a compiler and additional tools. The package name is usually:
Development package: sudo dnf install java-17-openjdk-devel
Once the installation is complete, you can check the installed version with the command java -version And, if you installed the JDK, also with javac-versionFedora manages Java alternatives similarly to other distributions using version selection tools.
Installing Java 17 on Arch Linux
Arch Linux and its derivative distributions use pacman as a package manager and a rolling release or continuous update modelThis means that Java versions are usually quite up-to-date in the official repositories.
To install the OpenJDK JRE from the Arch Linux repositoriesA specific package is used for the chosen version. For example, for Java 17, the standard JRE could be installed with a command similar to:
pacman JRE: sudo pacman -S jre-openjdk
If your system is a server without a graphical environment and you want to reduce the memory footprint, you can opt for the "Headless" edition of the JRE in Arch Linuxwhich eliminates unnecessary graphical components and is designed for background services:
Pac-Man headless: sudo pacman -S jre17-openjdk-headless (the exact name may vary depending on the version available)
For those who are going to programming in Java, developing applications, or creating specific mods and utilitiesIdeally, you should install the JDK instead of the JRE. On Arch, this is done using the OpenJDK development package, for example:
Pacman JDK: sudo pacman -S jdk-openjdk
After installation, you can verify that everything is working correctly by running java -version y javac-versionIf multiple versions are installed, Arch allows you to adjust the default version using its alternatives management tools or by manually configuring the path.
Install Java on other Linux distributions
If your distribution isn't Ubuntu, Debian, Fedora, or Arch, don't worry: practically All distributions have OpenJDK packages in their official repositoriesThe process usually boils down to searching for “openjdk” in the corresponding package manager and choosing the desired version.
When repositories don't offer the version you need, or you want a different build, you can turn to projects like Adoptium (formerly AdoptOpenJDK), which publishes pre-compiled Java binaries for different platforms and architectures, ready to download and install manually.
From Adoptium it is possible to obtain the Latest JRE for your Linux system and appropriate architecture (x64, ARM, etc.) and follow their specific installation instructions. This can be useful in less common distributions or in environments where you need a very specific version of Java.
If your intention is Develop applications, create mods, or work with complex build toolsYou might also want to look for a specific guide for your distribution on how to install and configure the JDK correctly, as there may be additional steps to integrate Java with the system and IDEs.
Installing the Oracle JDK on Linux
Although most users will be perfectly served by OpenJDK, in some business environments or with certain applications, it is explicitly required. Oracle JDKIn Linux, this option requires a Manual installation, as it is not usually included in the standard repositories. due to licensing issues.
At the time of writing this guide, one of the most relevant versions of Oracle is the JDK 21, which is also an LTS versionThe general procedure for installing it on a Debian/Ubuntu-based system, for example, would be something similar to the following, adapting it to your specific version.
First you will have to visit the official website of downloads from Oracle for the JDK and locate the appropriate file for Linux, usually the package x64 Compressed Archive, in format .tar.gzThey also usually offer a .deb package directly for better integration into Debian/Ubuntu systems.
Once you select the version, you will need to accept the Oracle license agreement and download the .tar.gz file to your computer. Once you have it, you can upload it to your server or Linux machine using an FTP client like FileZilla or by using the command scp from your local computer.
Upload file: scp /ruta/local/jdk-archivo.tar.gz usuario@servidor_ip:/tmp
In this example, the file is copied to the directory / Tmp from the server, but you could choose another one, like / OptOnce on the Linux machine, access that directory and extract the contents of the compressed file with:
Extract: tar -xzf nombre-de-archivo.tar.gz
This will create a folder containing the JDK files. To install in a more standard location, you can move the extracted folder to a permanent directoryfor example, within /usr/lib/jvm/using a command like:
Move to a system: sudo mv nombre-carpeta-extraida /usr/lib/jvm/oracle-jdk-21
From here, you will have to Configure the Java path and alternatives so that the system recognizes this JDK as a valid option, and optionally set it as the default using tools such as update-alternatives in Ubuntu/Debian or by configuring the environment variables according to your distribution.
Verify Java installation and manage versions
After installing any version of Java, it's a good idea to make sure that the system It correctly recognizes the installation and that you are using the version you actually want.This is essential if you have multiple versions running on the same machine.
To check the runtime version, run the following in the terminal:
Check version: java -version
The output will show something similar to “openjdk version \”17…\”” or “java version \”21.0.2\””, along with the type of runtime environment and details of the JVM (for example, “mixed mode” indicates that the virtual machine uses both interpreted and just-in-time compiled code, optimizing performance).
If you have also installed a JDK, it's a good idea to check the compiler with:
Compiler: javac -version
If you see the version number and the command runs without errors, it means that Java development tools are properly available on your system. This is essential for compiling projects or using build tools like Maven or Gradle.
In Ubuntu and Debian, when you have multiple versions of Java installed at the same timeYou can choose which one will be used by default using the alternatives system with the command:
Choose Java: sudo update-alternatives --config java
This command will show you a list of all the paths to the Java binaries installed on the system, along with a selection number. You just have to Enter the number associated with the version you want to use as default. and press Enter to apply the change.
Updating Java on APT-based systems is basically done with:
Update system: sudo apt update && sudo apt upgrade
This ensures you have security patches and improvements for installed Java versionsprovided they are distributed through the official repositories. In other distributions, the mechanism is similar, only changing the package manager (dnf, pacman, etc.).
Remove or uninstall Java on Linux
Sometimes you'll be interested clean up old versions of Java that you no longer use or free up space on your system. In Ubuntu and Debian, the first step is to identify the Java-related packages you have installed.
To list these packages, you can use:
List packages: apt list --installed | grep java
The result will show all packages whose name contains the word “java”, including different versions of OpenJDK, JRE, JDK, and other components. From there, you can choose which package you want to uninstall, For example:
Eliminate: sudo apt remove openjdk-21-jdk
This command will remove the specified package, although can leave configuration files on the systemIf you also want to remove those configuration files and perform a more thorough cleanup, you can use:
Purge: sudo apt purge openjdk-21-jdk
Keep in mind that if you remove all installed versions of Java, any application or service that depends on Java will also be affected. It will stop working until you reinstall a compatible version.It is advisable to thoroughly review dependencies before performing an aggressive purge on a production server.
Configure the JAVA_HOME environment variable
The variable JAVA_HOME is one of the key settings when working with Java development tools.Application servers, IDEs, or scripts that need to know exactly where the JDK is installed.
In many distributions, if you have installed Java using the package manager, the different versions are usually located in the directory /usr/lib/jvm/To see what's inside, you can run:
Explore JVM: ls /usr/lib/jvm/
That list will show the folders of the installed JDK and JRE, such as java-17-openjdk-amd64, java-21-openjdk-amd64, oracle-jdk-21etc. Note the full path of the installation you want to use as the value of JAVA_HOME.
The next step is to edit your shell profile file so that JAVA_HOME will load automatically every time you log inFor a specific user who uses bash, the usual file is ~/.bashrcYou can edit it with:
Edit profile: nano ~/.bashrc
If what you want is to establish JAVA_HOME at the system level for all users, a file is usually modified as / Etc / profileFor this, you will need administrator privileges. For example:
Edit globally: sudo nano /etc/profile
Within the file you are editing, go to the end and add a line defining JAVA_HOME with the exact path to your Java installation.A typical example, if you are using 64-bit OpenJDK 21, would be:
Define JAVA_HOME: export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
Save your changes and close the editor. If you have modified ~/.bashrc For a specific user, you can Apply the changes immediately with:
Apply changes: source ~/.bashrc
If you changed a global profile file like / Etc / profileThe simplest thing is log out and log back in for the new environment variables to take effect. From that moment on, any application that uses JAVA_HOME You should be able to find the correct Java installation without any problems.
Taking all of the above into account, you now have A fairly comprehensive overview for installing, verifying, updating, changing, and removing Java on Linux.Whether you prefer OpenJDK or need the Oracle JDK, and regardless of whether you use Ubuntu, Debian, Fedora, Arch, or another distribution, with the appropriate package manager and a well-configured JAVA_HOME, it's easy to get Java ready to run servers, tools, or to develop your own projects with a solid and stable foundation.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.
