• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Java on Ubuntu 22.04

Written by Admin, Updated On January 16, 2023
java, jdk, ubuntu
How to Install Java on Ubuntu 22.04

In this tutorial we will show how install Java on Ubuntu 22.04. Java is one of the most popular programming language used to build flexible and maintainable applications and systems.

Java comes in two different implementations OpenJDK and Oracle Java. Oracle java provides commercial features. It’s license allows only non-commercial use of software, for personal use or development use.

The default Ubuntu 22.04 repositories include two OpenJDK packages, Java Runtime Environment (JRE) and Java Development Kit (JDK).

  • JRE (Java Runtime Environment) – It includes a set of software tools, classes and binaries that require for the execution of Java applications.
  • JDK (Java Development Kit) – It is development environment and needed for the development of Java application. It includes an interpreter, a compiler, an archiver, and other software tools.
  • OpenJDK – It’s an open-source implementation of JDK. If you are not sure which Java package to install then you should stick to the default OpenJDK.

Prerequisites#

You should have a Ubuntu 22.04 instance with a system user with sudo privileges.

How to Install Java on Ubuntu 22.04#

Perform the following steps to install Java on Ubuntu 22.04:

Step 1 – Update System#

First of all you have to update your system using the below given command:

sudo apt update

Step 2 – Install OpenJDK#

By default Ubuntu 22.04 includes Open JDK 11, which is an open-source variant of the JRE and JDK.

sudo apt install openjdk-jdk

Step 2 – Verify Installation#

Once the installation is complete, you can verify it by checking the Java version:

java -version

It should show output as below:

openjdk version "11.0.17" 2022-11-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-3ubuntu1, mixed mode, sharing)

All done! Java is install on your Ubuntu 22.04 system.

Set the default Java version#

You can set the default Java version, If you have multiple Java versions installed on your Ubuntu system. First of all, check the current default version by typing:

java -version

To change the default version use the update-alternatives command:

sudo update-alternatives --config java

It should show output like this:

There are 2 choices for the alternative java (providing /usr/bin/java).

  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-19-openjdk-amd64/jre/bin/java   1191      manual mode

Press <enter> to keep the current choice[*], or type selection number:

It will show the list of installed Java versions. Select the version which you want to set as default by entering number and hit Enter key.

JAVA_HOME Environment Variable#

The JAVA_HOME environment variable holds the Java installation location which used by the Java applications.

At first, use update-alternatives command to find where the Java versions are installed:

sudo update-alternatives --config java

It will show the path where Java is installed. In this example the installation paths are as follows:

  • OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java
  • Oracle Java is located at /usr/lib/jvm/java-11-oracle/jre/bin/java

Now, open the /etc/environment file by typing:

sudo nano /etc/environment

To set Java 11 as default, set Java 11 installation path to JAVA_HOME as given below, at the end of file:

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

Next, Save and exit the text editor. Finally, issue the source command as follows.

source /etc/environment

To confirm the Java environment variable setting, run the command.

echo JAVA_HOME

You should see the path to the Java installation:

/usr/lib/jvm/java-11-openjdk-amd64

Uninstall Java#

Uninstall of Java is simple process like any other packages installed with apt:

For example, to uninstall the openjdk-jdk package simply run:

sudo apt remove openjdk-jdk

Conclusion#

The latest LTS version OpenJDK 11 and previous LTS version OpenJDK 11 are available in the default Ubuntu 22.04 repositories. The installation is a very simple and straightforward task. You learned how to install different java version on Ubuntu 22.04.

If you have any query or suggestion, feel free to leave a comment.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Jenkins on Ubuntu 22.04
Next Article   How to Install Slack on Ubuntu 22.04

Related Posts

  • How to Install and Use PHP Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    January 31, 2023
  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023
  • How to Install Puppet Agent on Ubuntu 22.04

    How to Install Puppet Agent on Ubuntu 22.04

    January 22, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook