System version: Ubuntu 16.04
JDK version: jdk1.8.0_121
I have the latest version here, other versions are also available
sudo mkdir /java
sudo mv jdk-8u121-linux-x64.tar.gz /java
tar -zxvf jdk-8u121-linux-x64.tar.gz
sudo gedit /etc/environment
Add the following configuration at the end (the path after JAVA_HOME is the file location of jdk)
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export JAVA_HOME=/java/jdk1.8.0_121
Save and close after modification, and enter the following command to make the environment variable take effect immediately
source /etc/environment
sudo gedit /etc/profile
Add the following at the end of the file:
# set Java environment
export JAVA_HOME=/dengyang/jdk1.8.0_56
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
source /etc/profile
Reprinted from: http://www.linuxidc.com/Linux/2017-02/140908.htm
Recommended Posts