Install JAVA on Centos and windows. Also, set JAVA_HOME using the YUM repo

DevOpsLab-LiveScenarios
3 min readJan 17, 2024

--

Steps:

  1. Check Centos Version:

cat /etc/redhat-release or cat /etc/os-release

Update the System:

sudo yum update

2. Check which versions of Java are available in the YUM repository on Red Hat/Centos

sudo yum list available 'java-*-openjdk*'

3. Use devel package as OpenJDK development package, includes headers and static libraries using below yum command:

yum install java-17-openjdk-devel.x86_64 -y

4. Once installed, check for the version using

java -version

5. Check java is installed on which path, using:

echo $(dirname $(dirname $(readlink $(readlink $(which javac)))))

Here,
which javac: Finds the location of the javac executable.

readlink $(which javac): Resolves symbolic links to get the real path of the javac executable.

readlink $(readlink $(which javac)): Resolves symbolic links again in case there are nested links.

dirname $(readlink $(readlink $(which javac))): Obtains the directory containing the javac executable.

dirname $(dirname $(readlink $(readlink $(which javac)))): Obtains the parent directory of the directory containing javac.

O/P: /usr/lib/jvm/java-17-openjdk-17.0.6.0.9–0.3.ea.el8.x86_64

6. To setup JAVA_HOME, either use ~/.bashrc file or ~/.bash_profile

vim ~/.bash_profile

JAVA_HOME=/usr/lib/jvm/java-17-openjdk-17.0.6.0.9–0.3.ea.el8.x86_64
PATH=$PATH:$JAVA_HOME/bin:$HOME/bin
export PATH

7. To apply the changes, run the following command:

source ~/.bash_profile

8. Check for JAVA version and JAVA_HOME

===============================================================

JAVA for windows:

Download jdk-*_windows-x64_bin.exe from https://www.oracle.com/sg/java/technologies/downloads/#jdk22-windows

Install and set JAVA_HOME path:

JAVA_HOME — C:\Program Files\Java\jdk-20

edit path and set —

%JAVA_HOME%\bin

Restart the system and check the java version:

java -version

Happy Learning!! :)

--

--