How to Install Full Version of JDK on Linux
When working with Java applications, one of the first things you need is the Java Development Kit (JDK). The JDK is essential for compiling, running, and debugging Java programs. It includes the Java Runtime Environment (JRE), compilers, and various tools like JavaDoc and Java Debugger.
Whether you're developing Android apps, working on a Java server-side project, or just learning Java, installing the full version of the JDK on Linux is your first step.
In this article, I’ll guide you through how to install the JDK on Linux, regardless of whether you're using Ubuntu, Fedora, or another Linux distribution.
Why Install the JDK?
If you are serious about Java development, installing the full version of the JDK is essential. It provides not only the runtime environment that lets you run Java programs but also the tools you need to write and debug your own Java applications.
The JDK includes libraries, compilers, and debuggers necessary for building Java applications. By installing it, you will have everything you need to get started with Java development on Linux.
Step 1: Choose the Right JDK Version
Before you install the JDK, you need to know which version of the JDK you want to install. Oracle releases new versions of the JDK regularly, and you can choose between the official Oracle JDK or the OpenJDK, which is an open-source alternative.
For most users, OpenJDK is a great option since it is widely supported and freely available.
Oracle JDK: Offers official support and the latest updates, but it comes with a commercial license for production use.
OpenJDK: The open-source implementation of Java, it is free to use and perfect for most developers.
In this guide, I’ll focus on installing OpenJDK, but the steps for Oracle JDK are similar.
Step 2: Installing OpenJDK on Ubuntu or Debian-based Systems
Ubuntu and other Debian-based systems make it easy to install the JDK using their package manager. You can choose between different versions of the JDK, such as Java 8, Java 11 (the current Long Term Support version), or Java 17 (the latest version).
Using the Terminal
Update your package list: Open your terminal and run the following command to update your package list:
sudo apt update
Install OpenJDK: To install OpenJDK, you need to specify which version you want. If you want to install Java 11, for example, run:
sudo apt install openjdk-11-jdk
This command installs the full version of JDK 11, including the compiler (
javac
), runtime (java
), and development tools.Verify the installation: After installation, check that Java was installed correctly by running:
java -version
You should see the version of Java you installed. If you installed JDK 11, it will say
openjdk version "11.x.x"
.Set the default version (if multiple versions are installed): If you have more than one version of the JDK installed, you can choose the default version by running:
sudo update-alternatives --config java
Follow the prompts to select the version you want to use.
That’s it! You’ve installed OpenJDK on Ubuntu or any other Debian-based system.
Step 3: Installing OpenJDK on Fedora
For Fedora users, installing OpenJDK is just as straightforward. Fedora uses the DNF package manager, which makes it easy to install the JDK.
Using the Terminal
Update your system: Open your terminal and update your package list by running:
sudo dnf update
Install OpenJDK: To install JDK 11, for example, use the following command:
sudo dnf install java-11-openjdk-devel
This command installs both the runtime environment and the development tools.
Verify the installation: After installation, check the version to ensure everything is set up correctly:
java -version
You should see the OpenJDK version that you installed.
Fedora makes it easy to install multiple JDK versions side by side, so if you need an older version (like JDK 8), you can install it by replacing java-11-openjdk-devel
with java-1.8.0-openjdk-devel
.
Step 4: Installing OpenJDK on Arch Linux
If you’re using Arch Linux, installing OpenJDK is simple, but it requires a different method using Pacman, Arch’s package manager.
Using Pacman
Update the package database: Open your terminal and run:
sudo pacman -Syu
This command updates your package list and ensures you have the latest software available.
Install OpenJDK: To install OpenJDK 11, for instance, use:
sudo pacman -S jdk11-openjdk
Verify the installation: After installation, verify the Java version:
java -version
As with Ubuntu and Fedora, you should see the installed version of OpenJDK in your terminal.
Step 5: Installing Oracle JDK
If you prefer Oracle’s official JDK, the installation is a bit more manual, as it requires downloading the installer from Oracle’s website. Here’s how to install Oracle JDK on Linux:
Download Oracle JDK: Visit the Oracle JDK download page and download the version you need. Make sure to choose the
.tar.gz
file for Linux.Extract the archive: Once downloaded, extract the JDK to a preferred directory:
tar -xvzf jdk-11_linux-x64_bin.tar.gz
Move to the desired location: Move the extracted folder to
/usr/local/
or another appropriate location:sudo mv jdk-11 /usr/local/
Set up environment variables: To use Oracle JDK, you’ll need to set up your environment variables. Add the following lines to your
.bashrc
or.zshrc
file:export JAVA_HOME=/usr/local/jdk-11 export PATH=$JAVA_HOME/bin:$PATH
Save the file and run
source ~/.bashrc
to apply the changes.Verify the installation: Check that the installation was successful by running:
java -version
You should see the Oracle JDK version displayed.
Step 6: Setting Up Java Development Tools
Once you’ve installed the JDK, you can start developing Java applications. Here are some popular tools you might want to install for a better development experience:
IDE (Integrated Development Environment): Consider installing an IDE like Eclipse or IntelliJ IDEA. These tools make writing, debugging, and testing Java applications much easier.
Maven or Gradle: These are popular build tools for Java projects. To install Maven on Ubuntu, for instance, run:
sudo apt install maven
Gradle can also be installed using your package manager.
Conclusion
Installing the full version of the JDK on Linux is essential for anyone who wants to start developing Java applications. Whether you choose OpenJDK or Oracle JDK, the process is simple and can be done in just a few steps. Depending on your Linux distribution, you’ll use package managers like apt
, dnf
, or pacman
to install the JDK.
Once installed, you’ll have all the tools you need to compile, run, and debug Java applications. With the JDK set up, you’re ready to dive into Java programming!