How to install Java on a Linux computer

Overview: 
This article will walk you through the process of installing the official Oracle Java platform on your Linux machine.
 
Background: 
There are many Linux distributions available and many of them come with one or more Java platform/s pre-installed. In the vast majority of the cases the Java platform which comes pre-installed on a Linux machine is not the official Oracle Java, but another one such as OpenJKD or IBM Java. 
The Trader Workstation has been developed on the official Oracle Java platform and shows the most stable behavior and the best performances when run by the official Oracle Java process. Therefore we recommend to all the Linux users, who want to run the Trader Workstation, to install the official Oracle Java platform and set it as the preferred Java environment to be used by the operating system.
 

For the purpose of this guide, we will divide the Linux distributions nowadays available into three big families:

  1. APT based Linux distributions (Ubuntu, Mint) - those distributions use the Advanced Packaging Tool to fetch and install software packages in a semi-automatic way, resolving and taking care of dependencies. 
  2. RPM based Linux distributions (Suse, OpenSUSE, Red Hat, CentOS, Fedora, Oracle Linux) - those distributions allow the installation of software packages (.rpm files), which contain the binary files to be installed on the system and an integrated dependency checker script. The .rpm packages allow a simplified and smooth installation of software without requiring a deep knowledge of the system.
  3. Other Linux distributions  - those distributions may or may not use a specific package manager but all of them allow the installation of software using the source code package (.tar.gz) through a series of command to be issued on the Terminal.

 

How to install the official Oracle Java on APT based Linux distributions

The most simple way to install Java on Ubuntu or Mint is using the webupd8 repository. This method will install the latest version of JDK 8 and the JRE 8 browser plugin. The supported versions are: Ubuntu 15.04, 14.10, 14.04, 12.04 - Linux Mint 17.1, 17, 13

For details, please refer to: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

a. On your Linux machine, open the "Terminal". If you need help with accessing and using the Terminal, please refer to: https://help.ubuntu.com/community/UsingTheTerminal

b. Become root, by typing su on the Terminal and entering the super user password. Instead of becoming root, you can choose to use the sudo feature (which gives your user the root privileges for a single command). If you want to use sudo, just add sudo before each one of the commands you will enter in the Terminal. You will be requested to enter the sudo password.

c. Add the webupd8 repository by tiping add-apt-repository ppa:webupd8team/java Follow the instructions on the screen. You should be asked to press [ENTER] to continue. Once done, the repository will be added.

d. Type the command apt-get update

e. Enter the command: apt-get install oracle-java8-installer The process will download and install automatically the required packages along with their dependencies. Once the command has completed, the Oracle Java platform will be ready to be used.

Should you prefer to have control of all the phases of the installation, instead of relying on the APT facility, please refer to the instructions on this page: http://www.wikihow.com/Install-Oracle-Java-JRE-on-Ubuntu-Linux

 

How to install the official Oracle Java on RPM based Linux distributions

a. On your Linux machine, open the "Terminal". If you need help with accessing and using the Terminal, please refer to: https://help.ubuntu.com/community/UsingTheTerminal

b. Become root, by typing su on the Terminal and entering the super user password. Instead of becoming root, you can choose to use the sudo feature (which gives your user the root privileges for single commands). If you want to use sudo, just add sudo before each one of the commands you will enter in the Terminal. You will be requested to enter the sudo password.

c. Create the folder /usr/java by issuing the command mkdir /usr/java. If the directory already exists you will see a message indicating that. In this case you can proceed directly to point d.

d. Go to the page https://www.java.com/en/download/linux_manual.jsp

e. If you have a 32 bit system, download the file "Linux RPM" . If you have a 64 bit system, download the file "Linux64 RPM". In either case, please instruct your browser to save the file in the folder /usr/java or move the file to that foder once it has been downloaded.

f. Go back to the Terminal and move to the /usr/java folder by typing cd /usr/java

g. List the content of the folder by typing the command ls -la You should see the file you downloaded. It will be called jre-XuYY-linux-ARCH.rpm (where X is the Java family, YY the update number and ARCH will be i586 for 32 bit installer and x64 for 64 bit installer)

h.  Launch this command to perform the installation: rpm -ivh jre-XuYY-linux-ARCH.rpm  Obviously you need to use the real file name, for example jre-8u65-linux-x64.rpm

Once the installation has been performed, the Oracle Java should be ready to be used. Usually a system restart is not required on Linux machines. In case you see warning or error message/s during the installation, please check their content and search the Internet for possible solutions. Most of the time the warning/error messages maight refer to missing dependencies (this means that another package needs to be installed before you can install Java) or to unsufficient privileges (this means that you are launching the command with a regular user instead of "root"). If you cannot find the proper course of actions to overcome the issue, please refer to the support documentation or forums for your current Linux distribution.

 

How to install the official Oracle Java on other Linux distributions

If your Linux distribution does not support RPM or APT package managers, the installation of Oracle Java can be performed manually in this way:

a. On your Linux machine, open the "Terminal".

b. Become root, by typing su on the Terminal and entering the super user password. Instead of becoming root, you can choose to use the sudo feature (which gives your user the root privileges for single commands). If you want to use sudo, just add sudo before each one of the commands you will enter in the Terminal. You will be then required to enter the sudo password.

c. Create the folder /usr/java by issuing the command mkdir /usr/java. If the directory already exists you will see a message indicating that. In this case you can proceed directly to point d.

d. Go to the page https://www.java.com/en/download/linux_manual.jsp

e. If you have a 32 bit system, download the file "Linux" . If you have a 64 bit system, download the file "Linux x64". In either case, please instruct your browser to save the file in the folder /usr/java or move the file to that foder once it has been downloaded.

f. Go back to the Terminal and move to the /usr/java folder by typing cd /usr/java

g. List the content of the folder by typing the command ls -la You should see the file you downloaded. It will be called jre-XuYY-linux-ARCH.tar.gz (where X is the Java family, YY the update number and ARCH will be i586 for 32 bit installer and x64 for 64 bit installer)

h.  Launch this command to perform the installation: tar zxvf jre-XuYY-linux-ARCH.tar.gz  Obviously you need to use the real file name, for example jre-8u65-linux-x64.tar.gz

i. Once done, enter command ls -la You will see the folder /usr/java/jre1.X.0_YY (where X is the Java family, YY the update number)

l.  The Java executables are now present in the folder /usr/java/jre1.X.0_YY/bin 

m. Now check which is the symbolic link used by the system to access the java executables by entering the commands:

which java  - you will receive an output similar to this: /usr/bin/java  From now on we will refer to this path as javasympath.

which javac  - you will receive an output similar to this: /usr/bin/java  From now on we will refer to this path as javacsympath.

which javaws  - you will receive an output similar to this: /usr/bin/java  From now on we will refer to this path as javawssympath.

Unless your are launching the java applications using the full path (for example /usr/java/jre1.X.0_YY/bin/java ...), you would need to tell your system which java executables should be used when a generic java command is issued. In order to to this, you can either update your alternatives files (if your system supports them) or the symbolic links. Here below you can see the instructions, according to your system:

- If your system uses the alternatives files:

n.  Issue the following commands, paying attention to make the necessary substitutions .

update-alternatives --install javasympath java /usr/java/jre1.X.0_YY/bin/java 1

update-alternatives --install javacsympath javac /usr/java/jre1.X.0_YY/bin/javac 1

update-alternatives --install javawssympath javaws /usr/java/jre1.X.0_YY/bin/javaws 1

- If your system does not use the alternatives files:

n. Issue the following commands, paying attention to make the necessary substitutions .

ln -sf  /usr/java/jre1.X.0_YY/bin/java javasympath

ln -sf /usr/java/jre1.X.0_YY/bin/javac javacsympath

ln -sf /usr/java/jre1.X.0_YY/bin/javaws javawssympath