Java is a commonly utilized object-oriented programming language which is a very secure, quick, and trustworthy language. Java is mostly used in website and application development. It helps users in creating games(mobile or computer), websites, and other applications. Ubuntu is an operating system software that is Linux-based. Users can implement and run Java programs in Ubuntu. To implement this, users have to install Java in Ubuntu.
This article will demonstrate some methods to install Java in Ubuntu 22.04:
- Method 1: Through OpenJDK18
- Method 2: Through Java Development SE Kit 21
Method 1: How to Install/Setup Java in Ubuntu 22.04 via OpenJDK18?
OpenJDK18 (Open Java Development Kit) is an open-source Java Development Kit of version 18, which means free source code availability that can be utilized by all users. OpenJDK consists of some packages including JRE and JDK. Java Development Kit(JDK) is used for the development of Java applications whereas JRE (Java Runtime Environment) is needed to execute applications of Java.
To install Java in Ubuntu 22.04 via OpenJDK 18, we should follow the below-mentioned steps:
- Update System Packages/Repositories
- OpenJDK 18 Installation
- OpenJDK 18 JRE Installation
Step 1: Update System Packages/Repositories
The convenient option for installing Java is from default packages/repositories. For that, first, open the terminal and update the packages/repositories by using the below-listed command:
“apt” is a tool used for application installations and management.
The update command will update all the existing packages:
Step 2: OpenJDK 18 Installation
Depending on user choice or preference, install/download OpenJDK or JRE on Ubuntu 22.04. To get OpenJDK below-listed command is used:
“-y” means yes to all prompts during installation packages, so that prompt doesn’t pause during the installation process until the user replies to yes and continues the further process as generally prompts do.
In this way, OpenJDK will install:
The below output shows that the installation has been completed:
Step 3: OpenJDK 18 JRE Installation
If users have JDK installed, there is no need for JRE as JRE is a part of JDK. However, if specifically, the user wants to install OpenJDK 18 JRE in Ubuntu 22.04, utilize the below-mentioned command:
The above command will install OpenJDK 18 JRE:
Method 2: How to Install/Download Java in Ubuntu 22.04 via Java Development SE Kit 21?
Java Development SE Kit 21 also contains various tools for developing, debugging, and running Java applications.
To install Java Development SE Kit 18 in Ubuntu 22.04, check out the below-listed steps:
- Updation of System Repositories/Packages
- Installation of Necessary Dependencies
- Download of Java Development SE Kit 21
- Installation of Java Development SE Kit 21
- Java Environment Configuration
- Check Java Version
Step 1: Updation of System Repositories/Packages
First, open the terminal and update the packages/repositories by using the provided command:
The above command will update all the packages:
Step 2: Installation of Necessary Dependencies
To run the program efficiently, dependencies are used. Dependencies include modules, packages, and libraries. The below-mentioned command is utilized to install the required dependencies:
“libc” is an acronym for standard C library. “libc6-x32” is a package that includes the shared version of libc. “libc-i386” is the 1386 version of the standard C library used for i386 systems.
The output will show the installation process of dependencies:
Step 3: Download Java Development SE Kit 21
Java Development SE Kit 21 package can be downloaded from the Official Website via the “wget” command:
It can be observed that the latest version of Java Development SE Kit has been downloaded successfully:
Step 4: Installation of Java Development SE Kit 21
Now, to install Java Development SE Kit 21 in Ubuntu 22.04, the below-given command is used:
The above-mentioned command will install the Java Development SE Kit 21
Step 5: Java Environment Configuration
After installation, Java Environment Configuration should be done. To do so, use the below commands one by one:
> export JAVA_HOME=/usr/lib/jvm/jdk-21
> export PATH=\$PATH:\$JAVA_HOME/bin
> EOF
The following output will be shown after configuration:
Then, to run the profile file named “jdk21.sh”, use the “source” command:
Step 6: Check the Java Version
To confirm the installation of Java in Ubuntu, the user needs to verify by checking the Java version using the given command:
This can be observed that the latest Java version has been installed successfully:
Bonus Tip: How to Uninstall Java in Ubuntu 22.04?
Sometimes a user wants to uninstall Java for some reason including freeing up space, no more need. For the need to uninstall Java in Ubuntu, follow the below-listed steps:
- Verify Java Version
- Detect the Location of Java Packages
- Remove Directory from Java
- Confirm Uninstallation of Java Version
Step 1: Verify Java Version
The need to verify the Java version is to know about the current status of it either already installed or not. The first step for uninstalling Java is to verify the version by using the given command:
The below output shows the installed version of Java:
Step 2: Detect the Location of Java Packages
Mostly, packages of Java are present in the /opt/ directory or the /usr/lib/ directory. To detect the location of Java packages following command should be used:
Utilizing the above command, we will get the directories from Java’s current location:
Step 3: Remove Directory from Java
After identifying the location of Java packages, the user has to remove that directory by utilizing the “remove” command:
Step 4: Confirm Uninstallation of Java’s Version
Again, recheck the Java version to verify the removal of a directory from Java using the “version” command:
The output confirms Java directory removal.
We have explained the efficient methods to install Java in Ubuntu 22.04.
Conclusion
To download/install Java in Ubuntu 22.04 via OpenJDK18 method, utilize either the“$ sudo apt install -y openjdk-18-jdk” or “$ sudo apt install -y openjdk-18-jre” command. Alternatively, Java can be installed via Java Development SE Kit 21 method. This can be done by using the official website along with the help of the “$ sudo apt install ./jdk-18_linux-x64_bin.deb” command. This article has demonstrated the methods to Install Java in Ubuntu 22.04.