查看系统是否已安装OpenJDK。一般的linux都默认使用了开源的OpenJDK。
# 查看
rpm -qa | grep java
rpm -qa | grep jdk
# 批量卸载
rpm -qa | grep jdk | xargs rpm -e --nodeps
rpm -qa | grep java | xargs rpm -e --nodeps
#yum search java | grep -i --color JDK //查看可用的JDK软件包列表
#yum --showduplicate list java* | grep 1.8.0 //自定义yum install -y java-1.8.0-openjdk-1.8.0.201.b09-0.amzn2
yum -y install java-1.8.0-openjdk*
which java
ll -rt /usr/bin/java
[root@slave ~]# ls -lr /etc/alternatives/java
lrwxrwxrwx 1 root root 71 Nov 24 14:16 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre/bin/java
ll /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre/bin/ # openJDK执行文件
# 配置环境变量
vi /etc/profile
export JAVA_HOME=/usr/lib/jvm/java # 这是yum安装java的
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
# 刷新配置
[root@jenkins-slave205 jvm]# source /etc/profile
[root@jenkins-slave205 jvm]# echo $PATH
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
Openjdk和Oracejdk安装方式类同
# 直接使用此方法下载会有问题,请使用下面命令下载
wget -P /root/shared http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz
# 如果没有 wget 命令,可以是用下面命令安装 wget
yum -y install wget
# 下载,解决上面下载文件不全问题
cd /root/shared
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz"
# 解压
tar -zxvf /root/shared/jdk-8u191-linux-x64.tar.gz
tar -zxf apache-maven-3.8.2-bin.tar.gz && mv apache-maven-3.8.2 maven
echo "export MAVEN_HOME=/opt/maven" >>/etc/profile
echo "export PATH=$MAVEN_HOME/bin:$PATH" >>/etc/profile
最终效果:
export JAVA_HOME=/usr/lib/jvm/java
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export MAVEN_HOME=/opt/maven
export PATH=$MAVEN_HOME/bin:$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
变量 | 含义 |
---|---|
JAVA_HOME | 指明JDK安装路径,就是刚才安装时所选择的路径,此路径下包括lib,bin,jre等文件夹(tomcat,Eclipse的运行都需要依靠此变量) |
CLASSPATH | 为java加载类(class or lib)路径,只有类在classpath中,java命令才能识别,设:.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib 。CLASSPATH 变量值中的.表示当前目录 |
PATH | 使得系统可以在任何路径下识别java命令,设为:$JAVA_HOME/bin:$JRE_HOME/bin |
特别注意 | 环境变量值的结尾没有任何符号,不同值之间用:隔开(windows中用;) |
SSH启动器{host=‘192.168.1.1’, port=22, credentialsId=‘8e58fbdf-59e6-4328-bbf0-47f0c1137871’, jvmOptions=‘’, javaPath=‘/usr/bin/java
’, prefixStartSlaveCmd=‘’, suffixStartSlaveCmd=‘’, launchTimeoutSeconds=60, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.KnownHostsFileKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
<=[JENKINS REMOTING CAPACITY]=>channel started
Remoting version: 4.11.2
This is a Unix agent
Evacuated stdout
Agent successfully connected and online
Live up to yourself, not fear the future!