CentOS下安装JDK的三种方法

由于各Linux开发厂商的不同,因此不同开发厂商的Linux版本操作细节也不一样,今天就来说一下CentOS下JDK的安装:

方法一:手动解压JDK的压缩包,然后设置环境变量

1.在/usr/目录下创建java目录

[root@localhost~]#mkdir/usr/java

[root@localhost~]#cd/usr/java

2.下载jdk,然后解压

[root@localhostjava]#curl-Ohttp://download.Oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz

[root@localhostjava]#tar-zxvfjdk-7u79-linux-x64.tar.gz

3.设置环境变量

[root@localhostjava]#vi/etc/profile

在profile中添加如下内容:

#setjavaenvironment

JAVA_HOME=/usr/java/jdk1.7.0_79

JRE_HOME=/usr/java/jdk1.7.0_79/jre

CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

exportJAVA_HOMEJRE_HOMECLASS_PATHPATH

让修改生效:

[root@localhostjava]#source/etc/profile

4.验证JDK有效性

[root@localhostjava]#java-version

javaversion"1.7.0_79"

Java(TM)SERuntimeEnvironment(build1.7.0_79-b15)

JavaHotSpot(TM)64-BitServerVM(build24.79-b02,mixedmode)

方法二:用yum安装JDK

1.查看yum库中都有哪些jdk版本(暂时只发现了openjdk)

[root@localhost~]#yumsearchjava|grepjdk

ldapjdk-javadoc.x86_64:Javadocforldapjdk

java-1.6.0-openjdk.x86_64:OpenJDKRuntimeEnvironment

java-1.6.0-openjdk-demo.x86_64:OpenJDKDemos

java-1.6.0-openjdk-devel.x86_64:OpenJDKDevelopmentEnvironment

java-1.6.0-openjdk-javadoc.x86_64:OpenJDKAPIDocumentation

java-1.6.0-openjdk-src.x86_64:OpenJDKSourceBundle

java-1.7.0-openjdk.x86_64:OpenJDKRuntimeEnvironment

java-1.7.0-openjdk-demo.x86_64:OpenJDKDemos

java-1.7.0-openjdk-devel.x86_64:OpenJDKDevelopmentEnvironment

java-1.7.0-openjdk-javadoc.noarch:OpenJDKAPIDocumentation

java-1.7.0-openjdk-src.x86_64:OpenJDKSourceBundle

java-1.8.0-openjdk.x86_64:OpenJDKRuntimeEnvironment

java-1.8.0-openjdk-demo.x86_64:OpenJDKDemos

java-1.8.0-openjdk-devel.x86_64:OpenJDKDevelopmentEnvironment

java-1.8.0-openjdk-headless.x86_64:OpenJDKRuntimeEnvironment

java-1.8.0-openjdk-javadoc.noarch:OpenJDKAPIDocumentation

java-1.8.0-openjdk-src.x86_64:OpenJDKSourceBundle

ldapjdk.x86_64:TheMozillaLDAPJavaSDK

2.选择版本,进行安装

//选择1.7版本进行安装

[root@localhost~]#yuminstalljava-1.7.0-openjdk

//安装完之后,默认的安装目录是在:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64

3.设置环境变量

[root@localhost~]#vi/etc/profile

在profile文件中添加如下内容

#setjavaenvironment

JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64

JRE_HOME=$JAVA_HOME/jre

CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

exportJAVA_HOMEJRE_HOMECLASS_PATHPATH

让修改生效

[root@localhostjava]#source/etc/profile

4.验证(同上一方法)

方法三:用rpm安装JDK

1.下载rpm安装文件

[root@localhost~]$curl-Ohttp://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm

2.使用rpm命令安装

[root@localhost~]#rpm-ivhjdk-7u79-linux-x64.rpm

3.设置环境变量

[root@localhostjava]#vi/etc/profile

在打开的profile文件中添加如下内容

#setjavaenvironment

JAVA_HOME=/usr/java/jdk1.7.0_79

JRE_HOME=/usr/java/jdk1.7.0_79/jre

CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

exportJAVA_HOMEJRE_HOMECLASS_PATHPATH

让修改生效

[root@localhostjava]#source/etc/profile

4.验证(同上一方法)

注:和yum安装类似,不用设置环境变量就可以运行java命令。rpm安装方式默认会把jdk安装到/usr/java/jdk1.7.0_79,然后通过三层链接,链接到/usr/bin,具体链接如下:

[root@localhost~]#cd/bin

[root@localhostbin]#ll|grepjava

lrwxrwxrwx.1rootroot25Mar2811:24jar->/usr/java/default/bin/jar

lrwxrwxrwx.1rootroot26Mar2811:24java->/usr/java/default/bin/java

lrwxrwxrwx.1rootroot27Mar2811:24javac->/usr/java/default/bin/javac

lrwxrwxrwx.1rootroot29Mar2811:24javadoc->/usr/java/default/bin/javadoc

lrwxrwxrwx.1rootroot28Mar2811:24javaws->/usr/java/default/bin/javaws

lrwxrwxrwx.1rootroot30Mar2811:24jcontrol->/usr/java/default/bin/jcontrol

[root@localhostbin]#cd/usr/java/

[root@localhostjava]#ll

total4

lrwxrwxrwx.1rootroot16Mar2811:24default->/usr/java/latest

drwxr-xr-x.8rootroot4096Mar2811:24jdk1.7.0_79

lrwxrwxrwx.1rootroot21Mar2811:24latest->/usr/java/jdk1.7.0_79

方法四:Ubuntu上使用apt-get安装JDK

1.查看apt库都有哪些jdk版本

root@linuxidc:~#apt-cachesearchjava|grepjdk

default-jdk-StandardJavaorJavacompatibleDevelopmentKit

default-jdk-doc-StandardJavaorJavacompatibleDevelopmentKit(documentation)

gcj-4.6-jdk-gcjandclasspathdevelopmenttoolsforJava(TM)

gcj-jdk-gcjandclasspathdevelopmenttoolsforJava(TM)

openjdk-6-dbg-JavaruntimebasedonOpenJDK(debuggingsymbols)

openjdk-6-demo-JavaruntimebasedonOpenJDK(demosandexamples)

openjdk-6-doc-OpenJDKDevelopmentKit(JDK)documentation

openjdk-6-jdk-OpenJDKDevelopmentKit(JDK)

openjdk-6-jre-lib-OpenJDKJavaruntime(architectureindependentlibraries)

openjdk-6-source-OpenJDKDevelopmentKit(JDK)sourcefiles

openjdk-7-dbg-JavaruntimebasedonOpenJDK(debuggingsymbols)

openjdk-7-demo-JavaruntimebasedonOpenJDK(demosandexamples)

openjdk-7-doc-OpenJDKDevelopmentKit(JDK)documentation

openjdk-7-jdk-OpenJDKDevelopmentKit(JDK)

openjdk-7-source-OpenJDKDevelopmentKit(JDK)sourcefiles

uwsgi-plugin-jvm-openjdk-6-JavapluginforuWSGI(OpenJDK6)

uwsgi-plugin-jwsgi-openjdk-6-JWSGIpluginforuWSGI(OpenJDK6)

openjdk-6-jre-OpenJDKJavaruntime,usingHotspotJIT

openjdk-6-jre-headless-OpenJDKJavaruntime,usingHotspotJIT(headless)

openjdk-7-jre-OpenJDKJavaruntime,usingHotspotJIT

openjdk-7-jre-headless-OpenJDKJavaruntime,usingHotspotJIT(headless)

openjdk-7-jre-lib-OpenJDKJavaruntime(architectureindependentlibraries)

2.选择版本进行安装

root@linuxidc:~#apt-getinstallopenjdk-7-jdk

3.设置环境变量

root@linuxidc:~#vi/etc/profile

在打开的profile文件中添加如下内容

#setjavaenvironment

JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64

JRE_HOME=$JAVA_HOME/jre

CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

exportJAVA_HOMEJRE_HOMECLASS_PATHPATH

让修改生效

root@linuxidc:~#source/etc/profile

4.验证(同上一方法)

Ubuntu14.04安装JDK1.8.0_25与配置环境变量http://www.linuxidc.com/Linux/2015-01/112030.htm

CentOS搭建JDK环境http://www.linuxidc.com/Linux/2015-06/118879.htm

Ubuntu14.04安装JDK1.8.0_25与配置环境变量http://www.linuxidc.com/Linux/2015-01/112030.htm

Ubuntu14.04LTS安装OracleJDK1.8http://www.linuxidc.com/Linux/2014-11/109216.htm

CentOS6.3安装JDK和环境配置http://www.linuxidc.com/Linux/2012-09/70780.htm

Ubuntu14.04安装JDK8http://www.linuxidc.com/Linux/2014-09/106218.htm

Ubuntu下安装JDK图文解析http://www.linuxidc.com/Linux/2014-09/107291.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-09/134941.htm

linux