Configuring Java Environment Variables on Linux

1. Download Java

1. Download from the official website

2. Extract It

1
2
tar -zxvf jdk-8u211-linux-x64.tar.gz   # Extract the archive
mv jdk1.8.0_211/ /usr/local/           # Move the JDK to /usr/local

3. Configure Environment Variables

1
vim /etc/profile

Press i to start editing, then add the following lines at the end of the file. Replace /usr/local/jdk1.8.0_211 with your actual installation path:

1
2
3
export JAVA_HOME=/usr/local/jdk1.8.0_211
export PATH=.:$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Then run:

1
2
source /etc/profile     # Reload environment variables
java -version           # Check the installed Java version
转载请保留本文转载地址,著作权归作者所有