Java Tutorial



Java Tutorial

How to Install Java in Linux


Java has been widely used for developing various desktop and mobile applications. In addition to being platform-independent, Java can run on different operating systems, including macOS, Linux, and Windows. The following tutorial will show you the steps to install Java in the Linux operating system. 


Among the components of Java, there are the Java Runtime Environment (JRE), the Java Virtual Machine (JVM), and the Java Development Kit (JDK). A JDK is necessary for the development and execution of Java programs, while a JRE is only needed for execution.

The JVM is responsible for translating and executing the bytecode that the JRE receives. Thus, understanding the differences between JDK, JRE, and JVM before learning how to install Java in Linux OS is crucial. 

Several Java Development Kit(JDK) versions can be installed on different operating systems, including Linux, Windows, and Mac OS. The following is a detailed tutorial on how to install Java in a Linux terminal.

Which One do I need: JVM, a JRE, or a JDK?

The Java Runtime Environment (JRE), Java Virtual Machine (JVM), and Java Development Kit (JDK) are the three elementary parts of Java. While the JVM executes the bytecode produced by the Java compiler when the Java code is executed, the JRE runs Java applications.

The JDK is a package of the tools required for creating and building Java programs. It contains several tools for creating and debugging Java applications, such as the Java compiler and debugger.

  • Java Runtime Environment(JRE)

JRE, often known as Java RTE, stands for Java Runtime Environment. It is a group of software applications created to run other applications. JRE offers a runtime environment, and it is an implementation of JVM. To launch any Java software, a user needs JRE.

JRE functions as an operating system component of the software. It loads categories, examines memory utilization, and locates the system resources required for programs to function. The JRE alone will assist in running Java apps. 

JRE (Java Runtime Environment) is included with every JDK version. Users can avoid downloading and installing JRE individually on their PCs this way. The JRE is physically present as well. The JVM (Java Virtual Machine) deploys it during runtime, comprising a library set and a few other files.

  • Java Virtual Machine (JVM)

Java Virtual Machine (JVM) offers a runtime environment for Java programs or code. Java's bytecode is transformed into machine language via the abstract machine known as JVM. In addition, it can execute programs that have been translated into Java bytecode by programmers in other languages. Due to its virtual nature, the JVM can be called a virtual machine.

JRE (Java Run Environment) comprises JVM as its whole. Downloading and installing it individually is not possible. Installing JRE is a prerequisite for installing JVM. Numerous hardware and software systems support it. The compiler works to generate machine code for specific platforms in a variety of different programming languages. A virtual machine, sometimes called JVM, is created solely by the Java compiler.

  • Java Development Kit (JDK)

The initials JDK stand for Java Development Kit. It is a software development environment used to create Java programs and applets. A physical version of JDK exists, and it includes JRE + tools for development. On the same machine, several versions of JDK are simple to install. Java developers may use it on Mac OS X, Linux, Windows, and Solaris. 

JDK aids in the coding and execution of Java programs. The JDK makes it simple for programmers to create apps. 

Difference between JRE vs OpenJDK vs Oracle JDK 




Oracle JDK


Runs Java programs on a PC.

Java Development Kit (JDK) execution that is open source.

Java Development Kit (JDK) as it is implemented unofficially by Oracle.

Components included

Java programs must be run on the Java Virtual Machine (JVM), libraries, and other components.

Open-source but the same as Oracle JDK.

Similar to OpenJDK, but with additional proprietary parts.

Development tools included


Consists of development tools like a Java compiler and tools for debugging.

similar to OpenJDK


Proprietary license

Open-source license

Proprietary license




There is a charge for official assistance.

Java Runtime Environment (JRE)

The bare minimal set of tools needed to run Java programs on a computer is included in the JRE software package called JRE. It contains various libraries and parts required to run Java programs and the Java Virtual Machine (JVM), which interprets Java bytecode. Development tools like the Java compiler and debugging tools are not included with JRE. 


The Java Runtime Environment (JRE) and Java Development Kit (OpenJDK) were created by the users of open-source software and are available under the GPL license. The Java platform is implemented using free and open-source software that is GPL-licensed.

The OpenJDK package comes with a Java Development Kit (JDK) for programmers, a Java Runtime Environment (JRE) for users of the software, and a Java Virtual Machine (JVM) for running Java code.

Oracle JDK

Oracle JDK is the proprietary version of Java Development Kit (JDK) offered by Oracle. It includes several proprietary components unavailable in the OpenJDK version, such as JavaFX, Java Mission Control, and Java Flight Recorder.

Oracle JDK is designed for developers and includes development tools such as a compiler, debuggers, and other utilities that developers might need to develop Java applications.

OpenJDK vs Oracle JDK

The main difference between OpenJDK and Oracle JDK is the licensing. OpenJDK is free to use and distribute under an open-source license, while Oracle JDK is not free and requires a commercial license for production use. 

OpenJDK and Oracle JDK have similar functionality, providing a complete development environment for creating and running Java applications.

How to Check if Java is Already Installed in Linux? 

Perform the following steps to check if Java has been configured on your Linux system:

Step 1: Open a window on your Linux Terminal.

Step 2: To find out if Java has been installed on your machine, type the following command:

java -version

Step 3: If Java has been set up on your machine, the program will output the most recent version of Java. For example:

java version "11.0.11" 2021-04-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)

Step 4: The command displays an error if Java does not exist on your system.

Command 'java' not found, but can be installed with:

sudo apt install default-jre              # version 2:1.11-72, or
sudo apt install openjdk-11-jre-headless  # version 11.0.11+9-0ubuntu2~20.04
sudo apt install openjdk-16-jre-headless  # version 16.0.1+9-1~20.04
See 'snap info java' for additional versions.

How to Download and Install Java on Linux?

Using your Linux distribution package administration feature is one of the simplest methods to get Java on your computer and install it. The primary steps are as follows:

Step 1: Open a window on your Linux Terminal.

Step 2: Run the command below to update the package list as follows:

$ sudo apt update

Step 3: The following command should be executed when installing the default Java Runtime Environment (JRE):

$ sudo apt install default-jre

The default JRE for your system will be installed with this command.

Step 4: Check the Java version on your machine using the command below to confirm the installation:

$ java -version

We installed and downloaded Java on the Linux machine using the package manager.

How to Install JDK in Linux? 

The following instructions will show you how to install the Java Development Kit(JDK) on Linux:

Step 1: Open a window on your Linux Terminal.

Step 2: Run the command below to update your system's package index:

$ sudo apt update

Step 3: Run the following command for setting up the JDK (Java Development Kit) on your computer:

$ sudo apt install default-jdk

This will set up OpenJDK, the standard JDK.

Step 4: It will request authorization before downloading a few programs. Y stands for yes.

$ sudo apt install default-jdk

Step 5: Your system will now have JDK installed. 

$ java -version

This command will show the installed version of Java on your machine.

Download and Install Java IDE on Linux.

Step 1: Open the Linux terminal window

Step 2: The Eclipse IDE must be installed using an installer. Input the command to use the Snap installer for this.

$ sudo apt install snap

Step 3: After installing a snap installer, use the command to set up the Eclipse IDE. The download for the Eclipse IDE will start.

$ sudo snap install --classic eclipse
Download snap "eclipse"(66)from channel "stable"  12% 7.35MB/s 39.3s

Step 4: You will get the following message once the installation is complete.

$ sudo snap install --classic eclipse eclipse
2022-12 from Snapcrafters installed 

Step 5: You might discover the Eclipse IDE installed by searching for Eclipse in the program's search.

Write your first Java program on a Linux OS. 

Let's create our first Java program that displays “Hey Earth.”

Step 1: Select Create a New Java Project after setting up the workspace.

Step 2: Enter a name for your project in the Project name field, then click Finish. The project is called HeyEarth.

Step 3: In the package explorer, look for a folder called after your project name, for example, HeyEarth. Select the src folder after expanding the folder. Click on New, then Package.

Step 4: Make the following package in the src folder:

Step 5: Java is a programming language that uses classes and objects to perform operations. Create a new class using the identical procedures in your generated package.

Step 6: Set up a new class.

Step 7: The window below is shown on Eclipse. All necessary classes and methods have been developed. The commands must be written in the main method.

package newpackage;
  public class HeyEarth {
    public static void main(String[] args){//TODO Auto-generated method stub

Step 8: To print the message "Hey Earth!" And then run the program's code.

package newpackage;
 public class HeyEarth {
  public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hey! Earth"); }

Step 9: The result of the Hey application will come.


Java is both a platform and a programming language. Programming with Java is high-level, reliable, object-oriented, and secure. Java code is compiled using the Javac command, and it is executed using the Java program. The most recent version of Java was published on September 15, 2020. Learners eager to grasp Java fundamentals can benefit from this thorough explanation of how to install Java in Linux OS.


1. How to uninstall Java in Linux?

Use the  sudo apt remove default-jdk command if you need to uninstall any of the installed Java packages.

2. How to install Java in Linux using Yum?

The most recent version of Java is OpenJDK 11, which can be installed using yum before the command is executed. 

3. How to install Java in Linux using Putty?

After connecting to the Linux system through SSH, enter the command "sudo apt install default-jdk" in the terminal to install Java on Linux using Putty.

Leave a Reply

Your email address will not be published. Required fields are marked *