There are different vendors that provide Java, such as Oracle Java (this is typically what people think of when then think of Java), OpenJDK, Adopt OpenJDK (adoptium), IBM Java, and the list goes on. Each flavor of Java has it's own installation process.
Oracle Java
- Go to https://www.java.com.
- Select Download.
- Select See all Java downloads.
- Under Linux, select one of the download options, such as RPM or tar.gz.
If you downloaded the RPM (Red Hat Package Manager) file, on a Red Hat distibution (CentOS, Fedora, Red Hat), the rpm install command can be used to install Oracle Java. By default, this should install Oracle Java at /usr/bin/java.
~]# rpm -ivh /tmp/jre-<version>-linux.rpm
If the /usr/lib/jvm directory does not exist, create the /usr/lib/jvm directory.
mkdir /usr/lib/jvm
Use the tar --extract command to extract the tar archive to the /usr/lib/jvm directory.
tar --extract --gunzip --preserve-permissions --file jre-<version>-linux-i586.tar.gz --directory /usr/lib/jvm
Create a symbolic link between the "jre" command in the extracted directory (e.g. /usr/lib/jvm/jre-<version>-linux-i586/jre) and /etc/alternatives.
ln -s /usr/lib/jvm/OpenJDK17U-jdk_x64_linux_hotspot_<version>/jre /etc/alternatives/oracle_java_<version>_jre
Create a symbolic link between /usr/bin/java and /etc/alternatives/oracle_java_<version>_jre. This will make it so that the "java" command points to /etc/alternatives/oracle_java_<version>_jre which in turn points to the "jre" command in the extracted directory (e.g. /usr/lib/jvm/re-<version>-linux-i586/jre).
ln -s /etc/alternatives/oracle_java_<version>_jre /usr/bin/java
OpenJDK
On a Debian system (Mint, Ubuntu), the apt-get install command can be used to install OpenJDK.
apt-get install openjdk-8-jre
On a Red Hat distibution (CentOS, Fedora, Red Hat), the dnf install or yum install comand can be used to install OpenJDK.
dnf install java-1.8.0-openjdk
Adoptium OpenJDK
- Go to https://www.adoptium.net/temurin/releases.
- Download the Linux tar (e.g. OpenJDK17U-jdk_x64_linux_hotspot_17.0.4.1_1.tar)
If the /usr/lib/jvm directory does not exist, create the /usr/lib/jvm directory.
mkdir /usr/lib/jvm
Use the tar --extract command to extract the tar archive to the /usr/lib/jvm directory.
tar --extract --preserve-permissions --file OpenJDK17U-jdk_x64_linux_hotspot_<version>.tar --directory /usr/lib/jvm
Create a symbolic link between the "jre" command in the extracted directory (e.g. /usr/lib/jvm/OpenJDK17U-jdk_x64_linux_hotspot_<version>/jre) and /etc/alternatives.
ln -s /usr/lib/jvm/OpenJDK17U-jdk_x64_linux_hotspot_<version>/jre /etc/alternatives/adoptium_openjdk_<version>_jre
Create a symbolic link between /usr/bin/java and /etc/alternatives/adoptium_openjdk_<version>_jre. This will make it so that the "java" command points to /etc/alternatives/adoptium_openjdk_<version>_jre which in turn points to the "jre" command in the extracted directory (e.g. /usr/lib/jvm/OpenJDK17U-jdk_x64_linux_hotspot_<version>/jre).
ln -s /etc/alternatives/adoptium_openjdk_<version>_jre /usr/bin/java
By default, this should install Java to /usr/lib/jvm/java-<version>/jre/bin/java.
It is also noteworthy that there are different types of OpenJDK that can be installed, such as the developer version of OpenJDK, and the debugging version. Typically, you will just install the OpenJDK Runtime Enviroment. However, if you need another version for some reason, the other versions can also easily be installed using yum or apt-get.
~]# yum search 1.7.0-openjdk
=================================================================
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without audio and video support
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
JAVA_HOME
The JAVA_HOME variable will need to be set for applications that use Java, such as Tomcat. JAVA_HOME is the path to the Java directory that contains the bin folder. For example, if you installed OpenJDK, JAVA_HOME will be /usr/lib/jvm/java-<version>/jre.
Oracle Java
JAVA_HOME="/usr"
OpenJDK
JAVA_HOME="/usr/lib/jvm/java-<version>/jre"
It is best to set the JAVA_HOME variable is the users .bash_profile file. After setting JAVA_HOME, the java -version command will dispaly the version of Java being used.
~]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
Did you find this article helpful?
If so, consider buying me a coffee over at