In this article, I’ll walk you through the installation of Java JDK (Java Development Kit) on an Ubuntu 24.04 Linux system. Java is a popular programming language used for development of Desktop Applications, Games, Mobile applications and many others. Ubuntu 24.04 was released recently and is now ready for Production use. As a Java Developer, you’ll want to install the default Java available on Ubuntu 24.04.
We will focus on the installation of the default version of Java on Ubuntu 24.04. You can check available versions with the command:
sudo apt update
Once the APT index is updated, check versions of Java available on the default repositories of Ubuntu:
$ apt policy default-jdk
default-jdk:
Installed: (none)
Candidate: 2:1.21-75+exp1
Version table:
2:1.21-75+exp1 500
500 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 Packages
We will install both Java Runtime Environment (JRE) and the Java Development Kit (JDK) on Ubuntu 24.04:
sudo apt install default-jdk default-jre
A number of dependencies will be installed, you can validate and agree to install Java on Ubuntu 24.04 with the y key:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
ca-certificates-java default-jdk-headless default-jre-headless fonts-dejavu-extra java-common libatk-wrapper-java libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev libsm-dev libx11-dev
libxau-dev libxcb-shape0 libxcb1-dev libxdmcp-dev libxt-dev libxxf86dga1 openjdk-21-jdk openjdk-21-jdk-headless openjdk-21-jre openjdk-21-jre-headless x11-utils x11proto-dev xorg-sgml-doctools
xtrans-dev
Suggested packages:
libice-doc libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-21-demo openjdk-21-source visualvm libnss-mdns fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei
fonts-indic mesa-utils
Recommended packages:
luit
The following NEW packages will be installed:
ca-certificates-java default-jdk default-jdk-headless default-jre default-jre-headless fonts-dejavu-extra java-common libatk-wrapper-java libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev
libsm-dev libx11-dev libxau-dev libxcb-shape0 libxcb1-dev libxdmcp-dev libxt-dev libxxf86dga1 openjdk-21-jdk openjdk-21-jdk-headless openjdk-21-jre openjdk-21-jre-headless x11-utils x11proto-dev
xorg-sgml-doctools xtrans-dev
0 upgraded, 27 newly installed, 0 to remove and 4 not upgraded.
Need to get 135 MB of archives.
After this operation, 316 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Confirm Java installation on Ubuntu 24.04
After successfully installing Java on Ubuntu 24.04, confirm the version with the java command line.
$ java -version
openjdk version "21.0.4" 2024-07-16
OpenJDK Runtime Environment (build 21.0.4+7-Ubuntu-1ubuntu224.04)
OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu224.04, mixed mode, sharing)
Write a test Java application.
cat > HelloWorld.java <<HELLO
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
HELLO
Run the test java application created.
$ java HelloWorld.java
Hello World!
If you have more that one version of Java installed, set default Java to use with the command:
sudo update-alternatives --config java
You must have noted you can directly run Java source files in Java 11. The compilation step is automatically handled for you.
Explore More with CloudSpinx
Looking to streamline your tech stack? Look no further. Here at CloudSpinx, we deliver robust solutions tailored to your needs:
- Hosting Services: Web Hosting, VPS, and Email Hosting.
- Development Services: Custom Web & Mobile Apps, UI/UX Design.
- Consultancy Services: Cloud, DevOps, Cybersecurity, and Kubernetes Experts.
- Managed Services: End-to-end infrastructure support.
- Dedicated Servers: Power and control, fully managed.
Learn more about how we can support your journey with CloudSpinx.