linux 安装Openjdk1.8

 一、在线安装

1、更新软件包

sudo apt-get update

2、安装openjdk

sudo apt-get install openjdk-8-jdk

3、配置openjdk1.8

openjdk默认会安装在/usr/lib/jvm/java-8-openjdk-amd64

vim ~/.bashrc

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

export JRE_HOME=${JAVA_HOME}/jre

export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

export PATH=${JAVA_HOME}/bin:$PATH

刷新配置生效

source ~/.bashrc

二、离线安装

1、下载

使用下面地址下载配置环境变量即可。

下载地址 

2、安装

#将下载的包上传到服务器上
#将包放到/usr/local/目录
mv openjdk-11.0.2_linux-x64_bin.tar.gz /usr/local/

#进入/usr/local并解压删除压缩包
cd /usr/local/ && tar xf openjdk-11.0.2_linux-x64_bin.tar.gz && rm -rf openjdk-11.0.2_linux-x64_bin.tar.gz

3、配置

#添加环境变量(使用追加方式添加)
echo "export PATH=/usr/local/jdk-11.0.2/bin:$PATH" >> /etc/profile

#不放心可以查看一下环境变量
tail -1 /etc/profile

#生效环境变量
source /etc/profile

 三、卸载openjdk

  1. 查看openjdk命令: rpm -qa | grep jdk
  2. 卸载openjdk命令: rpm -e --nodeps **
[root@cn0013vm6012 ~]# rpm -qa | grep jdk
java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
copy-jdk-configs-3.3-10.el7_5.noarch
java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
[root@cn0013vm6012 ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
[root@cn0013vm6012 ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
[root@cn0013vm6012 ~]# rpm -qa | grep jdk
copy-jdk-configs-3.3-10.el7_5.noarch
[root@cn0013vm6012 ~]#

猜你喜欢

转载自blog.csdn.net/LIU_ZHAO_YANG/article/details/140172818