1.编译安装jdk
[root@localhost src]# mkdir /usr/java #创建存放目录
[root@localhost src]# tar -zxvf jdk-8u131-linux-x64.tar.gz #解压下载好的jdk
[root@localhost src]# mv jdk1.8.0_131/ /usr/java #移动到创建的目录
2.配置jdk环境
  • 全局用户添加JDK环境变量

以root用户,编辑系统全局环境配置文件/etc/profile

[root@localhost src]# vim /etc/profile   
/etc/profile文件尾部添加:
export JAVA_HOME=/usr/java/jdk1.8.0_131  #jdk安装路径
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH.
  • 给用户配置JDK环境变量以tomcat用户(应用系统用户),编辑用户环境配置文件$HOME/.bash_profile
[tomcat@localhost ~]$ vim .bash_profile
#修改为下面的内容
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
JAVA_HOME=/usr/java/jdk1.8.0_131        #jdk安装路径
export JAVA_HOME
CLASSPATH=.:$JAVA_HOME/jre/lib/dt.jar:$JAVA_HOME/jre/lib/tools.jar
export CLASSPATH
PATH=$PATH:$HOME/bin:$JAVA_HOME/jre/bin
export PATH
export LANG=zh_CN.UTF-8

[tomcat@localhost ~]$ source /etc/profile
[tomcat@localhost ~]$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

本文原创地址:https://www.linuxprobe.com/centos6-install-tomcat.html编辑:yangbinbin,审核员:逄增宝