AnolisOS 8 安裝jdk1.8

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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市反镇,隨后出現(xiàn)的幾起案子固蚤,更是在濱河造成了極大的恐慌,老刑警劉巖歹茶,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件夕玩,死亡現(xiàn)場離奇詭異你弦,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)燎孟,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進(jìn)店門禽作,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人揩页,你說我怎么就攤上這事旷偿。” “怎么了爆侣?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵萍程,是天一觀的道長。 經(jīng)常有香客問我兔仰,道長茫负,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任乎赴,我火速辦了婚禮忍法,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘无虚。我一直安慰自己缔赠,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布友题。 她就那樣靜靜地躺著嗤堰,像睡著了一般。 火紅的嫁衣襯著肌膚如雪度宦。 梳的紋絲不亂的頭發(fā)上踢匣,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天,我揣著相機(jī)與錄音戈抄,去河邊找鬼离唬。 笑死,一個胖子當(dāng)著我的面吹牛划鸽,可吹牛的內(nèi)容都是我干的输莺。 我是一名探鬼主播,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼裸诽,長吁一口氣:“原來是場噩夢啊……” “哼嫂用!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起丈冬,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤嘱函,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后埂蕊,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體往弓,經(jīng)...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡疏唾,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了函似。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片槐脏。...
    茶點(diǎn)故事閱讀 39,722評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖缴淋,靈堂內(nèi)的尸體忽然破棺而出准给,到底是詐尸還是另有隱情,我是刑警寧澤重抖,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布露氮,位于F島的核電站,受9級特大地震影響钟沛,放射性物質(zhì)發(fā)生泄漏畔规。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一恨统、第九天 我趴在偏房一處隱蔽的房頂上張望叁扫。 院中可真熱鬧,春花似錦畜埋、人聲如沸莫绣。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽对室。三九已至,卻和暖如春咖祭,著一層夾襖步出監(jiān)牢的瞬間掩宜,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工么翰, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留牺汤,地道東北人。 一個月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓浩嫌,卻偏偏與公主長得像檐迟,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子码耐,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評論 2 353

推薦閱讀更多精彩內(nèi)容