Java is one of the most popular programming languages that is used to build various cross-platform applications. Java has been around for a very long time, and it still hasn’t stopped evolving, uniquely combining stability and innovation and staying at the top of the game. Java programs are extremely flexible as they run on any machine, regardless of its architecture or platform. This is possible because most computers, be it Windows, Macintosh, Unix, or Linux, are compatible with the Java Runtime Environment (JRE). If you are a developer looking to install Java on Ubuntu 18.04, you are at the right place.
Before we get into the Ubuntu Java installation process, let us first dive into the prerequisites.
Java Variations
Java comes in three different variations - Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME). In this tutorial, we are going to cover only the Standard Edition variation of Java, as this is what most developers use.
There are two different Java packages or bundles in most machine repositories. They are the Java Runtime Environment (JRE) and the Java Development Kit (JDK). As evident from their names, a JRE enables the running of various Java Programs and is usually in-built on every device; but if you wish to code and compile, want developing/debugging tools and libraries, then a JDK does the job for you.
Two major JDKs are popular and are used by developers the most right now - OpenJDK and Oracle Java. Both of them provide the same features, but Oracle Java has some additional commercial features and is used by some business organisations as well. This tutorial covers Ubuntu Java installations of both these packages. If you are unable to decide between OpenJDK and Oracle Java, it’s recommended that you install OpenJDK.
How To Install Java On Ubuntu - OpenJDK (Java 11)
Java 11 SE is the latest version of Java at the time of writing this tutorial. Follow the below-mentioned steps to know how to install Java on Ubuntu 18.04 - OpenJDK package:
Step 1: Open a Terminal Window.
Step 2: Update the apt package index with the syntax given below:
sudo apt update
Step 3: Once the package index is updated, check if Java is already installed using the syntax given below:
java -version
If Java is not installed, you will see the following output:
Output
Command 'java' not found, but can be installed with:
apt install default-jre
apt install openjdk-11-jre-headless
apt install openjdk-8-jre-headless
If Java is already installed, you will see the following output:
Output
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.7+10-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)
Step 4: If Java is not installed already, here’s the syntax to install it:
sudo apt install default-jdk
Step 5: Once Java is installed, you might want to verify the installation. This can be done by checking the java version as shown below:
java -version
After installation, you’ll see the version of Java installed on your output screen as shown below:
Output
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.7+10-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)
You have successfully now installed Java on Ubuntu 18.04. If you observe the syntax displayed in the output screen in step 5 (also the second output in step 3), you will know which version of Java you have installed along with the date of installation. In our example, we have installed version 11.0.7 on the 14th of April, 2020.
How To Install Java On Ubuntu - Oracle Java
Oracle’s licensing agreement doesn’t allow automatic Ubuntu Java installation through package managers. To install the Oracle JDK - the official version distributed by Oracle - you must manually download the JDK by creating an Oracle account and adding a new package repository for the actual installation process. Here are the steps you need to follow to install Java on ubuntu - Oracle JDK:
Step 1: Find out the version of the JDK you need to install. This version should match the version of the installer script. To check for the version on the installer script, visit the oracle-java11-installer page and look for the “bionic” package, beside which you will find the version you need to install. Let’s say it’s version 11.0.7 for instance.
Step 2: Visit the Oracle Downloads Page, and locate the version you need. Since you’ve to install Java on Ubuntu, you need to look for the .tar.gz package that’s compatible with Linux. You will be asked to agree to Oracle’s license agreement and only then start the download.
Step 3: Once the file download is complete, upload the file to the server on your local machine.
Step 4: Now you need to add a third-party repository that will let you install Oracle’s Java. The real Ubuntu Java Installation process begins here.
Step 5: Install the dependencies required to add a new repository. Type in the following command:
sudo apt install software-properties-common
Step 6: Enable Linux Uprising PPA by importing the signing key used to verify any software install:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EA8CACC073C3DB2A
You’ll see the following output:
Output
gpg: key EA8CACC073C3DB2A: public key "Launchpad PPA for Linux Uprising" imported
gpg: Total number processed: 1
gpg: imported: 1
Step 7: Use the add-apt-repository command to add the repo to your list of package sources:
sudo add-apt-repository ppa:linuxuprising/java
This is the message you will see on the output screen:
Output
Oracle Java 11 (LTS) and 12 installer for Ubuntu, Linux Mint and Debian.
Java binaries are not hosted in this PPA due to licensing. The packages in this PPA download and install Oracle Java 11, so a working Internet connection is required.
The packages in this PPA are based on the WebUpd8 Oracle Java PPA packages: https://launchpad.net/~webupd8team/+archive/ubuntu/java
Created for users of https://www.linuxuprising.com/
Installation instructions (with some tips), feedback, suggestions, bug reports etc.:
. . .
Press [ENTER] to continue or ctrl-c to cancel adding it
Press ENTER to continue with the installation process.
Step 8: Once the repository is added, update your package list to make the new software available for Ubuntu Java installation:
sudo apt update
Step 9: The Oracle JDK file you downloaded should be in /var/cache/oracle-jdk11-installer-local. Create this directory and move the Oracle JDK archive there:
sudo mkdir -p /var/cache/oracle-jdk11-installer-local/
sudo cp jdk-11.0.7_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/
Step 10: Finally, install the package:
sudo apt install oracle-java11-installer-local
Accept the license agreement, after which the installer will extract the Java package and install it.
You have now successfully completed installing Java on Ubuntu - Oracle JDK package.
Final Word
We now hope that this tutorial gave you clarity concerning both the concepts behind basic Java packages and how to install Java on Ubuntu. Ubuntu servers are widely used by developers who use Java. Are you one among them? Did you follow this tutorial for your Ubuntu Java installation?
If you are a programmer, then you definitely need cloud services to manage your files and documents. You should check out E2E cloud solutions provided by us at E2E Cloud. We are trusted by 3000 clients all over the world, and we are known to satisfy our customers with quality cloud solutions at affordable rates. Check for yourself!