linux 下安装jdk

卸载已安装的open jdk[1][2]

  • 查看系统已安装的jdk:rpm -qa|grep jdk
copy-jdk-configs-1.2-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64
java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
  • 查询java相关的信息:rpm -qa|grep java
javapackages-tools-3.4.1-11.el7.noarch
python-javapackages-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64
java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
tzdata-java-2017b-1.el7.noarch
javamail-1.4.6-8.el7.noarch
  • 卸载:
rpm -e --nodeps copy-jdk-configs-1.2-1.el7.noarch
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
如果卸载对应后继续运行卸载该命令,会出现以下提示:
error: package java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64 is not installed

安装JDK[1]

  • 在JDK下载页面找到对应的包,然后进行下载:
    centos:
    wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm"

ubuntu:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz?AuthParam=1504071462_ada46b0cca620eea37f1524f3d72847f"
  • 安装:
    centos: rpm -ivh jdk-8u144-linux-x64.rpm
    ubuntu: tar zxf jdk-8u144-linux-x64.tar.gz
  • 校验: java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
  • 设置JAVA_HOME
    1. vim ~/.bashrc,打开该文件
    2. 然后在vim模式下输入a
    3. 定位到文件最后位置,粘贴以下内容
export JAVA_HOME=/usr/java/jdk1.8.0_131
export PATH=$PATH:$JAVA_HOME
  1. 按下esc
  2. 输入冒号:,然后输入wq保存修改并且推出即可

或者:

echo 'export JAVA_HOME="/opt/jdk1.8.0_144"
export PATH="$JAVA_HOME/bin:$JAVA_HOME/jre:$PATH"' >> ~/.bashrc

你可能感兴趣的:(linux 下安装jdk)