centOS7 How to install jdk1.8
- 2020-11-18 06:35:38
- OfStack
1. Create a new Java folder under /usr/local
mkdir /usr/local/java
Copy jdk to /usr/local/java into the java folder and unzip the package
tar xvf jdk-8u181-linux-x64.tar.gz
2, set the environment variable here to use the global setting method, is to modify etc/profile, it is the common environment variable for all users find /etc/profile, edit, add at the end
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
export JRE_HOME=/usr/local/java/jdk1.8.0_181/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH
During the above process, do not add Spaces to the equal sign, otherwise "not valid identifier" will appear, because source /etc/profile cannot recognize the extra Spaces, which will be interpreted as part of path 1.
And save it.
Run the following command for profile to take effect.
source /etc/profile
3. Check whether the terminal is successful
java -version
javac
conclusion