dnf 安裝openjdk1.8
AnolisOS 可以使用 dnf 或者 yum 進(jìn)行軟件安裝空民,兩者指令結(jié)構(gòu)基本相同龙考,推薦使用dnf蛆封。
dnf --version #查看 dnf版本
4.7.0
Installed: dnf-0:4.7.0-8.0.1.an8.noarch at Mon 04 Jul 2022 05:16:37 AM GMT
Built : OpenAnolis Community at Wed 18 May 2022 08:05:12 AM GMT
Installed: rpm-0:4.14.3-23.0.1.an8.x86_64 at Mon 04 Jul 2022 05:16:24 AM GMT
Built : OpenAnolis Community at Wed 18 May 2022 11:24:53 AM GMT
使用dnf查找jdk
dnf search java|grep jdk
檢查是否已經(jīng)安裝了openjdk,查看具體版本
# java -version
openjdk version "1.8.0_342"
OpenJDK Runtime Environment (build 1.8.0_342-b07)
OpenJDK 64-Bit Server VM (build 25.342-b07, mixed mode)
使用dnf安裝openjdk1.8
dnf install java-1.8.0-openjdk
Repository epel is listed more than once in the configuration
上次元數(shù)據(jù)過期檢查:2:08:27 前杀糯,執(zhí)行于 2022年09月22日 星期四 13時52分44秒喻杈。
軟件包 java-1.8.0-openjdk-1:1.8.0.342.b07-2.an8_6.x86_64 已安裝彤枢。
依賴關(guān)系解決。
============================================================================================================================================================================
軟件包 架構(gòu) 版本 倉庫 大小
============================================================================================================================================================================
升級:
java-1.8.0-openjdk x86_64 1:1.8.0.345.b01-1.an8_6 AppStream 347 k
java-1.8.0-openjdk-devel x86_64 1:1.8.0.345.b01-1.an8_6 AppStream 9.8 M
java-1.8.0-openjdk-headless x86_64 1:1.8.0.345.b01-1.an8_6 AppStream 34 M
事務(wù)概要
============================================================================================================================================================================
升級 3 軟件包
總下載:44 M
確定嗎筒饰?[y/N]:
已升級:
java-1.8.0-openjdk-1:1.8.0.345.b01-1.an8_6.x86_64 java-1.8.0-openjdk-devel-1:1.8.0.345.b01-1.an8_6.x86_64 java-1.8.0-openjdk-headless-1:1.8.0.345.b01-1.an8_6.x86_64
完畢缴啡!
[root@anolis ~]# java -version
openjdk version "1.8.0_345"
OpenJDK Runtime Environment (build 1.8.0_345-b01)
OpenJDK 64-Bit Server VM (build 25.345-b01, mixed mode)
可見新版本的 openjdk1.8已經(jīng)安裝成功。
查看安裝路徑,默認(rèn)安裝路徑在/usr/lib/jvm/下邊龄砰,
如/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-2.an8_6.x86_64
[root@anolis ~]# which java
/usr/bin/java
[root@anolis ~]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-2.an8_6.x86_64
[root@anolis ~]# ll /usr/bin/java
lrwxrwxrwx 1 root root 22 9月 22 16:04 /usr/bin/java -> /etc/alternatives/java
[root@anolis ~]# ll /etc/alternatives/java
lrwxrwxrwx 1 root root 73 9月 22 16:04 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.an8_6.x86_64/jre/bin/java
[root@anolis ~]# ll /usr/lib/jvm/
總用量 0
lrwxrwxrwx 1 root root 26 9月 22 16:04 java -> /etc/alternatives/java_sdk
lrwxrwxrwx 1 root root 32 9月 22 16:04 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0
lrwxrwxrwx 1 root root 40 9月 22 16:04 java-1.8.0-openjdk -> /etc/alternatives/java_sdk_1.8.0_openjdk
drwxr-xr-x 7 root root 135 9月 22 16:04 java-1.8.0-openjdk-1.8.0.345.b01-1.an8_6.x86_64
lrwxrwxrwx 1 root root 34 9月 22 16:04 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx 1 root root 21 9月 22 16:04 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root 27 9月 22 16:04 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root 35 9月 22 16:04 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx 1 root root 51 9月 14 11:30 jre-1.8.0-openjdk-1.8.0.345.b01-1.an8_6.x86_64 -> java-1.8.0-openjdk-1.8.0.345.b01-1.an8_6.x86_64/jre
lrwxrwxrwx 1 root root 29 9月 22 16:04 jre-openjdk -> /etc/alternatives/jre_openjdk
查看java是否可用:javac
# javac
-bash: javac: command not found
錯誤原因:默認(rèn)安裝完只有運(yùn)行環(huán)境,java安裝目錄下只有jre文件夾
安裝開發(fā)環(huán)境dnf install java-1.8.0-openjdk-devel.x86_64
安裝完可看到j(luò)ava安裝目錄下出現(xiàn)bin讨衣、lib等文件夾:
[root@anolis ~]# cd /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.an8_6.x86_64/
[root@anolis java-1.8.0-openjdk-1.8.0.345.b01-1.an8_6.x86_64]# ll
總用量 184
-rw-r--r-- 1 root root 1522 9月 14 11:29 ASSEMBLY_EXCEPTION
drwxr-xr-x 2 root root 4096 9月 22 16:04 bin
drwxr-xr-x 3 root root 132 9月 22 16:04 include
drwxr-xr-x 4 root root 95 9月 22 16:04 jre
drwxr-xr-x 3 root root 144 9月 22 16:04 lib
-rw-r--r-- 1 root root 19274 9月 14 11:29 LICENSE
drwxr-xr-x 2 root root 204 9月 22 16:04 tapset
-rw-r--r-- 1 root root 157063 9月 14 11:29 THIRD_PARTY_README
再次輸入javac說明安裝成功
[root@anolis ~]# javac
用法: javac <options> <source files>
其中, 可能的選項(xiàng)包括:
-g 生成所有調(diào)試信息
-g:none 不生成任何調(diào)試信息
-g:{lines,vars,source} 只生成某些調(diào)試信息
-nowarn 不生成任何警告
-verbose 輸出有關(guān)編譯器正在執(zhí)行的操作的消息
-deprecation 輸出使用已過時的 API 的源位置
-classpath <路徑> 指定查找用戶類文件和注釋處理程序的位置
-cp <路徑> 指定查找用戶類文件和注釋處理程序的位置
-sourcepath <路徑> 指定查找輸入源文件的位置
-bootclasspath <路徑> 覆蓋引導(dǎo)類文件的位置
-extdirs <目錄> 覆蓋所安裝擴(kuò)展的位置
-endorseddirs <目錄> 覆蓋簽名的標(biāo)準(zhǔn)路徑的位置
-proc:{none,only} 控制是否執(zhí)行注釋處理和/或編譯换棚。
-processor <class1>[,<class2>,<class3>...] 要運(yùn)行的注釋處理程序的名稱; 繞過默認(rèn)的搜索進(jìn)程
-processorpath <路徑> 指定查找注釋處理程序的位置
-parameters 生成元數(shù)據(jù)以用于方法參數(shù)的反射
-d <目錄> 指定放置生成的類文件的位置
-s <目錄> 指定放置生成的源文件的位置
-h <目錄> 指定放置生成的本機(jī)標(biāo)頭文件的位置
-implicit:{none,class} 指定是否為隱式引用文件生成類文件
-encoding <編碼> 指定源文件使用的字符編碼
-source <發(fā)行版> 提供與指定發(fā)行版的源兼容性
-target <發(fā)行版> 生成特定 VM 版本的類文件
-profile <配置文件> 請確保使用的 API 在指定的配置文件中可用
-version 版本信息
-help 輸出標(biāo)準(zhǔn)選項(xiàng)的提要
-A關(guān)鍵字[=值] 傳遞給注釋處理程序的選項(xiàng)
-X 輸出非標(biāo)準(zhǔn)選項(xiàng)的提要
-J<標(biāo)記> 直接將 <標(biāo)記> 傳遞給運(yùn)行時系統(tǒng)
-Werror 出現(xiàn)警告時終止編譯
@<文件名> 從文件讀取選項(xiàng)和文件名
查看環(huán)境變量
vi /etc/profile
在profile文件末尾查看如下內(nèi)容:
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-2.an8_6.x86_64
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
使環(huán)境變量生效:source /etc/profile
[root@anolis ~]# source /etc/profile
[root@anolis ~]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-2.an8_6.x86_64
二進(jìn)制安裝jdk1.8
上傳jdk-8u11-linux-x64.tar.gz 安裝包
解壓jdk文件
tar -xzvf jdk-8u11-linux-x64.tar.gz -C /usr/local/
添加環(huán)境變量
echo 'export JAVA_HOME=/usr/local/jdk1.8.0_11' | sudo tee -a /etc/profile
echo 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' | sudo tee -a /etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' | sudo tee -a /etc/profile
使變量立即生效
source /etc/profile
# java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
[root@anolis ~]# 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