How To Set JAVA_HOME Environment Variable On Ubuntu 22.04 LTS
We’ll walk you through setting the JAVA_HOME Environment variable on Ubuntu 24.04 LTS in this Java instructional post. First, confirm that Java is installed on your Ubuntu 24.04 LTS computer. We also have a solution for the case where Java is not installed. One of the most widely used programming languages is Java. Numerous programs are written in Java, and those programs require the JAVA_HOME environment variable to identify where Java should be installed. Setting the JAVA_Home environment option on Ubuntu 24.04 LTS is simple yet complex.
The first step is to find out where Java is installed.
How To Install Java on Ubuntu 24.04 LTS
- At first, We need to install JRE or Java runtime environment.
- The default Ubuntu packages repositories contain the packages for the OpenJDK 11.
- The default repository also contains OpenJDK 8 previous stable release packages.
List of Java version and their life of support.
J ava Version | Active Support | Extended Support |
---|---|---|
8 (LTS) | March 31, 2022 | December 21, 2030 |
11 (LTS) | September 30, 2023 | September 30, 2026 |
17 (LTS) | September 30, 2026 | September 30, 2029 |
19 | March 21, 2023 | March 21, 2023 |
20 | September 19, 2023 | Unavailable |
21 (LTS) | September 30, 2028 | September 30, 2031 |
22 | September 17, 2024 | Unavailable |
1. Install Java 11 on Ubuntu 24.04 LTS
Run the following commands to install OpenJDK 11 package on Ubuntu 24.04 . Java 11 is the latest LTS version that is available for installation for Ubuntu 24.04 LTS
sudo apt update sudo apt install openjdk-11-jdk
OpenJDK 11 has been installed.. Run the following command to verify it by checking the Java version:
java -version openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
2. Install Java 8 on Ubuntu On Ubuntu 24.04 LTS.
Run the following command to install OpenJDK 8 package on Ubuntu 24.04 LTS.
sudo apt update sudo apt install openjdk-8-jdk
3. Install Oracle Java 14 On Ubuntu 24.04 LTS.
Run the following command to download the Debian file of JAVA.
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/14.0.1+7/664493ef4a6946b186ff29eb326336a2/jdk-14.0.1_linux-x64_bin.deb"
How To Set JAVA_HOME Environment Variable On Ubuntu 24.04
Run the following update-alternatives command to find the path of JAVA installation in your Ubuntu 24.04 LTS.
sudo update-alternatives --config java
Output
Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode * 2 /usr/lib/jvm/java-11-oracle/bin/java 1091 manual mode Press to keep the current choice[*], or type selection number:
Now, we can find the location of the JAVA and its associate.
OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java and Oracle Java is located at /usr/lib/jvm/java-11-oracle/jre/bin/java.
Open /etc/environment using nano or your favorite text editor:
sudo nano /etc/environment
Make sure that the path to the JAVA installation is correct and now you need to go to the end of the file, and add the following line. Save the file and exit the editor.
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Now you need to reload this file to apply the changes to your current session:
source /etc/environment
Run the following command if you want to verify that the environment variable is set:
echo $JAVA_HOME
You will see the output like below:
Output /usr/lib/jvm/java-11-openjdk-amd64
Bonus:
What Is Differences Between OpenJDK and OpenJRE
While OpenJRE and OpenJDK are related, they differ in a few ways. OpenJRE is a runtime environment for Java applications, while OpenJDK is an open-source Java SE (Standard Edition) platform implementation that comes with a Java Development Kit (JDK) that offers tools for creating and compiling Java applications as well as a Java Runtime Environment (JRE), which is required to run Java applications on a user’s computer. It consists of the Java class libraries, which offer the fundamental features of the Java platform, and the Java Virtual Machine (JVM), which is the engine that executes Java code. The JDK’s development tools and compilers are not included in OpenJRE.
Summary:
We hope that you are now able “To Set JAVA_HOME Environment Variable On Ubuntu 24.04 LTS”.