安装JDK
rpm安装
[root@centos8 ~]#ls -lh jdk-8u241-linux-x64.rpm -rw-r--r-- 1 root root 171M Feb 8 18:29 jdk-8u241-linux-x64.rpm
#安装jdk,无相关依赖包 [root@centos8 ~]#dnf -y install jdk-8u241-linux-x64.rpm [root@centos8 ~]#java -version java version "1.8.0_241" Java(TM) SE Runtime Environment (build 1.8.0_241-b07) Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode) #初始化环境变量 [root@centos8 ~]#vim /etc/profile.d/jdk.sh [root@centos8 ~]#cat /etc/profile.d/jdk.sh export JAVA_HOME=/usr/java/default export PATH=$JAVA_HOME/bin:$PATH #以下两项非必须项
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib/:$JRE_HOME/lib/
[root@centos8 ~]#. /etc/profile.d/jdk.sh #运行
二进制文件安装 [root@centos8 ~]#tar xvf jdk-8u241-linux-x64.tar.gz -C /usr/local/ [root@centos8 ~]#cd /usr/local/ [root@centos8 ~]#ln -s jdk1.8.0_241/ jdk #初始化环境变量 [root@centos8 ~]#vim /etc/profile.d/jdk.sh [root@centos8 ~]#cat /etc/profile.d/jdk.sh export JAVA_HOME=/usr/local/jdk export PATH=$PATH:$JAVA_HOME/bin #以下两项非必须项 #export JRE_HOME=$JAVA_HOME/jre #export CLASSPATH=.:$JAVA_HOME/lib/:$JRE_HOME/lib/ [root@centos8 ~]#. /etc/profile.d/jdk.sh #注意:JAVA_HOME变量必须设置,否则tomcat启动时会出下面错误 [root@centos8 ~]#catalina.sh Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program [root@centos8 ~]#startup.sh Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program #验证安装 [root@centos8 ~]#java -version java version "1.8.0_241" Java(TM) SE Runtime Environment (build 1.8.0_241-b07) Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode) [root@centos8 ~]#which java /usr/local/jdk/bin/java
一键安装二进制的JDK [root@ubuntu1804 ~]#vim install_jdk.sh JDK_FILE="jdk-11.0.15.1_linux-x64_bin.tar.gz" #JDK_FILE="jdk-11.0.12_linux-x64_bin.tar.gz" #JDK_FILE="jdk-8u301-linux-x64.tar.gz"
JDK_DIR="/usr/local" DIR=`pwd` color () { RES_COL=60 MOVE_TO_COL="echo -en \\033[${RES_COL}G" SETCOLOR_SUCCESS="echo -en \\033[1;32m" SETCOLOR_FAILURE="echo -en \\033[1;31m" SETCOLOR_WARNING="echo -en \\033[1;33m" SETCOLOR_NORMAL="echo -en \E[0m" echo -n "$2" && $MOVE_TO_COL echo -n "[" if [ $1 = "success" -o $1 = "0" ] ;then ${SETCOLOR_SUCCESS} echo -n $" OK " elif [ $1 = "failure" -o $1 = "1" ] ;then ${SETCOLOR_FAILURE} echo -n $"FAILED" else ${SETCOLOR_WARNING} echo -n $"WARNING" fi ${SETCOLOR_NORMAL} echo -n "]" echo } install_jdk(){ if ! [ -f "$DIR/$JDK_FILE" ];then color 1 "$JDK_FILE 文件不存在" exit; elif [ -d $JDK_DIR/jdk ];then color 1 "JDK 已经安装" exit else [ -d "$JDK_DIR" ] || mkdir -pv $JDK_DIR fi tar xvf $DIR/$JDK_FILE -C $JDK_DIR cd $JDK_DIR && ln -s jdk* jdk cat > /etc/profile.d/jdk.sh <<EOF export JAVA_HOME=$JDK_DIR/jdk export PATH=\$PATH:\$JAVA_HOME/bin #export JRE_HOME=\$JAVA_HOME/jre #export CLASSPATH=.:\$JAVA_HOME/lib/:\$JRE_HOME/lib/ EOF . /etc/profile.d/jdk.sh java -version && color 0 "JDK 安装完成" || { color 1 "JDK 安装失败" ; exit; } } install_jdk
安装openjdk yum install java-11-openjdk yum install java-1.6.0-openjdk yum install java-1.7.0-openjdk yum install java-1.8.0-openjdk