CentOS7安装jdk1.8

目录

一、CentOS7一般会自带Open JDK,先卸载它

二、安装jdk1.8


 

一、CentOS7一般会自带Open JDK,先卸载它

  • 卸载系统自带的OpenJDK以及相关的java文件
  • 在命令行窗口输入:java -version
[root@localhost yum.repos.d]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)

 

可以看到系统自带的OpenJDK版本信息,在命令窗口键入: rpm -qa | grep java

命令说明:
rpm   管理套件
-qa   使用询问模式,查询所有套件
grep  查找文件里符合条件的字符串
java   查找包含java字符串的文件

 

[dr@localhost ~]$ rpm -qa | grep java
tzdata-java-2017b-1.el7.noarch
java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64
java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64

以上文件中,下面这几个可以删除

java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64
java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64

 在root用户下,在命令窗口输入

rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64

命令介绍:
rpm     管理套件
-e     删除指定的套件
–nodeps  不验证套件档的相互关联性

检查是否已经删除成功在命令窗口键入:java -version

[root@localhost dr]# java -version
bash: java: command not found...

到这里CentOS自带的Open JDK已经完全删除了!!!


二、安装jdk1.8

一、本地文件安装

首先去 官网把 jdk1.8 下载 到本地,保存到自己习惯的地方

首先创建java存放目录,这里我在 /usr/local/ 目录下创建了一个 java文件夹

[root@localhost Datafile]# sudo mkdir /usr/local/java

把下载的文件先解压,解压文件会在当前目录下

[root@localhost Datafile]# tar -zxvf jdk-8u171-linux-x64.tar.gz
jdk1.8.0_171/
jdk1.8.0_171/javafx-src.zip
jdk1.8.0_171/bin/
jdk1.8.0_171/bin/jmc
jdk1.8.0_171/bin/serialver
jdk1.8.0_171/bin/jmc.ini
jdk1.8.0_171/bin/jstack
jdk1.8.0_171/bin/rmiregistry
jdk1.8.0_171/bin/unpack200
...

查看解压文件 

[root@localhost Datafile]# ll
total 186420
drwxr-xr-x. 8 10 143       255 Mar 28  2018 jdk1.8.0_171
-rw-rw-r--. 1 dr dr  190890122 Mar 28 04:41 jdk-8u171-linux-x64.tar.gz

 将解压后的文件,启动到新建的目录下

[root@localhost Datafile]# mv jdk1.8.0_171/ /usr/local/java/

# 然后配置环境变量

vi /etc/profile

# 按 i 进入编辑模式,去文件最后加上下面两行, path 是存放jdk的路径 /usr/local/java/jdk1.8.0_171

export JAVA_HOME=/path
export PATH=$PATH:$JAVA_HOME/bin 


# 先按Esc键  再按 :wq! 退出保存

最后让配置文件生效

source /etc/profile

测试是否安装成功

[root@localhost Datafile]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

[root@localhost Datafile]# java
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -server       to select the "server" VM
                  The default VM is server,
                  because you are running on a server-class machine.


    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
...

[root@localhost Datafile]# javac
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files and annotation processors
  -cp <path>                 Specify where to find user class files and annotation processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
...


 

 

上一篇:Centos7下载linux内核源码


下一篇:docker教程000:Centos7下安装Docker