How to set up JDK environment variables on CentOS?

There are two common methods for configuring the JDK environment variable in CentOS systems.

  1. Configure environment variables in the /etc/profile file.
  2. Open the file /etc/profile and add the following lines to the end of the file:
    export JAVA_HOME=/path/to/your/jdk
    export PATH=$JAVA_HOME/bin:$PATH
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  3. Save and exit the file, then execute the following command in the terminal to make the configuration take effect: source /etc/profile
  4. Configure environment variables in the ~/.bashrc file (for the current user).
  5. Open the ~/.bashrc file and add the following lines to the end of the file:
    export JAVA_HOME=/path/to/your/jdk
    export PATH=$JAVA_HOME/bin:$PATH
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  6. Save and exit the file, then run the following command in the terminal to apply the configuration: source ~/.bashrc

Replace the /path/to/your/jdk in the above configuration with the actual path to your JDK installation. After the configuration is complete, you can use the java -version command in the terminal to verify if the JDK environment variable is set up successfully.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds