How to configure JDK installation on CentOS 7

To install and configure JDK on CentOS 7, please follow these steps:

  1. Download the JDK installation package.
  2. 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.
  3. Install JDK.
  4. 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/
  5. Navigate to the /usr/local directory and unpack the installation package:
    cd /usr/local
    sudo tar -zxvf jdk-11.tar.gz
  6. 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
  7. Check if the installation was successful by running: java -version.
  8. Set up environment variables.
  9. Open the ‘/etc/profile’ file using a text editor: sudo vi /etc/profile.
  10. 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
  11. Save and close the file.
  12. Execute the following command to apply the configuration: source /etc/profile.
  13. Configuration verification:
  14. 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.

bannerAds