How To Install The Java Runtime And Development Kit On Ubuntu

Install Java On Ubuntu
Install Java On Ubuntu.
01
of 06

How To Get The Official Oracle Java Runtime Environment (JRE) For Ubuntu

Install Java On Ubuntu
Install Java On Ubuntu.

The Java Runtime Environment is required for running Java applications within Ubuntu.

Fortunately when it comes to installing Minecraft there is a snap package available which makes it incredibly easy as shown by this guide.

Snap Packages provide a way of installing an application along with all of its dependencies in a container so that there are no conflicts with other libraries and the application is almost guaranteed to work.

However snap packages do not exist for all applications so you will need to install a version of Java yourself.

There are two versions of the Java Runtime Environment available. The official version is released by Oracle. This version is not available via the "Ubuntu Software" tool which is generally used for installing applications in Ubuntu. 

The Oracle website doesn't include a Debian package either. Debian packages with the ".deb" extension are in a format which is easy to install within Ubuntu.

Instead you have to install the package by installing via a "tar" file. A "tar" file is basically a list of files all stored under one filename which when installed places the files in their correct folders.

The other Java Runtime Environment available is an open source alternative called OpenJDK. This version is also not available via the "Ubuntu Software" tool but is available from the command line using apt-get.

If you intend to develop Java programs you will want to install the Java Development Kit (JDK) instead of the Java Runtime Environment (JRE). As with the Java Runtime Environments the Java Development Kits are available as an official Oracle package or an open source package.

This guide will show you how to install both the official Oracle Runtime and Development Kits as well as the open source alternatives.

To start installing the official Oracle version or the Java Runtime Environment visit https://www.oracle.com/uk/java/index.html.

You will see 2 links available:

  1. Java For Developers
  2. Java For Consumers

Unless you intend to develop Java applications you should click on the link for "Java For Consumers".

You will now see a big red button called "Free Java Download".

02
of 06

How To Install The Official Oracle Java Runtime For Ubuntu

Install Oracle Java Runtime
Install Oracle Java Runtime.

 A page will appear with 4 links on it:

  • Linux RPM
  • Linux
  • Linux x64
  • Linux x64 RPM

The Linux RPM and Linux x64 RPM files are not for Ubuntu so you can ignore those links.

The Linux link is the 32-bit version of the Java Runtime and the Linux x64 link is the 64-bit version of the Java Runtime.

If you have a 64-bit computer you will probably want to install the Linux x64 file and if you have a 32-bit computer you will definitely want to install the Linux file.

After the relevant file has download open a terminal window. The easiest way to open a terminal window in Ubuntu is to press CTRL, ALT and T at the same time.

The first thing to do is find the name of the actual file that was downloaded from the Oracle website. To do this run the following commands:

cd ~/Downloads

ls jre*

The first command will change the directory to your "Downloads" folder. The second command provides a directory listing of all the files beginning with "jre".

You should now see a filename looking something like this:

jre-8u121-linux-x64.tar.gz

Take a note of the file name or select it with the mouse, right click and choose copy.

The next step is to navigate to the place where you plan to install Java and extract the zipped up tar file.

Run the following commands:

sudo mkdir /usr/java

cd /usr/java

sudo tar zxvf ~/Downloads/jre-8u121-linux-x64.tar.gz

The files will now be extracted into the /usr/java folder and that is it.

To remove the downloaded file run the following command:

sudo rm ~/Downloads/jre-8u121-linux-x64.tar.gz

The final step is to update your environment file so that your computer knows where Java is installed and which folder is the JAVA_HOME.

Run the following command to open the environment file in the nano editor:

sudo nano /etc/environment

Scroll to the end of the line that begins PATH= and before the final " enter the following

:/usr/java/jre1.8.0_121/bin

Then add the next line:

JAVA_HOME="/usr/java/jre1.8.0_121"

Save the file by pressing CTRL and O and exit the editor by pressing CTRL and X.

You can test whether Java is working by typing the following command:

java -version

You should see the following results:

Java Version 1.8.0_121

03
of 06

How To Install The Official Oracle Java Development Kit For Ubuntu

Oracle JDK Ubuntu
Oracle JDK Ubuntu.

If you plan to develop software using Java you can install the Java Development Kit instead of the Java Runtime Environment.

Visit https://www.oracle.com/uk/java/index.html and choose the option "Java For Developers".

You will see a fairly confusing page with a lot of links. Look for the link called "Java SE" which takes you to this page.

There are now 2 further options:

The Java JDK installs just the Java Development Kit. The Netbeans option installs a full development integration environment as well as the Java Development Kit.

If you click on the Java JDK you will see a number of links. As with the runtime environment you will want either the Linux x86 file for the 32-bit version of the development kit or the Linux x64 file for the 64-bit version. You do not want to click on the RPM links, instead click on the link ending in "tar.gz".

As with the Java Runtime Environment you will need to open a terminal window and search for the file you downloaded.

To do this run the following commands:

cd ~/Downloads

ls jdk*

The first command will change the directory to your "Downloads" folder. The second command provides a directory listing of all the files beginning with "jdk".

You should now see a filename looking something like this:

jdk-8u121-linux-x64.tar.gz

Take a note of the file name or select it with the mouse, right click and choose copy.

The next step is to navigate to the place where you plan to install the development kit and extract the zipped up tar file.

Run the following commands:

sudo mkdir /usr/jdk

cd /usr/jdk

sudo tar zxvf ~/Downloads/jdk-8u121-linux-x64.tar.gz

The files will now be extracted into the /usr/java folder and that is it.

To remove the downloaded file run the following command:

sudo rm ~/Downloads/jdk-8u121-linux-x64.tar.gz

The final step as with the runtime environment is to update your environment file so that your computer knows where the JDK is installed and which folder is the JAVA_HOME.

Run the following command to open the environment file in the nano editor:

sudo nano /etc/environment

Scroll to the end of the line that begins PATH= and before the final " enter the following

:/usr/jdk/jdk1.8.0_121/bin

Then add the next line:

JAVA_HOME="/usr/jdk/jdk1.8.0_121"

Save the file by pressing CTRL and O and exit the editor by pressing CTRL and X.

You can test whether Java is working by typing the following command:

java -version

You should see the following results:

Java Version 1.8.0_121

04
of 06

An Alternative Way To Install The Official Oracle Version Of Java In Ubuntu

Use Synaptic To Install Java Within Ubuntu
Use Synaptic To Install Java Within Ubuntu.

If the use of the Linux terminal is something you are not comfortable with you can use graphical tools to install the official version of the Java Runtime Environment and Development Kits.

This requires adding an external personal package archive (PPA). A PPA is an external repository not provided by Canonical or Ubuntu.

The first step is to install a piece of software called "Synaptic". Synaptic is a graphical package manager. It differs from the "Ubuntu Software" tool in that it returns all the results available in your available software repositories.

Unfortunately in order to install Synaptic you need to use the terminal but it really is just one command. Open a terminal by pressing CTRL, ALT and T at the same time.

Enter the following command:

sudo apt-get install synaptic

To launch Synaptic click on the icon at the top of the launch bar and type "Synaptic". When the icon appears click on it.

Click on the "Settings" menu and choose "Repositories".

The "Software and Updates" screen will appear.

Click on the tab called "Other Software".

Click on the "Add" button and enter the following into the window that appears:

ppa:webupd8team/java

Click on the "Close" button.

Synaptic will now ask to reload the repositories to pull in the list of software titles from the PPA you just added.

05
of 06

Install The Oracle JRE And JDK Using Synaptic

Install Oracle JRE And JDK
Install Oracle JRE And JDK.

You can now search for the Oracle Java Runtime Environment and Java Development Kits using the search feature within Synaptic.

Click on the "Search" button and enter "Oracle" into the box. Click the "Search" button.

A list of the available packages with the name "Oracle" will appear.

You can now choose whether to install the runtime environment or the development kit. Not only that though you can choose which version to install. 

It is currently possible to install as far back as Oracle 6 up until the new Oracle 9 which isn't in fully released. The recommended version is Oracle 8.

To actually install a package place a check in the box next to the item you wish to install and then click the "Apply" button.

During the installation you will be asked to accept the Oracle license.

This is actually a more simple route to installing Oracle but it does use a third party PPA and so there is no guarantees that this will always be an available option.

06
of 06

How To Install The Open Source Java Runtime And Java Development Kit

Open JRE And JDK
Open JRE And JDK.

If you prefer to use only open source software then you can install the open source versions of the Java Runtime and Development Kits.

You will need to install Synaptic in order to continue and if you didn't read the previous page the way to do this is as follows:

  • Open a terminal window by pressing CTRL, ALT and T
  • Enter the following command into the terminal window:

    sudo apt-get install synaptic

To launch Synaptic click on the icon at the top of the launch bar and type "Synaptic". When the icon appears click on it.

Within Synaptic all you need to do is click the "Search" button at the top of the screen and search for "JRE".

The list of applications include "Default JRE" for the open source version of the Java Runtime Environment or "OpenJDK".

To search for the open source version of the Java Development Kit click on the "Search" button and search for "JDK". An option called "OpenJDK JDK" will appear.

To install a package place a tick in the box next to the item you wish to install and click "Apply".