JDK部署
yum安装
yum是rpm的管理工具,管理一个软件库,可以很好的解决依赖关系
1) yum安装
yum install -y java
2) yum更新
yum update -y java
3) yum卸载
yum remove -y java
或
yum erase -y java
安装JDK
[root@promote ~]# yum install java
已加载插件:fastestmirror,langpacks
Loading mirror speeds from cached hostfile
*base: mirrors.hust.edu.cn
*extras: mirrors.skyshe.cn
*updates: mirrors.yun-idc.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 java-1.8.0-openjdk.x86_64.1.1.8.0.45-30.b13.el7_1将被安装
--> 解决依赖关系完成
依赖关系解决
================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
java-1.8.0-openjdk x86_64 1:1.8.0.45-30.b13.el7_1 updates 213 k
事务概要
================================================================================
安装 1 软件包
总下载量:213 k
安装大小:501 k
Is this ok [y/d/N]: y
Downloading packages:
java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64.rpm | 213 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 :1:java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64 1/1
验证中 : 1:java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64 1/1
已安装:
java-1.8.0-openjdk.x86_64 1:1.8.0.45-30.b13.el7_1
完毕!
[root@promote ~]#
查看安装目录
[root@promote ~]# whereis java
java: /usr/bin/java /usr/lib/java /etc/java/usr/share/java /usr/share/man/man1/java.1.gz
发现没有再找
[root@promote bin]# ls /usr/bin/java
/usr/bin/java
找到JVM的目录,这是自带JDK默认安装目录
[root@promote java]# ls /usr/lib/
alsa games jvm modules sysctl.d
binfmt.d gcc jvm-commmon modules-load.d systemd
cpp grub jvm-exports mozilla tmpfiles.d
crda java jvm-private polkit-1 tuned
cups java-1.5.0 kbd python2.7 udev
debug java-1.6.0 kdump rpm udisks2
dracut java-1.7.0 kernel sendmail x86_64-redhat-linux6E
firewalld java-1.8.0 locale sendmail.postfix yum-plugins
firmware java-ext modprobe.d sse2
再看里面
[root@promote jvm]# ls /jvm
java-1.7.0-openjdk-1.7.0.79-2.5.5.1.el7_1.x86_64
java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64这就是目录包
jre
jre-1.7.0
jre-1.7.0-openjdk
jre-1.7.0-openjdk-1.7.0.79-2.5.5.1.el7_1.x86_64
jre-1.8.0
jre-1.8.0-openjdk
jre-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64
jre-openjdk
找到了很长
[root@promote jre]# ls/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64/jre/
bin lib
下面开始编辑环境变量/etc/profile
[root@promote jre]# vim /etc/profile
添加如下
exportJAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64/jre/
exportJAVA_BIN=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64/jre/bin
exportJAVA_LIB=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64/jre/lib
export PATH=$PATH:$JAVA_BIN
exportCLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME PATH CLASSPATH
修改默认加载JDK版本
[root@promote ~]# sudo update-alternatives--install /usr/bin/java java/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64/bin/java 300
[root@promote ~]# sudo update-alternatives--install /usr/bin/java javac /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64/bin/javac300
[root@promote ~]#
或者
[root@promote ~]# sudo update-alternatives--config java
共有 3个提供“java”的程序。
选项 命令
-----------------------------------------------
*+ 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79-2.5.5.1.el7_1.x86_64/jre/bin/java
2 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64/jre/bin/java
3 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-30.b13.el7_1.x86_64/bin/java
按 Enter保留当前选项[+],或者键入选项编号:2
[root@promote ~]# java -version
openjdk version "1.8.0_45"
OpenJDK Runtime Environment (build1.8.0_45-b13)
OpenJDK 64-Bit Server VM (build 25.45-b02,mixed mode)
测试成功