How to configure JDK installation on CentOS 7
To install and configure JDK on CentOS 7, please follow these steps:
- Download the JDK installation package.
- Go to the official Oracle website (https://www.oracle.com/java/technologies/javase-jdk11-downloads.html) to download the JDK installation package for CentOS. Make sure to select the package that matches your system architecture and version.
- Install JDK.
- Open the terminal and use the following command to copy the JDK installation package to the /usr/local directory: sudo cp /path/to/jdk-11.tar.gz /usr/local/
- Navigate to the /usr/local directory and unpack the installation package:
cd /usr/local
sudo tar -zxvf jdk-11.tar.gz - Set the default JDK version by running the following commands in the terminal:
sudo alternatives –install /usr/bin/java java /usr/local/jdk-11/bin/java 1
sudo alternatives –install /usr/bin/javac javac /usr/local/jdk-11/bin/javac 1
sudo alternatives –install /usr/bin/jar jar /usr/local/jdk-11/bin/jar 1 - Check if the installation was successful by running: java -version.
- Set up environment variables.
- Open the ‘/etc/profile’ file using a text editor: sudo vi /etc/profile.
- Please add the following content at the end of the file (modify according to the JDK version you have installed): export JAVA_HOME=/usr/local/jdk-11
export PATH=$PATH:$JAVA_HOME/bin - Save and close the file.
- Execute the following command to apply the configuration: source /etc/profile.
- Configuration verification:
- Run the following commands to verify that the JDK environment variables are correctly configured: echo $JAVA_HOME echo $PATH
Now that you have successfully installed and configured JDK on CentOS 7, you can verify if it is working properly by using the command java -version.