Install Java manually on Linux

Manual installation provides the user with the highest level of control over the Java runtime environment.
32 readers like this.
How Linux got to be Linux: Test driving 1993-2003 distros

Internet Archive Book Images. Modified by Opensource.com. CC BY-SA 4.0

It is easy to use your Linux distribution's package management tool to install the Java software packages. However, sometimes you need to do a manual installation of Java. This is of particular importance to administrators of Java-based application servers such as Tomcat or JBoss. Many open source and proprietary software products rely on these services.

Developer or Runtime kit?

The Java Virtual Machine (JVM) is provided in two different forms: The Java Development Kit (JDK) or the Java Runtime Environment (JRE).

Software developers usually need the JDK. It contains the binaries necessary for compiling, running, and testing the source code. To deploy a pre-built Java application generally only requires the JRE. It doesn't include the compilers and other development tools. The JRE is typically installed in production environments due to increased security and space limitations.

Get Java

You can download open source Java software from the internet. You can find downloads of OpenJDK tarballs at Red Hat Developer, Adoptium.net, or the Zulu Community edition from Azul.

Install Java

Set up a directory to hold the Java files. I like to create one simply called java so I can download and extract the tarball in a dedicated directory.

$ mkdir -p java/jdk

Let's use the JDK in this example. Save the downloaded file to the jdk directory. Then change into that directory:

$ cd java/jdk
$ ls
OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz

Extract the tarball. Note that tar will create a new directory:

$ tar xvzf OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz
$ ls
jdk-11.0.12+7 OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz

Confirm the version of the new JVM using the -version option:

$ cd jdk-11.0.12+7/bin
$ ./java -version

The version output of the JVM looks similar to this:

openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

Environment variables

To ensure that a given application works correctly, it needs to know exactly how to locate the JVM. Two main variables should be set: JAVA_HOME and PATH:

$ echo $JAVA_HOME
$ echo $PATH

These can be set in the user's .bashrc file. Make sure that the variables come after any existing code that sets PATH:

#Set the JAVA_HOME
export JAVA_HOME=~/java/jdk/jdk-11.0.12+7
#Add the JAVA_HOME to the PATH
export PATH="$JAVA_HOME/bin:$PATH"

Manual install situations

Different situations require a manual installation of Java. Consider the following three scenarios.

One situation could be a requirement for a different, perhaps older, version of Java that is not available in your Linux distribution's software repositories.

Another example could be a security-driven decision that Java will not be installed on an operating system by default or at the "root level."

A third situation could be the need for several different versions of Java, usually because multiple instances of a J2EE web application are running on the same server. This OS sharing is less common today due to the increased usage of virtual machines and containers to isolate processes. However, the need to maintain varying container images continues to make the understanding of manual installation vital.

Wrap up

I demonstrated how I like to install the Java runtime environment but feel free to make up a convention that works best for your needs. Ultimately, manual installation provides the user with the highest level of control over the Java runtime environment.

What to read next
Tags
Alan Formy-Duval Opensource.com Correspondent
Alan has 20 years of IT experience, mostly in the Government and Financial sectors. He started as a Value Added Reseller before moving into Systems Engineering. Alan's background is in high-availability clustered apps. He wrote the 'Users and Groups' and 'Apache and the Web Stack' chapters in the Oracle Press/McGraw Hill 'Oracle Solaris 11 System Administration' book.

1 Comment

Good collection of informative stuff.I really like the articles and it has helped me a lot with my current js project.
www.rwit.io

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.