发布网友 发布时间:2022-03-20 10:16
共2个回答
懂视网 时间:2022-03-20 14:37
如何在centos系统上如何安装java JDK环境?
产品型号:Thinkpad E15
系统版本:centos7
软件版本:jdk 1.8
Java JDK是Java Development Kit的缩写,也就是开发工具包,里面内含平时用户用到的JRE,也就是Java Runtime Enviroment运行环境。所以装了JDK,JRE自然也被装上了。
使用Yum安装JDK或者手动安装
yum install java-1.8.0-openjdk -y
查看安装的java版本号:
[root@xuegod63 ~]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK -Bit Server VM (build 25.262-b10, mixed mode)
总结:
使用Yum安装JDK或者手动安装
yum install java-1.8.0-openjdk -y
热心网友 时间:2022-03-20 11:45
方法一:手动解压JDK的压缩包,然后设置环境变量
1.在/usr/目录下创建java目录
[root@localhost ~]# mkdir/usr/java
[root@localhost ~]# cd /usr/java
2.下载jdk,然后解压
[root@localhost java]# curl -O http://download.Oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x.tar.gz (自行上 oracle.com 官网查看x86 for linux 32位连接)
[root@localhost java]# tar -zxvf jdk-7u79-linux-x.tar.gz
3.设置环境变量
[root@localhost 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
让修改生效:
[root@localhost java]# source /etc/profile
4.验证JDK有效性
[root@localhost java]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) -Bit Server VM (build 24.79-b02, mixed mode)
方法二:用yum安装JDK
1.查看yum库中都有哪些jdk版本(暂时只发现了openjdk)
[root@localhost ~]# yum search java|grep jdk
ldapjdk-javadoc.x86_ : Javadoc for ldapjdk
java-1.6.0-openjdk.x86_ : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_ : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_ : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_ : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_ : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_ : OpenJDK Runtime Environment
java-1.7.0-openjdk-demo.x86_ : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_ : OpenJDK Development Environment
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_ : OpenJDK Source Bundle
java-1.8.0-openjdk.x86_ : OpenJDK Runtime Environment
java-1.8.0-openjdk-demo.x86_ : OpenJDK Demos
java-1.8.0-openjdk-devel.x86_ : OpenJDK Development Environment
java-1.8.0-openjdk-headless.x86_ : OpenJDK Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-src.x86_ : OpenJDK Source Bundle
ldapjdk.x86_ : The Mozilla LDAP Java SDK
2.选择版本,进行安装
//选择1.7版本进行安装
[root@localhost ~]# yum install java-1.7.0-openjdk
//安装完之后,默认的安装目录是在: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_
3.设置环境变量
[root@localhost ~]# vi /etc/profile
在profile文件中添加如下内容
#set java environment
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_
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
让修改生效
[root@localhost java]# source /etc/profile
4.验证(同上一方法)
方法三:用rpm安装JDK
1.下载rpm安装文件
[root@localhost ~]$ curl -O http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x.rpm
2.使用rpm命令安装
[root@localhost ~]# rpm -ivh jdk-7u79-linux-x.rpm
3.设置环境变量
[root@localhost 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
让修改生效
[root@localhost java]# source /etc/profile
4.验证(同上一方法)
注:和yum安装类似,不用设置环境变量就可以运行java命令。rpm安装方式默认会把jdk安装到/usr/java/jdk1.7.0_79,然后通过三层链接,链接到/usr/bin,具体链接如下:
[root@localhost ~]# cd /bin
[root@localhost 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
[root@localhost bin]# cd /usr/java/
[root@localhost 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