Java is a popular programming language that is used to develop a wide range of applications, from web and mobile applications to large-scale enterprise systems. There are two main implementations of Java available: OpenJDK and Oracle JDK. In this article, we will show you how to install both OpenJDK and Oracle JDK on Ubuntu 22.04.
Install OpenJDK
OpenJDK is an open-source implementation of the Java Development Kit (JDK), which is the official development kit for Java. It is developed and maintained by the OpenJDK community, and is freely available to download and use.
To install OpenJDK on Ubuntu 22.04, you can use the apt
package manager. First, update the package index by running the following command:
sudo apt update
Next, install OpenJDK using the apt
command:
sudo apt install openjdk-14-jdk
This will install the OpenJDK 14 JDK, which is the latest version of OpenJDK at the time of writing.
To verify that OpenJDK is installed and working properly, you can run the java
command and check the version:
java -version
This will print the version of Java that is currently installed and being used on your system.
Install Oracle JDK
Oracle JDK is the official, commercial implementation of the Java Development Kit from Oracle Corporation. It includes additional features and tools that are not available in OpenJDK, but it is not freely available and requires a license to use.
To install Oracle JDK on Ubuntu 22.04, you first need to download the Oracle JDK installer from the Oracle website (https://www.oracle.com/java/technologies/javase-downloads.html
). You will need to create an Oracle account and accept the license agreement in order to download the installer.
Once you have downloaded the Oracle JDK installer, you can use the apt
package manager to install it. First, update the package index by running the following command:
sudo apt update
Next, install the Oracle JDK installer using the apt
command:
sudo apt install oracle-java14-installer
This will install the Oracle JDK 14 installer, which is the latest version of Oracle JDK at the time of writing.
To verify that Oracle JDK is installed and working properly, you can run the java
command and check the version:
java -version
This will print the version of Java that is currently installed and being used on your system.
Set the Default Java Version
By default, Ubuntu 22.04 uses OpenJDK as the default version of Java on the system. If you have installed Oracle JDK, you can use the update-alternatives
command to set Oracle JDK as the default Java version on your system.
To set the default Java version, first run the update-alternatives
command with the --config java
option:
sudo update-alternatives --config java
This will display a list of available Java versions on your system, and ask you to choose the default version. Select the Oracle JDK version from the list and press ENTER to set it as the default.
To verify that the default Java version has been changed, you can run the java
command and check the version again.