Installing and Configuring JDK on Linux Systems
Install JDK via Yum Package Manager
To install Java using Yum, first list available Java packages:
yum list java*
Proceed to install a specific JDK version, such as OpenJDK 8:
yum install java-1.8.0-openjdk.x86_64
After installation completes, verify the JDK installation:
java -version
Yum installs Java under /usr/lib/jvm. Configure environment variables by editing the system profile:
vi /etc/profile
Append these lines to the file:
# Java environment configuration
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
Apply the changes immediately:
source /etc/profile
Manual Installation Using Downloaded JDK Archive
Download the JDK archive, for example jdk-8u281-linux-x64.tar.gz, from Oracel's website. Transfer the file to your Linux server using tools like SCP or SFTP.
Extract the archive in the target directory:
tar -xzf jdk-8u281-linux-x64.tar.gz -C /opt
Set up environment variables by editing /etc/profile:
vi /etc/profile
Add these configurations at the end:
# Java environment setup
export JAVA_HOME=/opt/jdk1.8.0_281
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
Reload the profile to activate the settings:
source /etc/profile
Confirm the installation by checking the Java version:
java -version