0% found this document useful (0 votes)
87 views

01-How To Install Java On Linux

This document provides instructions for installing Java on Linux in 3 main steps: 1) Installing the OpenJDK Java using yum install commands. 2) Installing the Oracle Java by downloading the RPM file directly or uploading it, then extracting and configuring it. 3) Configuring multiple Java versions by selecting a default with update-alternatives, and setting the JAVA_HOME environment variable in /etc/profile.

Uploaded by

Heba Refaie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

01-How To Install Java On Linux

This document provides instructions for installing Java on Linux in 3 main steps: 1) Installing the OpenJDK Java using yum install commands. 2) Installing the Oracle Java by downloading the RPM file directly or uploading it, then extracting and configuring it. 3) Configuring multiple Java versions by selecting a default with update-alternatives, and setting the JAVA_HOME environment variable in /etc/profile.

Uploaded by

Heba Refaie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

How to install Java on Linux

Installing the Open JDK

Install Java JDK (JDK will install the JRE implicitly) – so better install the JDK

The below command will install the Java 8 JRE

$ sudo yum install java-1.8.0-openjdk

The below command will install the Java 8 JDK

$ sudo yum install java-1.8.0-openjdk-devel

Installing the Oracle Java

If you need to install Oracle java, you can either download the JDK or JRE rpm from the Oracle page and
upload the rpm to the Linux machine

Or you can download the rpm directly using the wget command

To install the oracle JRE

cd /opt
sudo wget --no-cookies --no-check-certificate --header "Cookie:
gpw_e24=http://www.oracle.com; oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jre-8u51-linux-x64.tar.gz "

sudo tar xvf jre-8u51-linux-x64.tar.gz

sudo rm /opt/jre-8u25-linux-x64.tar.gz

sudo chown -R root: jre1.8.0_51

#to create symbolic link to /usr/bin/java


sudo alternatives --install /usr/bin/java java /opt/jre1.8.0_51/bin/java 1
To install the oracle JDK

cd /opt

$ sudo wget --no-cookies --no-check-certificate --header "Cookie:


gpw_e24=http://www.oracle.com; oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jre-8u51-linux-x64.tar.gz "

sudo tar xvf jdk-8u51-linux-x64.tar.gz

sudo rm /opt/jdk-8u51-linux-x64.tar.gz

sudo chown -R root: jdk1.8.0_51

#to create symbolic link to /usr/bin/java


sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_51/bin/java 1

Dealing with multiple installations/versions of java

Different installation/versions of java can coexist on the same server – you can see all the different
installation via the below command, also you can select the default version of java

sudo update-alternatives --config java


Setting up the JAVA_HOME environment variable

sudo update-alternatives --config java

A directory path listing for each installation is below:

/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.el7_1.x86_64
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85-2.6.1.2.el7_1.x86_64
/usr/lib/jvm/jre-1.6.0-openjdk.x86_64

To edit the environment file use your text editor and edit the following file:

sudo nano /etc/profile

Now that you are in the user profile file, add the following code, along with the Path of your installation
from the previous step, to the bottom. ( Example: JAVA_HOME=”YOUR_PATH”)

export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.el7_1.x86_64"

Reload the file so all your changes could take effect with the following command:

source /etc/profile

Verify that your implementations are correct with the following command. Confirm :

echo $JAVA_HOME

You might also like