参考:
https://www.vultr.com/docs/how-to-manually-install-java-8-on-ubuntu-16-04
所需Java软件包https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载对应版本,到用户根目录下的Downloads
sudo mkdir /usr/lib/jvm
cd /usr/lib/jvm
sudo tar -xvzf ~/Downloads/jdk-8u192-linux-x64.tar.gz
sudo vim /etc/environment
内容替换成:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_192/bin:/usr/lib/jvm/jdk1.8.0_192/db/bin:/usr/lib/jvm/jdk1.8.0_192/jre/bin"
J2SDKDIR="/usr/lib/jvm/jdk1.8.0_192"
J2REDIR="/usr/lib/jvm/jdk1.8.0_192/jre*
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_192"
DERBY_HOME="/usr/lib/jvm/jdk1.8.0_192/db"
# sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_192/bin/java" 0
# sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_192/bin/javac" 0
# sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_192/bin/java
# sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_192/bin/javac
update-alternatives --list java
update-alternatives --list javac
java -version
出现:
java version “1.8.0_192”
Java™ SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot™ 64-Bit Server VM (build 25.192-b12, mixed mode)
6.
javac -version
出现:
javac 1.8.0_192
成功!