How To

Install Java on Ubuntu 18.04: OpenJDK 11 and OpenJDK 8

Many modern programs require Java to run. From development tools like Eclipse to search systems like Elasticsearch, Java is a core package for web hosts.

There are different versions of Java available. You can use OpenJDK, which is the open source version, or the official Oracle Java. For almost all tasks, OpenJDK is the best choice because it is free to use and easy to install.

This tutorial will show you how to install Java on Ubuntu 18.04, choose a default version, and set up your system environment.

Install the Default Java Version: OpenJDK 11

The default Java version in Ubuntu 18.04 is OpenJDK 11. This version is a long-term support release and is the standard for most modern systems.

Open your terminal and update the package list:

bashsudo apt update

Install the full development kit by running:

bashsudo apt install default-jdk

Verify that the installation was successful:

bashjava -version

The output will display the installed Java version. If you only need to run Java apps and do not need to build them, you can install the runtime environment instead by running sudo apt install default-jre.

Install OpenJDK 8

Some older programs do not work with newer Java versions. If you run software that requires Java 8, you can install OpenJDK 8 on the same machine.

Update your package index and run this install command:

bashsudo apt updatesudo apt install openjdk-8-jdk

Confirm the installation by checking the version again:

bashjava -version

The output will show version 1.8.0 to confirm that the package was installed correctly.

Choose the Default Java Version

If you have both Java 11 and Java 8 on your server, you can choose which one the system uses by default.

Run the configuration tool:

bashsudo update-alternatives --config java

The terminal will print a list of all installed Java versions. Each version has a number next to it. Type the selection number for the version you want to use and press Enter.

Set the JAVA_HOME Variable

Many Java programs look for the JAVA_HOME variable to find where Java is installed.

First, locate the path of your default Java version using the configuration command from the previous section. Copy the path to the directory, leaving out the /bin/java part.

Open the system environment file:

bashsudo nano /etc/environment

Add the following line at the end of the file:

textJAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

Save your changes. Reload the file to apply the environment changes to your current session:

bashsource /etc/environment

Confirm the path by printing the variable:

bashecho $JAVA_HOME

You have installed Java and set up your system path. Now you can run Java apps or start building your own. If you have any questions about this guide, leave a comment below.

Cyber Defence

Recent Posts

What Is a Data Protection Platform and Why Your Organization Needs One

A data protection platform is a unified system that helps organizations discover, classify, monitor, and…

4 days ago

How Swiss Privacy Rules Affect AI Companies Under GDPR

AI companies operating in or around Switzerland face a compliance challenge that most legal teams…

6 days ago

Swiss FADP vs EU GDPR: Key Differences for AI and Data Privacy

Two major data privacy laws now govern how organizations handle personal data across Europe; the…

7 days ago

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

1 month ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

1 month ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 months ago