Get the highlights in your inbox every week.
Install Java manually on Linux | Opensource.com
Install Java manually on Linux
Manual installation provides the user with the highest level of control over the Java runtime environment.
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.
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
Extract the tarball. Note that
tar will create a new directory:
$ tar xvzf OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz
Confirm the version of the new JVM using the
$ 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)
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
#Add the JAVA_HOME to the 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.
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.