一、安裝前的準備
1、在官網上下載適用於Ubuntu的JDK8安裝包:jdk-8u221-linux-x64.tar.gz。
2、確認系統是否具備安裝JDK8的條件:Ubuntu14.04及以上版本,至少2GB的內存和2GHz的處理器。
3、打開終端,輸入以下命令更新Ubuntu源:
sudo apt-get update
sudo apt-get upgrade
二、安裝JDK8
1、解壓縮JDK8安裝包
在終端輸入以下命令,解壓縮JDK8安裝包:
tar -zxvf jdk-8u221-linux-x64.tar.gz
解壓縮完成後,將其移動到有意義的目錄下,以便於後期使用:
sudo mkdir /usr/java
sudo mv jdk1.8.0_221 /usr/java/
2、配置環境變量
輸入以下命令打開環境變量配置文件:
sudo vim /etc/profile
在文件末尾添加以下內容:
#set JDK environment
export JAVA_HOME=/usr/java/jdk1.8.0_221
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
保存退出後,輸入以下命令應用配置文件:
source /etc/profile
3、檢查JDK8是否安裝成功
在終端中分別輸入以下命令,檢查JDK8和JRE是否已經安裝成功:
java -version
輸出以下信息即為安裝成功:
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
同樣地,輸入以下命令,檢查JRE是否已經安裝成功:
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
-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
-version Version information
-help Print a synopsis of standard options
-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
三、刪除JDK8
在終端中輸入以下命令,刪除JDK8安裝包:
sudo rm -rf /usr/java/jdk1.8.0_221
打開環境變量配置文件:
sudo vim /etc/profile
將以下內容刪除:
#set JDK environment
export JAVA_HOME=/usr/java/jdk1.8.0_221
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
保存後,輸入以下命令應用配置文件:
source /etc/profile
在終端中輸入以下命令,檢查JDK8是否已經被刪除:
java -version
若提示”bash: java: command not found”,說明成功刪除JDK8。
原創文章,作者:BTMNA,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/362668.html