Installing Oracle Java on Ubuntu and Fedora

Reading Time: 1 minute

Description

In this article we will install Oracle’s Java, besides the OpenJDK can be shipped with the package managers in the distros. This way will allow you to end-to-end fully install Oracle JDK. The version I used was against version 8, but you can also use the same way for the other versions as well

Specifications

Ubuntu 18.04 LTS 64 Bit

Oracle Java 8 Update 181

Steps

1. Download the Java from the Oracle’s web site

2. Unpack the tar file

tar zxvf jdk-8u181-linux-x64.tar.gz

3. Create a folder in the usr location

sudo mkdir /usr/java

4. Move all the files from the unzipped location to the newly created folder

sudo mv jdk1.8.0_181/ /usr/java

5. Install all the java commands using the alternatives

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.8.0_181/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.8.0_181/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_181/bin/javaws" 1
sudo update-alternatives --install /usr/bin/jar "jar" "/usr/java/jdk1.8.0_181/bin/jar" 1

6. Fix the permissions for the Java entries

sudo chmod a+x /usr/bin/java 
sudo chmod a+x /usr/bin/javac 
sudo chmod a+x /usr/bin/javaws
sudo chmod a+x /usr/bin/jar
sudo chown -R root:root /usr/java/jdk1.8.0_181

7. Add Java home to the Global Environment

sudo nano /etc/environment

7.1. And add the below line and save

JAVA_HOME=/usr/java/jdk1.8.0_172
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH

8. Reflect the Global Environment changes

source /etc/environment
. /etc/environment

9. Check the installation for Java

java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

10. Check the installation for Java Compiler

javac -version
javac 1.8.0_181

11. Check the installation for Java Web Start

javaws -version
Java(TM) Web Start 11.181.2.13-fcs

11. Check the installation for Jar

jar
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
sudo update-alternatives --config jar

Leave a Reply

Your email address will not be published. Required fields are marked *