CentOS7安装Jdk1.8

一、前期准备

a) 首先从官网上下载Jdk 8 for Linux x64到window下。

b) 我这边用的最小安装,所以没有安装centos自带的openjdk,如果你安装时,不是最小安装的话,可能集成了系统的openjdk,所以我们先要删除自带的openjdk,具体步骤如下:

1) 在系统终端输入:rpm -qa | grep java,如果有openjdk的话,会出现类似于XXXX_openjdk_XXX的信息。(可能有多条)

2) 删除openjdk,在终端输入:rpm -e –-nodeps XXXX_openjdk_XXX 。即可删除自带的openjdk。(如果有多条openjdk,依次执行命令删除)

rpm -e --nodeps `rpm -qa | grep java`
二、Jdk的安装

a) 我们登录超级用户,在超级用户目录usr下建立一个目录jdk:(路径可以自己选择)

su root 之后会提示输入密码。

mkdir jdk

b) 我们进入jdk,:

c) 解压jdk压缩包

tar –xzvf jdk-8u45-linux-x64.gz

d) 解压后的jdk的文件夹名字为jdk1.8.0_45,我们把它改为jdk1.8:

mv jdk1.8.0_45/ jdk1.8/

e) 进入jdk1.8文件夹,输入pwd 获取目录jdk1.8绝对路径

cd jdk1.8

pwd

三、jdk的配置

a) 使用vim命令打开系统的环境变量配置文件:

vi /etc/profile

b) 在profile文件最后加入:

## JAVA

export JAVA_HOME=jdk的绝对路径(我的是:/root/app/jdk1.8)

export PATH=$PATH:$JAVA_HOME/bin

c) 使profile生效

source /etc/profile

四、配置验证

a) 首先,我们输入java –version,会得到:

java version "1.8.0_45"

Java(TM) SE Runtime Environment (build 1.8.0_45-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

b) 我们再输入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.

-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process

-processorpath <path> Specify where to find annotation processors

-parameters Generate metadata for reflection on method parameters

-d <directory> Specify where to place generated class files

-s <directory> Specify where to place generated source files

-h <directory> Specify where to place generated native header files

-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files

-encoding <encoding> Specify character encoding used by source files

-source <release> Provide source compatibility with specified release

-target <release> Generate class files for specific VM version

-profile <profile> Check that API used is available in the specified profile

-Werror Terminate compilation if warnings occur

@<filename> Read options and filenames from file

c) 如果得到以上两步正确结果的话,恭喜你,你的jdk8就已经配置好了。

上一篇:第十三节 Ajax基础


下一篇:golang 字符串操作实例