How to Install Java, OpenJDK on Ubuntu

Published on December 28, 2023

Zignuts Technolab

How to Install Java, OpenJDK on Ubuntu
How to Install Java, OpenJDK on Ubuntu
Software Development


Java is a versatile, object-oriented programming language developed by Sun Microsystems (acquired by Oracle Corporation). It is designed to be platform-independent, allowing developers to write code that can run on any device or platform with a Java Virtual Machine (JVM). Java is widely used for building a variety of applications, including web, mobile, enterprise, and embedded systems.

Java Development Kit (JDK) and Java Runtime Environment (JRE) are essential components of the Java platform, each serving a specific purpose in the development and execution of Java applications.

Java Development Kit (JDK)

The JDK is a software development kit that provides tools, executables, and binaries required for developing, compiling, and running Java applications. It includes the Java Compiler(javac), Java Virtual Machine (JVM), various development tools, and an extensive set of libraries and APIs.


Java Compiler (javac) : Translates Java source code into Java bytecode..

Java Virtual Machine (JVM) : Executes Java bytecode on the target hardware.

Development Tools : Includes tools for debugging (jdb), documentation generation (Javadoc), and packaging (jar).

Use Case :

Developers use the JDK during the software development phase to write, compile, and test Java applications. It provides everything needed for the entire development life cycle.


Java Runtime Environment (JRE)

The JRE is a subset of the JDK and provides the runtime environment for Java applications. It includes the JVM, class libraries, and other supporting files needed for the execution of Java applications.


Java Virtual Machine (JVM): Executes Java bytecode.

Class Libraries: A set of precompiled classes and methods that Java applications can use for common tasks.

Use Case :

End-users who only need to run Java applications use the JRE. Itdoesn't include development tools like the compiler or debugger.


Relationship between JDK and JRE:

 The JDK includes the JRE, meaning that if you install the JDK, you also have everything in the JRE. However, the reverse is not true—the JRE doesn't include development tools.

Developers use the JDK during the development phase to create and test applications. End-users only need the JRE to run applications.

In summary, the JDK is a comprehensive package for Java development, including tools and libraries for both development and execution, while the JRE is a runtime environment for end-users, containing only what is necessary to run Java applications.

Let’s Get Started

This guide is predicated on the assumption that you are using an Ubuntu 22.04 server. But don't worry if your server is running a different operating system, the commands and concepts are still mostly applicable.

Step 1 : let’s Install Java

1.1 update your apt package index:

To start with installation let's first update your apt package index in your Linux:

Also, we need to check whether Java is already installed or not

Let’s install JRE from OpenJDK:

Now you can verify the installation:

You'll get the output shown below:

By default, Elasticsearch listens on localhost and port 9200. Modify settings such as and http.port if needed.

Initiate the Elasticsearch service using systemctl and allow a brief startup period to avoid connection errors:


To compile and run any specialized Java-based software, you might also require the JDK in addition to the JRE. Use the following command to install the JDK, which will also install the JRE:

Jdk installation can be verified bychecking version of java compiler:

You'll get the output shown below:


Step 2: Setting up Multiple Java versions

You can run the command below to set up multiple Java installations on a server and set up different Java versions using the command line.

Note: This command can also be used with the following other commands: key tool, java doc, and jarsigner, among others.

Step 3: Setting up JAVA_HOME Environment Variable

If you are running multiple versions use this command to find the path of the installation.

If you are not running multiple versions use this command to find the path of installation.

By running this command you will find output like this:


In my case java installation path is below : /usr/lib/jvm/java-11-openjdk-amd64

 Take a copy of the path from the installation you like. Following that, use nano or another text editor of your choice to open /etc/environment:

At the end of file you can add path as

In this case it will be

Save the file now, and then exit the editor.

We must execute the following command to make the modifications made in the current session visible:

To verify your changes run the following command :

Output : /usr/lib/jvm/java-11-openjdk-amd64

How to Install Java, OpenJDK on Ubuntu

How to Install Java, OpenJDK on Ubuntu





Why they’re fond of us?

tm img

A reliable and flexible technical partner, Zignuts Technolab enables a scalable development process. The team offers a comprehensive array of expertise and scalability that yields an optimized ROI. Direct contact with specialists maintains a seamless workflow and clear communication.


Technical Architect
Blockchain-based Real Estate Platform Company, Belgium

Zignuts Technolab transformed our platform by simplifying code, redesigning key aspects, and adding new features, all within impressive timelines. Their project management and communication were exceptional.


Managing Director
Automobile Company, UAE

Zignuts team has been instrumental in our platform’s development including backend, frontend and mobile apps, delivering excellent functionality and improving speed over time. Their project management, pricing and communication are top-notch.


AI-Based Fintech Startup, UK

Zignuts has delivered excellent quality in developing our website and mobile apps. Their genuine interest in our business and proactive approach have been impressive.


Technical Architect
Blockchain-based Real Estate Platform Company, Belgium

Their team's dedication and knowledge in handling our relocation information platform made the collaboration seamless and productive. Highly recommend their services.


CEO & Founder
Social Community Platform, Germany

Zignuts Technolab provided highly skilled full-stack developers who efficiently handled complex tasks, from backend development to payment gateway integration. Their responsiveness and quality of work were outstanding.


Chief Product Officer
Enterprise Solutions, Jordan

Zignuts Technolab has been highly efficient and responsive in developing our rewards and wellness app. Their ability to integrate feedback quickly and their solid expertise make them a great partner.


Wellness Startup, Thailand