In this article we are going to cover that “Java 18 Installation on Ubuntu 22.04 LTS [5 Steps]”


Java 18 is the latest version of the popular programming language and runtime environment. In this tutorial, we’ll walk you through the steps to install Java 18 on Ubuntu 22.04 LTS and set up the necessary environmental variables for development.


Before we begin, ensure you have the following prerequisites in place:

  1. A user account with sudo privileges.
  2. Access to the internet.
  3. An updated Ubuntu 22.04 LTS system.
  4. A text editor (optional).

Steps of “Java 18 Installation on Ubuntu 22.04 LTS [5 Steps]”

Assuming Java 18 or a similar version is available at the time of your installation, here’s “Java 18 Installation on Ubuntu 22.04 LTS [4 Steps]”:

Step #1:Update Your Ubuntu 22.04 LTS:

Start by updating your system’s package list to ensure that you have the latest information about available packages:

ubuntu@Rushi-InfoTech:~$ sudo apt-get update

Step #2:Install Java 18 on Ubuntu 22.04 LTS:

To install Java, you can use OpenJDK, which is the default open-source implementation of Java. Install it with the following command:

ubuntu@Rushi-InfoTech:~$ sudo apt install openjdk-18-jdk

We need to Confirm with “y” to install the java 18 in Ubuntu 22.04 LTS.

Step #3:Verify Java Installation on Ubuntu 22.04 LTS:

After the installation is complete, verify that Java has been installed correctly and check the installed version:

ubuntu@Rushi-InfoTech:~$ java -version

This command should display information about the installed Java version, confirming that Java 18 is now available.

Step #4:Set Environmental Variables (Optional):

Setting environmental variables can help manage which Java version to use and is particularly useful for Java-based applications. Here’s how to set the JAVA_HOME and update the PATH:

  • Edit your shell’s configuration file (e.g., ~/.bashrc for Bash) using a text editor:
ubuntu@Rushi-InfoTech:~$ nano ~/.bashrc
  • Add the following lines to the file, replacing /usr/lib/jvm/java-18-openjdk-amd64 with the actual path to your Java installation directory:
export JAVA_HOME="/usr/lib/jvm/java-18-openjdk-amd64"
export PATH="$PATH:$JAVA_HOME/bin"
  • Save the file and exit the text editor.
  • To apply the changes, either restart your shell session or run:
ubuntu@Rushi-InfoTech:~$ source ~/.bashrc

Step #5:Verify the Environmental Variables:

Confirm that the environmental variables are set correctly by running the following commands:

ubuntu@Rushi-InfoTech:~$ echo $JAVA_HOME
ubuntu@Rushi-InfoTech:~$ echo $PATH

These commands should display the Java installation directory and include it in the PATH.


You have successfully installed Java 18 on your Ubuntu 22.04 LTS system and configured the necessary environmental variables. You are now ready to develop and run Java applications using this latest Java version. Enjoy coding with the power of Java 18!

From this article we have learnt “Java 18 Installation on Ubuntu 22.04 LTS [5 Steps]”

Any queries pls contact us

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *