2021-05-12 14:32:11
CentOS 7.5下Java環境的安裝設定
1、檢視系統中的java環境
[root@localhost ~]# java -version
openjdk version "1.8.0_101"
OpenJDK Runtime Environment (build 1.8.0_101-b13)
OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)
進一步檢視JDK資訊:
[root@localhost ~]# rpm -qa | grep java
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.101-3.b13.el7_2.x86_64
Python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2016f-1.el7.noarch
java-1.8.0-openjdk-1.8.0.101-3.b13.el7_2.x86_64
解除安裝 OpenJDK:rpm -e --nodeps
[root@localhost ~]# rpm -e --nodeps javapackages-tools-3.4.1-11.el7.noarch
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.101-3.b13.el7_2.x86_64
[root@localhost ~]# rpm -e --nodeps python-javapackages-3.4.1-11.el7.noarch
[root@localhost ~]# rpm -e --nodeps tzdata-java-2016f-1.el7.noarch
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.101-3.b13.el7_2.x86_64
2、安裝jdk
下載jdk的rpm安裝包上傳到/usr/local/java
下載地址:http://www.Oracle.com/technetwork/java/javase/downloads/index.html
cd /usr/local/java 進入jdk所在的資料夾執行安裝命令:
[root@localhost java]# rpm -ivh jdk-8u91-linux-x64.rpm
準備中... ################################# [100%]
正在升級/安裝...
1:jdk1.8.0_91-2000:1.8.0_91-fcs ################################# [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
jfxrt.jar...
不報錯就安裝成功
驗證:
[root@localhost java]# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
3、環境變數設定
修改系統環境變數檔案
vi + /etc/profile
[root@localhost java]# vi + /etc/profile
fi
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
JAVA_HOME=/usr/java/jdk1.8.0_91
JRE_HOME=/usr/java/jdk1.8.0_91/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
"/etc/profile" 82L, 1972C
紅色字型的為新增的設定,通常java安裝在/usr/java/目錄下
使修改生效
[root@localhost ~]# source /etc/profile //使修改立即生效
驗證設定:
[root@localhost java]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.8.0_91/bin:/usr/java/jdk1.8.0_91/jre/bin
這樣就完成的對整個java環境的設定
本文永久更新連結地址:http://www.linuxidc.com/Linux/2016-09/134967.htm
相關文章