二进制jdk下载地址:https://www.openlogic.com/openjdk-downloads
选择64位 jdk的 java8下载,然后解压
$ cd /home/ec2-user/config/
$ tar xf openlogic-openjdk-8u382-b05-linux-x64.tar.gz
$ mv openlogic-openjdk-8u382-b05-linux-x64 openjdk-8
编辑环境变量文件,然后重加载,以下三个文件都得修改
$ vim /etc/profile
#java home
export JAVA_HOME=/home/ec2-user/config/ops/java8/jdk-8
export PATH=${JAVA_HOME}/bin:$PATH
$ source /etc/profile (重加载)
编辑.bashrc文件
$ vim ~/.bashrc
export JAVA_HOME=/home/ec2-user/config/ops/java8/jdk-8
export PATH=${JAVA_HOME}/bin:$PATH
$ source ~/.bashrc (重加载)
编辑.bash_profile文件
$ vim ~/.bash_profile
export JAVA_HOME=/home/ec2-user/config/ops/java8/jdk-8
export PATH=${JAVA_HOME}/bin:$PATH
$ source ~/.bash_profile (重加载)
测试
$ java -version
openjdk version "1.8.0_382-382"
OpenJDK Runtime Environment (build 1.8.0_382-382-b05)
OpenJDK 64-Bit Server VM (build 25.382-b05, mixed mode)
如果主机有多个用户,就切换到不同用户分别编辑上述三个文件重新加载即可