Installing Oracle Java on Linux Manually

Reading Time: 2 minutes

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

Debian 10 64 Bit

Oracle Java 8 Update 261

Steps

1. Download the Java from the Oracle’s web site https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html

2. Unpack the tar file

tar zxvf jdk-8u261-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_261/ /usr/java

5. Install all the java commands using the alternatives

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.8.0_261/bin/java" 1

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.8.0_261/bin/javac" 1

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_261/bin/javaws" 1

sudo update-alternatives --install /usr/bin/jar "jar" "/usr/java/jdk1.8.0_261/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_261

7. Add Java home to the Global Environment

sudo nano /etc/profile.d/java.sh

7.1. And add the below line and save

export JAVA_HOME=/usr/java/jdk1.8.0_261 
export JRE_HOME=$JAVA_HOME/jre 
export PATH=${JAVA_HOME}/bin:${PATH}
export PATH=${JRE_HOME}/bin:${PATH}

8. Make the file executable and Reload the “sh” file in the system

chmod +x /etc/profile.d/java.sh
source /etc/profile.d/java.sh

9. Check the installation for Java

java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)

10. Check the installation for Java Compiler

javac -version
javac 1.8.0_261

11. Check the installation for Java Web Start

javaws -version
Java(TM) Web Start 11.261.2.12-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