linux java jdk安装
1.先检查系统是否有自带openjdk,如有先将其卸载
[root@VM-12-12-centos ~]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2022a-1.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.332.b09-1.el7_9.x86_64
java-1.8.0-openjdk-1.8.0.332.b09-1.el7_9.x86_64
执行如下命令将其全部卸载
yum -y remove python-javapackages-3.4.1-11.el7.noarch
或者直接执行如下命令批量卸载
rpm -qa | grep java |awk '{print $1}'|xargs yum -y remove
2.将下载好的jdk安装包上传到服务器上
3.创建/usr/local/java文件夹
mkdir -p /usr/local/java
4.将jdk安装包解压到/usr/local/java目录下
[root@VM-12-12-centos local]# tar -zxvf /root/jdk-8u161-linux-x64.tar.gz -C /usr/local/java/
[root@VM-12-12-centos local]# cd /usr/local/java/
[root@VM-12-12-centos java]# ll
total 4
drwxr-xr-x 8 10 143 4096 Dec 20 2017 jdk1.8.0_161
5.配置环境变量并使环境变量生效
[root@VM-12-12-centos jdk1.8.0_161]# vi /etc/profile
# 在最下面添加如下内容
JAVA_HOME=/usr/local/java/jdk1.8.0_161
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
#执行命令使环境变量生效
source /etc/profile
6.验证是否安装成功
[root@VM-12-12-centos jdk1.8.0_161]# java -version
javacjava version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
[root@VM-12-12-centos jdk1.8.0_161]# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-profile <profile> Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-Werror Terminate compilation if warnings occur
@<filename> Read options and filenames from file