一、下载安装包
选择适合自己系统的jdk版本
或者使用wget命令下载:wget命令如下
wget --user=orcale账号 --ask-password 下载链接
我的orcale账号为295135885@qq.com,下载链接可以右键自己要下载的jdk文件,复制链接地址获得
wget --user=295135885@qq.com --ask-password https://download.oracle.com/otn/java/jdk/8u231-b11/5b13a193868b4bf28bcb45c792fce896/jdk-8u231-linux-x64.tar.gz
回车后输入oracle账号登录密码即可开始下载
二、解压安装包
将安装包解压到指定目录下
tar -zxvf jdk-8u231-linux-x64.tar.gz -C /usr/jdk
三、修改环境变量
用vim编辑器来编辑profile文件,按i进入编辑
vim /etc/profile
添加一下内容,具体根据自己的目录进行设置
export JAVA_HOME=/usr/jdk/jdk1.8.0_231
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
esc退出编辑,保存并退出(输入 :wq 后回车)
重新加载profile文件
source /etc/profile
四、测试石是否安装成功
1. 使用javac命令
[root@iz8vb4efgq8tzqwlylia5uz jdk1.8.0_231]# 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
2. 使用java -version 查看jdk版本
[root@iz8vb4efgq8tzqwlylia5uz jdk1.8.0_231]# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)