本文主要说明了在centos7系统下安装JDK8的详细步骤
- 1.1 下载jdk8
下载jdk8 -
1.2 把下载好的jdk8包传输到centos7服务器
- 1.3 解压
tar -xvf jdk-8u241-linux-i586.tar.gz
用ll
命令查看解压后的文件
[root@iZipqoqa9axzz1Z java]# ll
total 190576
drwxr-xr-x 7 10143 10143 4096 Dec 11 18:52 jdk1.8.0_241
-rw-r--r-- 1 root root 195143852 Mar 30 16:56 jdk-8u241-linux-i586.tar.gz
[root@iZipqoqa9axzz1Z java]#
删除安装包rm -rf jdk-8u241-linux-i586.tar.gz
(删除时输入 jdk-后,再按Tab键自动补全jdk安装包名字)
删除后查看目录:
[root@iZipqoqa9axzz1Z java]# ll
total 4
drwxr-xr-x 7 10143 10143 4096 Dec 11 18:52 jdk1.8.0_241
- 1.4 用vim编辑器设置jdk8的环境变量
vim /etc/profile
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
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
# 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 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
- 1,5 输入 i 键,切换到编辑模式(注:在最下方出现 --INSERT-- 才表示进入到编辑模式)
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
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
# 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 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
-- INSERT -- 78,1 Bot
移动光标在最下方填上:
JAVA_HOME=/fcj/java/jdk1.8.0_241
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
- 1.6 输入
Esc
退出vim编辑模式,再按:wq+回车
(保存并退出) - 1.7 输入
source /etc/profile
使环境变量文件立即生效 - 1.8 用 java -version 命令查看JDK是否安装成功
[root@iZipqoqa9axzz1Z java]# java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) Server VM (build 25.241-b07, mixed mode)
[root@iZipqoqa9axzz1Z java]#