In the world of digitalization, Java is one of the primarily used programming languages. You can build many applications including Mobile Applications, Desktop Applications, and Games with the help of Java programming language. Additionally, Java is free and available for different platforms.
This blog will guide related to installation on Java on Ubuntu 22.04 with apt-get.
How to Install Java on Ubuntu 22.04 with Apt-Get?
These steps will practically demonstrate the complete process of installing Java on Ubuntu 22.04.
Step 1: Update Ubuntu’s Package List
It is one of the best practices to keep your Ubuntu packages list up to date. Use the apt-get command followed by the update option to refresh and update your system:
sudo apt-get update |
---|
Your Ubuntu machine is up to date now.
Step 2: Verify Java Installation
Use the –version option to check if the java package is already available on your system.
java --version |
---|
The command will display the installed Java version in your Ubuntu terminal. You will also see some suggestions about the available packages in your system repository.
Step 3: Install Java Package
From the above step, you can install the Java package according to your needs. If you want to install the default package of Java, run the given below command:
sudo apt-get install default-jre |
---|
The command executed successfully and installed the default Java Runtime Environment (jre) package on your system.
Step 4: Check Java Version
Verify the installed version of Java using the command:
java --version |
---|
The output displayed in your terminal window, which includes details like the OpenJDK version 19.0.2, confirms that Java is now available and operational on your system.
How to Run Java on Ubuntu 22.04?
Step 1: Create helloworld.java File
Create and open the Nano editor from your Ubuntu terminal:
nano helloworld.java |
---|
Step 2: Type “Hello World” Script
Write your Java script in the text editor and save it with Ctrl + S. To exit the text editor, press Ctrl + X:
public class helloworld { public static void main(String[] args) { System.out.println("Hello, World!"); } } |
---|
Step 3: Run or Test a Java Program
You can test the Java program you have written, using the Java command followed by the class name such as helloworld.java:
java helloworld.java |
---|
If you see Hello, World! on your terminal screen, it indicates that the Java program is working properly on your Ubuntu 22.04 machine.
Conclusion
On Ubuntu 22.04, you can install the Java package using the apt-get package manager. First, you need to update your system then use the sudo apt-get install default-jre command to install the package. In this post, you have learned about the installation of Java on Ubuntu 22.04 using the apt-get utility.