操作系统

当前位置:金沙棋牌 > 操作系统 > CentOS下安装JDK的三种方法,使用yum命令安装Java

CentOS下安装JDK的三种方法,使用yum命令安装Java

来源:http://www.logblo.com 作者:金沙棋牌 时间:2019-08-29 16:04

6、测试java是否安装配置成功

查看 java 版本,输入命令:
[[email protected]~]# java -version

7、创建一个java小程序测试下,名字叫HelloWorld.java,输入以下命令:
[[email protected] ~]# touch HelloWorld.java

将以下代码复制到 HelloWorld.java 中 :
public class HelloWorld {
pu
blic static void main(String[] args) {
System.out.println("Hello, World! This is a test code by nixCraft!");
}
}

复制进去后,保存关闭文件。编译和运行这个小程序,输入以下命令:
[[email protected] ~]# javac HelloWorld.java
[[email protected] ~]# java HelloWorld

会得到以下显示:
Hello, World! This is a test code by nixCraft!

export JAVA_HOME JRE_HOME CLASS_PATH PATH

CentOS下安装JDK的三种方法,centosjdk三种方法

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

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

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

[[email protected] ~]# mkdir/usr/java
[[email protected] ~]# cd /usr/java

2.下载jdk,然后解压

[[email protected] java]#金沙棋牌, curl -O  
[[email protected] java]# tar -zxvf jdk-7u79-linux-x64.tar.gz

3.设置环境变量

[[email protected] java]# vi /etc/profile

在profile中添加如下内容:

#set java environment
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
export JAVA_HOME JRE_HOME CLASS_PATH PATH

让修改生效:

[[email protected] java]# source /etc/profile

4.验证JDK有效性

[[email protected] java]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

方法二:用yum安装JDK

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

[[email protected] ~]# yum search java|grep jdk
ldapjdk-javadoc.x86_64 : Javadoc for ldapjdk
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle
ldapjdk.x86_64 : The Mozilla LDAP Java SDK

2.选择版本,进行安装

//选择1.7版本进行安装
[[email protected] ~]# yum install java-1.7.0-openjdk
//安装完之后,默认的安装目录是在: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64

3.设置环境变量

[[email protected] ~]# vi /etc/profile

在profile文件中添加如下内容

#set java environment
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
export JAVA_HOME JRE_HOME CLASS_PATH PATH

让修改生效

[[email protected] java]# source /etc/profile

4.验证(同上一方法)

方法三:用rpm安装JDK

1.下载rpm安装文件

[[email protected] ~]$ curl -O

2.使用rpm命令安装

[[email protected]  ~]# rpm -ivh jdk-7u79-linux-x64.rpm

3.设置环境变量

[[email protected] java]# vi /etc/profile

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

#set java environment
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
export JAVA_HOME JRE_HOME CLASS_PATH PATH

让修改生效

[[email protected] java]# source /etc/profile

4.验证(同上一方法)

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

[[email protected] ~]# cd /bin
[[email protected] bin]# ll|grep java
lrwxrwxrwx. 1 root root    25 Mar 28 11:24 jar ->/usr/java/default/bin/jar
lrwxrwxrwx. 1 root root    26 Mar 28 11:24 java -> /usr/java/default/bin/java
lrwxrwxrwx. 1 root root    27 Mar 28 11:24 javac ->/usr/java/default/bin/javac
lrwxrwxrwx. 1 root root    29 Mar 28 11:24 javadoc ->/usr/java/default/bin/javadoc
lrwxrwxrwx. 1 root root    28 Mar 28 11:24 javaws ->/usr/java/default/bin/javaws
lrwxrwxrwx. 1 root root    30 Mar 28 11:24 jcontrol ->/usr/java/default/bin/jcontrol
[[email protected] bin]# cd /usr/java/
[[email protected] java]# ll
total 4
lrwxrwxrwx. 1 root root  16 Mar 28 11:24 default-> /usr/java/latest
drwxr-xr-x. 8 root root 4096 Mar 28 11:24 jdk1.7.0_79
lrwxrwxrwx. 1 root root  21 Mar 28 11:24 latest -> /usr/java/jdk1.7.0_79

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

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

[email protected]:~# apt-cache search java|grep jdk
default-jdk - Standard Java or Java compatible Development Kit
default-jdk-doc - Standard Java or Java compatible Development Kit (documentation)
gcj-4.6-jdk - gcj and classpath development tools for Java(TM)
gcj-jdk - gcj and classpath development tools for Java(TM)
openjdk-6-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-6-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-6-doc - OpenJDK Development Kit (JDK) documentation
openjdk-6-jdk - OpenJDK Development Kit (JDK)
openjdk-6-jre-lib - OpenJDK Java runtime (architecture independent libraries)
openjdk-6-source - OpenJDK Development Kit (JDK) source files
openjdk-7-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-7-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-7-doc - OpenJDK Development Kit (JDK) documentation
openjdk-7-jdk - OpenJDK Development Kit (JDK)
openjdk-7-source - OpenJDK Development Kit (JDK) source files
uwsgi-plugin-jvm-openjdk-6 - Java plugin for uWSGI (OpenJDK 6)
uwsgi-plugin-jwsgi-openjdk-6 - JWSGI plugin for uWSGI (OpenJDK 6)
openjdk-6-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-6-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-7-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-7-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-7-jre-lib - OpenJDK Java runtime (architecture independent libraries)

2.选择版本进行安装

[email protected]:~# apt-get install openjdk-7-jdk

3.设置环境变量

[email protected]:~# vi /etc/profile

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

#set java environment
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
export JAVA_HOME JRE_HOME CLASS_PATH PATH

让修改生效

[email protected]:~# source /etc/profile

4.验证(同上一方法)

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

三种CentOS下安装JDK的方法

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

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

[[email protected] ~]# mkdir/usr/java
[[email protected] ~]# cd /usr/java

2.下载jdk,然后解压

[[email protected] java]# curl -O
[[email protected] java]# tar -zxvf jdk-7u79-linux-x64.tar.gz

3.设置环境变量

[[email protected] java]# vi /etc/profile

在profile中添加如下内容:

#set java environment
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
export JAVA_HOME JRE_HOME CLASS_PATH PATH

让修改生效:

[[email protected] java]# source /etc/profile

4.验证JDK有效性

[[email protected] java]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

方法二:用yum安装JDK

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

[[email protected] ~]# yum search java|grep jdk
ldapjdk-javadoc.x86_64 : Javadoc for ldapjdk
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle
ldapjdk.x86_64 : The Mozilla LDAP Java SDK

2.选择版本,进行安装

//选择1.7版本进行安装
[[email protected] ~]# yum install java-1.7.0-openjdk
//安装完之后,默认的安装目录是在: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64

3.设置环境变量

[[email protected] ~]# vi /etc/profile

在profile文件中添加如下内容

#set java environment
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
export JAVA_HOME JRE_HOME CLASS_PATH PATH

让修改生效

[[email protected] java]# source /etc/profile

4.验证(同上一方法)

方法三:用rpm安装JDK

1.下载rpm安装文件

[[email protected] ~]$ curl -O

2.使用rpm命令安装

[[email protected] ~]# rpm -ivh jdk-7u79-linux-x64.rpm

3.设置环境变量

[[email protected] java]# vi /etc/profile

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

#set java environment
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
export JAVA_HOME JRE_HOME CLASS_PATH PATH

让修改生效

[[email protected] java]# source /etc/profile

4.验证(同上一方法)

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

[[email protected] ~]# cd /bin
[[email protected] bin]# ll|grep java
lrwxrwxrwx. 1 root root 25 Mar 28 11:24 jar ->/usr/java/default/bin/jar
lrwxrwxrwx. 1 root root 26 Mar 28 11:24 java -> /usr/java/default/bin/java
lrwxrwxrwx. 1 root root 27 Mar 28 11:24 javac ->/usr/java/default/bin/javac
lrwxrwxrwx. 1 root root 29 Mar 28 11:24 javadoc ->/usr/java/default/bin/javadoc
lrwxrwxrwx. 1 root root 28 Mar 28 11:24 javaws ->/usr/java/default/bin/javaws
lrwxrwxrwx. 1 root root 30 Mar 28 11:24 jcontrol ->/usr/java/default/bin/jcontrol
[[email protected] bin]# cd /usr/java/
[[email protected] java]# ll
total 4
lrwxrwxrwx. 1 root root 16 Mar 28 11:24 default-> /usr/java/latest
drwxr-xr-x. 8 root root 4096 Mar 28 11:24 jdk1.7.0_79
lrwxrwxrwx. 1 root root 21 Mar 28 11:24 latest -> /usr/java/jdk1.7.0_79

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

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

[email protected]:~# apt-cache search java|grep jdk
default-jdk - Standard Java or Java compatible Development Kit
default-jdk-doc - Standard Java or Java compatible Development Kit (documentation)
gcj-4.6-jdk - gcj and classpath development tools for Java(TM)
gcj-jdk - gcj and classpath development tools for Java(TM)
openjdk-6-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-6-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-6-doc - OpenJDK Development Kit (JDK) documentation
openjdk-6-jdk - OpenJDK Development Kit (JDK)
openjdk-6-jre-lib - OpenJDK Java runtime (architecture independent libraries)
openjdk-6-source - OpenJDK Development Kit (JDK) source files
openjdk-7-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-7-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-7-doc - OpenJDK Development Kit (JDK) documentation
openjdk-7-jdk - OpenJDK Development Kit (JDK)
openjdk-7-source - OpenJDK Development Kit (JDK) source files
uwsgi-plugin-jvm-openjdk-6 - Java plugin for uWSGI (OpenJDK 6)
uwsgi-plugin-jwsgi-openjdk-6 - JWSGI plugin for uWSGI (OpenJDK 6)
openjdk-6-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-6-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-7-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-7-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-7-jre-lib - OpenJDK Java runtime (architecture independent libraries)

2.选择版本进行安装

[email protected]:~# apt-get install openjdk-7-jdk

3.设置环境变量

[email protected]:~# vi /etc/profile

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

#set java environment
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
export JAVA_HOME JRE_HOME CLASS_PATH PATH

让修改生效

[email protected]:~# source /etc/profile

4.验证(同上一方法)

方法一:手动解压JDK的压缩包,然后设置环境变量 1.在/usr/目录下创建java目录 [[email protected] ~]# mkdir/usr/java [[email protected]

8、如何(怎样)运行 .jar 这类java应用?

语法如下:
[[email protected]~]# java -jar file.jar
[[email protected]~]# java -jar /path/to/my/java/app.jar #/path/to/my/java/app.jar表示应用的路径
[[email protected] ~]# java -jar /path/to/my/java/app.jar arg1 arg2 # arg1表示参数1 ,arg2表示参数2

使用yum命令安装Java SDK CentOS 6.X 和 7.X 自带有OpenJDK runtime environment (openjdk)。它是一个在linux上实现开源的Java平台。 安装方式: 1、输入...

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

CentOS7 使用yum命令安装Java SDK

CentOS 6.X 和 7.X 自带有OpenJDK runtime environment (openjdk)。它是一个在linux上实现开源的Java平台。

安装方式:

1、输入以下命令,以查看可用的JDK软件包列表;

yum search java | grep -i --color JDK

2、在CentOS linux安装 JAVA SDK
在命令行终端以root用户 输入以下命令yum安装 OpenSDK :

yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel #安装openjdk

待以上命令执行完成,则表示jdk安装成功。

3、在centos linux上设置JAVA_HOME environment variable(JAVA_HOME环境变量)

rhel 和 centos linux 使用yum命令后,将 OpenSDK 安装到/usr/lib/jvm/目录:

4、用cd 命令进入到jvm下唯一的一个目录中java-1.8.0-openjdk-1.8.0.51.x86_64 ,而jre-1.8.0-openjdk.x86_64 这个链接是指向 java-1.8.0-openjdk-1.8.0.51.x86_64 这个文件夹,所以,可以直接用export命令将 JAVA_HOME 指向 jre-1.8.0-openjdk.x86_64 这个链接。
即使用export命令:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51.x86_64

但是这样只能在当前会话中有效,一旦注销下线,就失效了。

5、标准方式配置环境变量

进行下面的操作:

vi /etc/profile

将下面的三行粘贴到 /etc/profile 中:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

保存关闭,后,执行:source /etc/profile #让设置立即生效。

在输入以下命令,来确认这三个变量是否设成了我们想要的:

[[email protected]~]# echo $JAVA_HOME
[[email protected] ~]# echo $CLASSPATH
[[email protected] ~]# echo $PATH

#set java environment

安装1.8yum install java-1.8.0-openjdk  java-1.8.0-openjdk-devel  #安装openjdk

3.设置环境变量

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

yum search java | grep -i --color JDK

安装1.7  yum install java-1.7.0-openjdk-devel

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

JRE_HOME=$JAVA_HOME/jre

yum search java|grep jdk

2、在CentOS linux安装 JAVA SDK

输入以下命令,以查看可用的JDK软件包列表;

让修改生效

在命令行终端以root用户 输入以下命令yum安装 OpenSDK :

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

在profile文件中添加如下内容

[root@localhost java]# source /etc/profile

本文由金沙棋牌发布于操作系统,转载请注明出处:CentOS下安装JDK的三种方法,使用yum命令安装Java

关键词:

上一篇:LVM基本概念,逻辑卷管理

下一篇:没有了