Java is an object oriented programming language popular among the develops. It is used for a wide range of software applications and development tasks. Installing Java on your Ubuntu system ensures compatibility and functionality for all Java-dependent operations. This tutorial focuses on installation of OpenJDK, the open-source implementation of the Java Platform, Standard Edition, on a Ubuntu 24.04 (Noble) Linux systems.
Prerequisites
Before proceeding to Java installation,
- A running Ubuntu 24.04 Linux system with root or sudo access
- A basic command line knowledge.
Now follow the below steps:
Step 1: Update Your System
As a best practice make sure to update all the existing packages on your system before installing any new software. Open your terminal and execute the following commands:
sudo apt update
sudo apt upgrade
Step 2: Installing OpenJDK
OpenJDK is available in multiple versions within the Ubuntu package repository, allowing you to choose according to your needs. For many users, OpenJDK 11, a long-term support version, is a popular choice these days. Use the following command to install Java 11 on your Ubuntu system:
sudo apt install openjdk-11-jdk
If you require a different version of OpenJDK, you can list the available versions by searching the package repository:
apt search openjdk
Replace 11 with the version number of your choice in the installation command if you need a different version.
Step 3: Verify the Installation
After installation, verify that Java has been installed correctly by checking the version.
java -version
This command will display the currently active Java version, confirming the successful installation. For those, show also installed JDK, can check for java compiler version using javac -version
command.
Step 4: Set Java’s Home Environment
Some applications require setting the JAVA_HOME environment variable to function correctly. You can set this variable globally on your system by first finding the installation path of your Java version:
sudo update-alternatives --config java
Copy the path shown (excluding the /bin/java part) and then edit the /etc/environment file:
sudo nano /etc/environment
Add the following line at the end of the file. Make sure to replace “/usr/lib/jvm/java-11-openjdk-amd64” with the path you copied form above command.
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Save and exit the file. Apply the changes by sourcing the file:
source /etc/environment
echo $JAVA_HOME
This will print the path you set for JAVA_HOME, confirming the configuration.
Step 5: Switching Between Java Versions (Optional)
If you have multiple Java installations and need to switch between them, you can configure the default version using:
sudo update-alternatives --config java
Select the version you wish to use by following the on-screen prompts.
Conclusion
You’ve just finished installing Java (OpenJDK) on your Ubuntu 24.04 system. This means you can now start running applications made with Java or even create some cool new Java programs yourself. It’s a good idea to try running some specific Java applications to make sure everything is set up properly and working as it should. This helps ensure that your system is fully ready to handle the tasks you need.