检查系统中的jdk版本
[root@localhost ~]# java -version
显示
[root@localhost ~]# java -version
-bash: java: command not found
我们需要到jdk官网上下载你想要的jdk版本:https://www.oracle.com/technetwork/java/javase/downloads/index.html
下载完成之后将需要安装的jdk安装包放到Linux系统指定的文件夹下,并且命令进入该文件夹下:
[root@localhost software]# ll
-rwxrw-rw-. 1 root root 185540433 Apr 21 09:06 jdk-8u131-linux-x64.tar.gz
创建jdk的目录并且解压jdk的tar包
[root@localhost software]# mkdir -p /usr/lib/jvm
[root@localhost software]# tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/lib/jvm
解压完成之后设置linxu的环境变量,编辑profire文件。
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
-bash: vim: command not found
[root@localhost ~]#
出现这个错误就是现实我们的vim没有安装,输入rpm -qa|grep vim 命令, 如果 vim 已经正确安裝,会返回下面的三行代码:
[root@localhost ~]# rpm -qa|grep vim
vim-enhanced-7.0.109-7.el5
vim-minimal-7.0.109-7.el5
vim-common-7.0.109-7.el5
如果少了其中的某一条,比如 vim-enhanced 的,就用命令 yum -y install vim-enhanced 来安裝:
[root@localhost ~]# yum -y install vim-enhanced
如果上面的三条一条都沒有返回, 可以直接用 yum -y install vim* 命令
[root@localhost ~]# yum -y install vim*
安装完成之后,在编辑profile文件
[root@localhost jvm]# vim /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`id -u`
UID=`id -ru`
fi
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# 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
在最后面export这里添加java的环境变量,这里注意的是进入到编辑页面的时候,开始执行编辑只需要按一下i键就可以了,保存编辑成果是按下Esc键之后再输入:wq,保存更改,(:q!是不保存更改)!
【温馨提示】如果在这里不想在黑窗口中修改profile文件,您也可以把 /etc下的profile文件拖到本地来在自己本地进行修改在放入linxu环境中,这样可以保证您改的时候不会出现错误也可以及时的发现错误。(本地修改只需要把上下两端代码复制进去即可)
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_131
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
# 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
修改完成之后执行profile文件可立即生效。
[root@localhost jvm]# source /etc/profile
检查新安装的jdk显示:
[root@localhost ~]# java -version
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
[root@localhost ~]#
本次分享安装jdk到此结束。
原文作者技术博客:https://www.jianshu.com/u/ac4daaeecdfe
95后前端妹子一枚,爱阅读,爱交友,将工作中遇到的问题记录在这里,希望给每一个看到的你能带来一点帮助。
欢迎留言交流。
网友评论