Minecraft

How to Install Java on Ubuntu 18.04

Minecraft·March 22, 2026·22 min read

How to Install Java on Ubuntu 18.04

This article will teach you how to install Java on Ubuntu 18.04. The commands will work on any private server or computer running the latest version, Ubuntu 18.04 Bionic Beaver, as well as on 16.04 and other long-term support (LTS) versions. Java is generally distributed in three editions: Micro (ME), Enterprise (EE) and Standard Edition (SE). For this guide, we will use Java SE 11 (LTS).

In general, Java is one of the leading programming languages in the world. It was created to have as few dependencies as possible, allowing application developers to apply the "write once, run anywhere" philosophy. As a result, compiled Java code can run on any platform that supports Java. You can use it to build everything from simple web applications to more advanced software.

Without further ado, let us see how we can install Java on Ubuntu 18.04.

1. JDK or JRE?

The OpenJDK (Java Development Kit) and Oracle JRE (Java Runtime Environment) are the two main kits you will be working with. Oracle Java contains the JVM, the Java program, along with other infrastructure, while the JDK is a superset of JRE. The JDK is essentially an SDK (Software Development Kit), as it gives you access to everything in JRE plus tools like jdb, javadoc and the compiler itself, javac.

If you are not interested in compiling Java software, the JRE will be sufficient. If this changes, you can upgrade it later.

The following commands assume you are already using a root user, but in case you are not, you should add "sudo" at the beginning of your commands.

2. Installing Java on Ubuntu Using the Default Package Manager:

- Update the current packages to the latest version:

```bash

apt-get update && apt-get upgrade

```

- Install the latest version of the Java Runtime Environment (JRE) by running the following command:

```bash

apt-get install default-jre

```

It is also possible to install the Java Development Kit (JDK) instead. It is required for certain programs or for compiling Java programs. JDK includes JRE, so there is no downside if you choose this method:

```bash

apt-get install default-jdk

```

- Java is ready to use on your Ubuntu system. You can verify that it was configured correctly with these commands:

```bash

java -version

javac -version

```

The output will be similar to:

```bash

openjdk version "11.0.6" 2020-01-14

OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)

OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)

```

3. Installing Java on Ubuntu via Oracle JDK:

- Update your current packages to the latest version:

```bash

apt-get update && apt-get upgrade

```

- Install a third-party library managed by WebUpd8 that will facilitate the installation:

```bash

apt-get install software-properties-common

```

- Add the Java Uprising PPA with the following command:

```bash

add-apt-repository ppa:linuxuprising/java

```

- It may be useful to run a quick update while you are at it:

```bash

apt-get update

```

- Finally, install Java on your Ubuntu system with the following command and follow the on-screen instructions:

```bash

apt update; apt-get install oracle-java17-installer

```

- Make sure to choose "Yes" with your keyboard to accept the license terms and the installation will begin.

- Java is successfully installed. You can verify it by checking the version with these two commands:

```bash

java -version

javac -version

```

A similar output will appear:

```bash

java version "14" 2020-03-17

Java(TM) SE Runtime Environment (build 14+36-1461)

Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

```

4. Java Management:

- A single server can have multiple Java installations. You can set the default version using the following command:

```bash

update-alternatives --config java

```

The following output will be shown, where you can select the version you want to use as default:

```bash

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status

------------------------------------------------------------

0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode

1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode

* 2 /usr/lib/jvm/java-14-oracle/bin/java 1091 manual mode

Press <enter> to keep the current choice[*] or type selection number:

```

- You can also do this with other Java commands, such as:

```bash

update-alternatives --config javac

update-alternatives --config javadoc

update-alternatives --config jarsigner

```

5. Configuring the Java Home Environment:

- Another useful thing to know is how to set the JAVA_HOME variable. Most applications require it to find the location of your Java installation. The command used earlier can help you locate the Java installation path:

```bash

update-alternatives --config java

```

Once you have copied the installation path, you will need to edit the environment file located in the etc directory:

```bash

nano /etc/environment

```

- Add the following line at the end to set the JAVA_HOME value:

```bash

JAVA_HOME="/usr/lib/jvm/java-14-oracle/bin/java"

```

Important! Do not forget to update it with the actual path of your Java installation.

- Press CTRL+X to finish editing and save the changes. Then, apply the changes with the following command:

```bash

source /etc/environment

```

- You can verify if it is active by entering:

```bash

echo $JAVA_HOME

```

Conclusion:

Congratulations, you now know how to install Java on Ubuntu 18.04. You have also learned some basic concepts, such as setting the default Java version and defining the JAVA_HOME variable.

If you found this article helpful, feel free to share it with the world. If you have tips, suggestions

or ideas of your own, we look forward to them in the comments section below.

Still have questions?

Come chat with us and we will get back to you as soon as possible!

Contact Support