How to set up JDK environment variables on CentOS?
There are two common methods for configuring the JDK environment variable in CentOS systems.
- Configure environment variables in the /etc/profile file.
- 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 - Save and exit the file, then execute the following command in the terminal to make the configuration take effect: source /etc/profile
- Configure environment variables in the ~/.bashrc file (for the current user).
- 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 - 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.