Install Java on Ubuntu

If you use LibreOffice you may have noticed that in order to benefit from the full functionality of the software e.g. use mail merge, table, query and form wizards, you will need to install the Oracle Java run-time environment. It’s a fairly simple process so I thought that It would be worth writing a tutorial on the subject. I am by no means a java expert and this tutorial is based on my own research online.

Java Versions

You can also choose between installing the java development kit (JDK) and the java runtime environment (JRE). Basically, If you are only interested in running java applications then you could install the JRE which comprises of the java virtual machine, core libraries and additional components to either run java applets or full applications.

If you want to develop applications then you would install the JDK which will take up more disk space, however, the JDK will install the JRE and, in addition, will install API classes, compiler, webstart and all the necessary files required to develop java applets and applications.

Installing the JRE/JDK

The easiest solution is to install the open source binaries (Open JDK) from the standard Ubuntu package repository. This is an open-source version of both JRE and JDK.

Before you go ahead and do that run the following command:

sudo apt-get update

This will check the Ubuntu repositories to see if there are any package updates. Once this has completed now check to see if Java is already installed on you computer. You can do this with the following command:

java -version

If you do not have any java installed on your computer you will see the following:

Command 'Java' not found, but can be installed with,

apt-get install default-jre
apt-get install openjdk-11-jre-headless
apt-get install openjdk-9-jre-headless
apt-get install openjdk-8-jre-headless

To install the default JRE use the following command:

sudo apt-get install default-jre

Running this version of Java will allow you to run most Java based software. Once installed verify the installation with:

java -version

You will now see the following:

Some Java versions will vary depending on which version of Ubuntu you are using. In this instance I am running OpenJDK 8 on Ubuntu 18.10

To check the current Java compiler use the following command:

javac -version

This will now display the current Java compiler version which in my case is javac 11.0.1.