1. Why upgrade
Because I upgraded the jenkins version from 2.328 to 2.387 before, my slave nodes need to be reconnected, but during the connection process, I found that the new version of jenkins does not support jdk8, so I started to upgrade jdk11, and then started working.
Two, linux upgrade jdk11
1. Install jdk11
yum install java-11-openjdk* -y
2. Switch java version
alternatives --config java
3. macos upgrade jdk11
1. Download jdk11
brew install openjdk@11
2. Install soft links
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
3. Environment variable configuration supports java version switching
1. Use /usr/libexec/java_home command line tool (supports dynamic search of Java Home, the default is Java Home of the latest version of JDK)
2. Configure $JAVA_HOME environment variable, find ~/.bash_profile Any one of ~/.bashrc, ~/.zshrc and other configuration files
# 配置Java11的家目录
export JAVA_11_HOME=$(/usr/libexec/java_home -v11)
# 配置Java8的家目录
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
# 配置别名,方便快速切换
alias java8='export JAVA_HOME=$JAVA_8_HOME'
# 配置别名,方便快速切换
alias java11='export JAVA_HOME=$JAVA_HOME'
# 习惯性配置,可选
export PATH=$JAVA_HOME/bin:$PATH:.
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib
# 验证
java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment Homebrew (build 11.0.15+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.15+0, mixed mode)
# 切换
java8 && source ~/.bash_profile ## &&表示前一条命令执行成功时,才执行后一条命令
java -version
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
① Switch Java11: java11 && source ~/.bash_profile.
① Switch Java8: java8 && source ~/.bash_profile.
MacBook-Pro ~ % java11 && source ~/.bash_profile
WARNING: this script is deprecated, please see git-completion.zsh
MacBook-Pro ~ % java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment Homebrew (build 11.0.15+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.15+0, mixed mode)