How to Install Oracle Java JDK 11 on Ubuntu 18.04 / 16.04 / 18.10

A new version of Oracle Java 11 has been released and this tutorial is going to show students and new users how to easily install it on Ubuntu 18.04 / 18.04 and 18.10 desktops…

If you’re going to be developing apps based on Java, then you’re definitely going to need Java JDK installed… the steps below show you how to do it on Ubuntu easily…..

Oracle Java JDK is a development environment for developing applications and tools based on Java… It can also be used for testing applications and program developed using the Java programming language.

There is an open source version of Java JDK ( OpenJDK ) that can be installed easily using the apt-get command…. However, this post is going show you how to download and install Oracle Java from its original repository instead of the opensource version…

To get Java JDK installed, follow the steps below:

Step 1: Download Java JDK

Download the latest Java SE Development Kit 11 LTS release from it from the link below….

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Take notes of the version number you’re downloading… If there’s a newer version number then the one below, select it instead…

You can also easily install Java DEB package by running the commands below…

cd /tmp
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" \
  http://download.oracle.com/otn-pub/java/jdk/11+28/55eed80b163941c8885ad9298e6d786a/jdk-11_linux-x64_bin.deb

Step 2: Install Java from the DEB package

Now that you’ve downloaded the correct archive package for your system, run the commands below to install Java…

sudo dpkg -i jdk-11_linux-x64_bin.deb

After that, run the commands below to configure Oracle Java on Ubuntu… The commands below configure Ubuntu to use Java alternatives….

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11/bin/java 2
sudo update-alternatives --config java

If you have other versions of Java installed and you ran the commands above, you should see a prompt to select the version of Java you want to make the default… If you don’t have another versions of Java installed, then the commands will return nothing…

Next, run the commands below to make Java 11 to be the default Java compiler for your Ubuntu desktop…

sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-11/bin/jar 2
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11/bin/javac 2
sudo update-alternatives --set jar /usr/lib/jvm/jdk-11/bin/jar
sudo update-alternatives --set javac /usr/lib/jvm/jdk-11/bin/javac

That should get Java installed and configured…..

Run the commadns below see if Ubuntu recognizes Java..

java –version

You should see the output below:

java 11 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)

Step 3: Create Java Environment Variables

To set JAVA environment variables, create a new file in the /etc/profile.d directory for Java JDK…

sudo nano /etc/profile.d/jdk.sh

Then copy and paste the lines into the end of the file and save…

export J2SDKDIR=/usr/lib/jvm/java-11
export J2REDIR=/usr/lib/jvm/java-11
export PATH=$PATH:/usr/lib/jvm/java-11/bin:/usr/lib/jvm/java-11/db/bin
export JAVA_HOME=/usr/lib/jvm/java-11
export DERBY_HOME=/usr/lib/jvm/java-11/db

Next, run the commands below

source /etc/profile.d/jdk.sh

The commands above should configure Java to work and function with Ubuntu. To test if Java is installed correctly, run the commands below.

You should see Java as been installed.

java –version

java 11 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)

Congratulations! You’ve just successfully install Java JDK 11 on Ubuntu 16.04 / 18.04 / 18.10

Summary:

This brief tutorial shows students and new users how to easily install Java JDK on Ubuntu 16.04 / 18.04 / 18.10 desktops…. There are alternate methods that are available across the internet that show users how to install Java from third-party PPAs or the OpenJDK versions.

This method installs the original versions from Oracle.

Enjoy!

You may also like the post below:

How to Install LEMP on Ubuntu 16.04 / 18.04 / 18.10