Installing Java on CentOS 7 can be done using the package manager "yum". Here is an example of the steps to install Java on a CentOS 7 system using yum:
- Update the package lists on your system by running the following command:
sudo yum update
- Install the OpenJDK package by running the following command:
sudo yum install java-1.8.0-openjdk
- Verify that Java is installed by running the following command:
java -version
- To set the default Java version, you can use the alternatives command:
sudo alternatives --config java
You will be prompted to choose the version of Java you want to use as the default. Select the appropriate option by entering the number next to it.
To set the JAVA_HOME environment variable, you can add the following line to your /etc/environment file:
export JAVA_HOME="/usr/lib/jvm/jre-1.8.0-openjdk"
- To make the changes take effect immediately, you can run the following command:
source /etc/environment
- Verify that the JAVA_HOME variable is set by running the following command:
echo $JAVA_HOME