This guide covers how to install Java 20(OpenJDK) on Ubuntu 22.04|20.04|18.04. Java is among the popular programming languages. It is known as a fast, secure, and reliable development language. It also allows developers to “write once and run everywhere.” This is to mean that an application that is complied with Java is able to run on all platforms supporting Java without the need to recompile it.
Java is used for:
- Server-Side Technologies like JBoss, Apache, GlassFish, etc.
- Programming of Hardware devices
- Developing Android applications and other Mobile Applications
- Big Data Analytics
- Creating Enterprise Software
- Scientific Computing Applications
Java has been through a series of development stages to the current version. The long-awaited version, Java 20 reached General Availability on 21st March 2023. The production-ready binaries are now available. Java 20 is not an LTS version therefore it will receive updates only until it is superseded in six months by JDK 21.
Follow the steps below to accomplish the installation of Java 20(OpenJDK) on Ubuntu 22.04|20.04|18.04.
#1. Prepare Your System
Update your system and available packages to the latest available versions:
sudo apt update
sudo apt upgrade
Install the required packages:
sudo apt install wget -y
#2. Download and Install Java 20(OpenJDK) on Ubuntu 22.04|20.04|18.04
To download the latest available version, visit the OpenJDK releases page. You can also pull the archive using wget as shown:
##For 64-bit
wget https://download.java.net/java/GA/jdk20/bdc68b4b9cbc4ebcb30745c85038d91d/36/GPL/openjdk-20_linux-x64_bin.tar.gz
##For AArch64
wget https://download.java.net/java/GA/jdk20/bdc68b4b9cbc4ebcb30745c85038d91d/36/GPL/openjdk-20_linux-aarch64_bin.tar.gz
Once downloaded, extract the archive:
tar -xvf openjdk-20_*_bin.tar.gz
Move the files to /opt
sudo mv jdk-20*/ /opt/jdk20
Set up the Java environment:
cat <<EOF | sudo tee /etc/profile.d/jdk.sh
export JAVA_HOME=/opt/jdk20
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
Source the profile:
source /etc/profile.d/jdk.sh
Now verify the Java version:
$ java -version
openjdk version "20" 2023-03-21
OpenJDK Runtime Environment (build 20+36-2344)
OpenJDK 64-Bit Server VM (build 20+36-2344, mixed mode, sharing)
#3. Test Java 20 on Ubuntu 22.04|20.04|18.04
To verify if Java 20 is working, we will run a simple Java code on our Ubuntu 22.04|20.04|18.04 system.
Create a test Java application with the command:
tee HelloWorld.java<<EOF
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello World from Java 20!");
}
}
EOF
Run the application with the command:
java HelloWorld.java
Sample Output:
![](https://i0.wp.com/tutornix.com/wp-content/uploads/2023/04/How-to-install-Java-20OpenJDK-on-Ubuntu-22.0420.0418.04.png?resize=700%2C53&ssl=1)
Conclusion
Today we have learned how to install Java 20(OpenJDK) on Ubuntu 22.04|20.04|18.04. You can learn more about how to use Java by following the below link
See more on this page: