How to Download and Install Oracle JAVA 8 on Ubuntu 18.04/16.04 LTS

Updated: May 29, 2020 by Unity

How to Download and Install Oracle JAVA 8 on Ubuntu 18.04 LTS Manually.

Table of Contents

Introduction

Java 8 Features:

Prerequisites

Step 1: Download Oracle Java 8

Step 2: Copy downloaded Setup and Extract

Step 3: Install Oracle Java 8 on ubuntu with Alternatives

Step 4: Verify Update Alternatives

Step 5: Setting the JAVA_HOME and JRE_HOME Environment Variables

Step 6: Verify Java Version

Conclusion

Related Articles:

Introduction

Java is a set of software and specifications developed at Sun Microsystems. There are two tyes of Java Platforms are JDK (Java Development Kit) and JRE (Java Runtime Environment). Both are helpful for deploying applications on servers and debugging, JVM monitoring,developing.

Java是由Sun Microsystems 开发的一组软件和规范。Java平台有两种类型,分别是JDK(Java开发工具包)和JRE(Java运行时环境)两者都有助于在服务器上部署应用程序及调试, JVM监视, 开发

Java 8 Features:

To know more detailed features go through this link.

Prerequisites

  • Ubuntu Server 18.04 LTS
  • SSH access with sudo privileges

To check Ubuntu version:

$ uname -a

OR

$ cat /etc/os-release

Output

NAME="Ubuntu"

VERSION="18.04.3 LTS (Bionic Beaver)"

ID=ubuntu

ID_LIKE=debian

PRETTY_NAME="Ubuntu 18.04.3 LTS"

VERSION_ID="18.04"

HOME_URL="https://www.ubuntu.com/"

SUPPORT_URL="https://help.ubuntu.com/"

BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"

PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"

VERSION_CODENAME=bionic

UBUNTU_CODENAME=bionic

Follow the below steps to Install Oracle Java 8 on Ubuntu Manually using command line.

Step 1: Download Oracle Java 8

Generally Oracle will not allow to download directly without accepting their licences. We have to create one account in Oracle java website by your personal or official mail. After accepting licence download the application from browser to local machine.

This link takes you to the Oracle home website Oracel Java SRE.

Once you opened above link goto “JAVA SE Development Kit 8u251” section, download “jdk-8u251-linux-x64.tar.gz” setup for Ubuntu click on “Accept License Agreement” Check Box.

After downloading into local machine, using SCP/SFTP/FTP transfer the file from local machine to Ubuntu server.

**Step 2: Copy downloaded Setup and Extract **

Create a directory /opt/jdk

$ sudo mkdir -p /opt/jdk

Copy the tar file from the directory copied from local machine to server to /opt/jdk folder and execute below command:

$ sudo cp -rf /home/unity/jdk-8u251-linux-x64.tar.gz /opt/jdk/
$ cd /opt/jdk
$ sudo tar -zxvf jdk-8u251-linux-x64.tar.gz

**Step 3: Install Oracle Java 8 on ubuntu with Alternatives **

Use update-alternatives command to configure java on your system

$ sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_251/bin/java 100

$ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_251/bin/javac 100

$ sudo update-alternatives --install /usr/bin/jar jar /opt/jdk/jdk1.8.0_251/bin/jar 100

After executing above command it shows below output:

Output:

update-alternatives: using /opt/jdk/jdk1.8.0_251/bin/java to provide /usr/bin/java (java) in auto mode

update-alternatives: using /opt/jdk/jdk1.8.0_251/bin/javac to provide /usr/bin/javac (javac) in auto mode

update-alternatives: using /opt/jdk/jdk1.8.0_251/bin/jar to provide /usr/bin/jar (jar) in auto mode

Note : Its not particularly o/p if you have installed open jdk before

Step 4: Verify **Update Alternatives **

Enter below command shows output:

$ sudo update-alternatives --display java

 java - manual mode

 link best version is /usr/lib/jvm/java-13-oracle/bin/java

 link currently points to /opt/jdk/jdk-13.0.2/bin/java

 link java is /usr/bin/java

slave java.1.gz is /usr/share/man/man1/java.1.gz

/opt/jdk/jdk-12.0.2/bin/java - priority 

/opt/jdk/jdk-13.0.2/bin/java - priority 1

/opt/jdk/jdk1.8.0_241/bin/java - priority 100

/usr/lib/jvm/java-13-oracle/bin/java - priority 1091

slave java.1.gz: /usr/lib/jvm/java-13-oracle/man/man1/java.1.gz 

To change for alternative mode:

$ sudo update-alternatives --config java

It prompts for selecting by 0,1,2..so choose accordingly:

Output

There are 4 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                  Priority   Status

------------------------------------------------------------

  0            /usr/lib/jvm/java-13-oracle/bin/java   1091      auto mode

  1            /opt/jdk/jdk-12.0.2/bin/java           2         manual mode

* 2            /opt/jdk/jdk-13.0.2/bin/java           1         manual mode

  3            /opt/jdk/jdk1.8.0_241/bin/java         100       manual mode

  4            /usr/lib/jvm/java-13-oracle/bin/java   1091      manual mode

Press <enter> to keep the current choice[*], or type selection number: 3

update-alternatives: using /opt/jdk/jdk1.8.0_241/bin/java to provide /usr/bin/java (java) in manual mode

Step 5: Setting the JAVA_HOME and JRE_HOME Environment Variables

To define the enviroment variable:

$ sudo vim /etc/environment

Paste the below variable on the file:

JAVA_HOME=/opt/jdk/jdk1.8.0_251
JRE_HOME=/opt/jdk/jdk1.8.0_251/jre

To check variables defined:

$ source /etc/environment
$ echo $JAVA_HOME

Output

/opt/jdk/jdk1.8.0_251
$ sudo apt-get update

Step 6: Verify Java Version

To check the java version:

$ java -version

Output

java version "1.8.0_251"

If you seeing output like above then we have successfully set up the Java 8 on Ubuntu.

Conclusion

In this article, We have downloaded Oracle Java 8 from official site, installed using command line, configured JAVA_HOME and JRE_HOME, verified installed version.

posted @ 2020-05-29 15:45  PrimerPlus  阅读(565)  评论(0编辑  收藏  举报