How to Properly install Java in RedHat 8
There are various methods to install Java in Red Hat Enterprise Linux (RHEL). Here are the main ones which is easy and hassle free:
- Using YUM Package Manager: If you are a subscribed or have managed to configure repo in Red Hat, you can directly install the OpenJDK, the open-source implementation of Java Platform using YUM (Yellowdog Updater Modified)Package manager.
sudo yum install java-11-openjdk-devel # For Java 11
OR,
sudo yum install java-1.8.0-openjdk-devel # For Java 8
2. Using RPM Package: You can download the RPM package directly from the Oracle Website (https://www.oracle.com/downloads/#category-java) and install it using RPM command.
sudo rpm -ivh jdk-11_linux-x64_bin.rpm # Replace with the actual file name
My recommended installation is below:
3. Using an Archive: If you want to use Java as User with no root privileges, it is useful to install using JRE (Java Runtime Environment) using an archive. Download the archive file from Red Hat Customer Portal (You can signup using your regular mail), https://access.redhat.com/jbossnetwork/restricted/listSoftware.html?product=core.service.openjdk&downloadType=distributions
Download the suitable version file, I have downloaded the below file.
Extract the file using tar:
tar -xf javafile.tar.xz
Copy it to the suitable location, I prefer /usr/local/ and give adequate permissions to user who wants to use Java.
You can create a Symbolic Link for easier upgrades which is useful to persistent systems.
ln -s ~/jres/java-1.8.0-openjdk-xxxxx.jre.exx.x86_64 ~/jres/java-x
Now, configure the JAVA_HOME environment variables, which is useful to run java from anywhere in terminal.
You can also verify it using “printenv | grep JAVA_HOME”
Also, make sure to export the bin directory of the generic JRE path to the PATH environment variable.
export PATH=”$JAVA_HOME/bin:$PATH”
Alternatively, you can also edit the Source file of user’s profile, i.e. .bash_profile, to contain the Java path and environment variables. Don’t forget to run source after editing the profile file.
After any of the above process to install the Java, don’t forget to check if java is installed properly or not.
This is just a reference post, you can always refer to below references.
References: