-
jdk下载清华开源镜像站https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/jdk/x64/linux/
-
将下载的jdk-8-linux.tar.gz的解压到/usr/java/包下
tar -vxf jdk-8-linux.tar.gz
-
配置环境变量
编辑profile文件修改profile的读写权限
chmod 666 /etc/profile vim /etc/profile 改回来 chmod 444 /etc/profile
vim /etc/profile
在适当位置添加以下内容:
export JAVA_HOME=/usr/jdk8u252-b09
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin
完成配置后,按ESC 键,然后输入:wq 保存并退出(:q! 退出不保存)
-
查看是否配置成功java -version
Command 'java' not found, but can be installed with: apt install default-jre apt install openjdk-11-jre-headless apt install openjdk-8-jre-headless
-
apt install openjdk-8-jre-headless
-
成功!
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)