Installing Java on CentOS/RHEL using yum
Many applications require Java to run, making it a vital part of many Linux systems. CentOS/RHEL, popular operating systems used in server environments, offer an easy way to install Java using the yum
package manager.
Here's how to install Java on CentOS/RHEL using yum
:
1. Install the Java Development Kit (JDK)
The JDK is a complete development environment containing tools for compiling and running Java programs.
Original Code:
sudo yum install java-11-openjdk-devel
This command installs the OpenJDK 11 JDK.
Explanation:
sudo
allows you to run the command with root privileges, which is necessary to install packages.yum
is the package manager used in CentOS/RHEL.install
is the command to install packages.java-11-openjdk-devel
is the package name for OpenJDK 11 JDK, including development tools.
You can replace java-11-openjdk-devel
with different versions of OpenJDK, like java-8-openjdk-devel
or java-17-openjdk-devel
.
2. Verify the Installation
After the installation, you can verify if Java is installed correctly by running:
java -version
This should print the Java version you just installed.
3. Set Java Environment Variables
For applications to find and use the installed Java, you need to set environment variables. This can be done by editing the /etc/profile
file.
Original Code:
sudo nano /etc/profile
Add the following lines at the end of the file:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.17.0.8-1.el8_6.x86_64/
export PATH=$PATH:$JAVA_HOME/bin
Explanation:
export JAVA_HOME
defines the directory where Java is installed.export PATH
adds the Java binaries directory to your system's path, allowing you to execute Java commands from any directory.
4. Apply Changes
Finally, you need to apply the changes you made to the /etc/profile
file:
source /etc/profile
Additional Information:
- You can find a list of available Java packages by running
yum search java
. - If you need a specific Java version, you can find it on the Oracle website or OpenJDK website.
- Oracle Java requires a license agreement, while OpenJDK is free and open-source.
By following these steps, you can successfully install and set up Java on your CentOS/RHEL system for your desired applications.