【初學Linux】Web開發環境搭建——JDK的安裝

Linux版本 CentOS 7.0

關於Linux下jdk安裝網上有好幾種方法,這裏選用的是通過Yum命令直接進行安裝,省事省力,對於我這種懶人這就顯得很關鍵了。


以下是操作步驟

1.查看yum庫中都有哪些jdk版本(暫時只發現了openjdk)



2.選擇jdk1.7.0進行安裝,安裝完成默認目錄 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64

[root@localhost wyj]# yum install java-1.7.0-openjdk

依賴關係解決
============================================================================================================================================
 Package                                    架構                  版本                                         源                      大小
============================================================================================================================================
正在更新:
 java-1.7.0-openjdk                         x86_64                1:1.7.0.141-2.6.10.1.el7_3                   updates                231 k
爲依賴而安裝:
 copy-jdk-configs                           noarch                1.2-1.el7                                    base                    14 k
爲依賴而更新:
 chkconfig                                  x86_64                1.7.2-1.el7_3.1                              updates                175 k
 java-1.7.0-openjdk-headless                x86_64                1:1.7.0.141-2.6.10.1.el7_3                   updates                 25 M
 nspr                                       x86_64                4.13.1-1.0.el7_3                             updates                126 k
 nss                                        x86_64                3.28.4-1.2.el7_3                             updates                872 k
 nss-softokn                                x86_64                3.16.2.3-14.4.el7                            base                   306 k
 nss-softokn-freebl                         x86_64                3.16.2.3-14.4.el7                            base                   204 k
 nss-sysinit                                x86_64                3.28.4-1.2.el7_3                             updates                 58 k
 nss-tools                                  x86_64                3.28.4-1.2.el7_3                             updates                496 k
 nss-util                                   x86_64                3.28.4-1.0.el7_3                             updates                 73 k
 ntsysv                                     x86_64                1.7.2-1.el7_3.1                              updates                 38 k


事務概要
============================================================================================================================================
安裝           (  1 依賴軟件包)
升級  1 軟件包 (+10 依賴軟件包)

3.安裝完成需要進行環境變量的配置,終歸還是需要自己配置,對於linux新手小白的我來說簡直是災難性的,vi命令什麼的給跪了,爲了方便以後使用,把命令貼出來。

(1)[root@localhost wyj]# vi /etc/profile

E325: ATTENTION
Found a swap file by the name "/etc/.profile.swp"
          owned by: root   dated: Thu Aug 17 10:26:48 2017
         file name: /etc/profile
          modified: YES
         user name: root   host name: localhost.localdomain
        process ID: 16008
While opening file "/etc/profile"
             dated: Thu Aug 17 10:33:55 2017
      NEWER than swap file!

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /etc/profile"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/etc/.profile.swp"
    to avoid this message.
"/etc/profile" 83L, 2011C
Press ENTER or type command to continue

(2)按Entre進入文檔編輯;

(3)操作光標跳到底行,按 “i”;

(4)粘貼命令

#set java environment
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.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

(5)保存退出(按Esc進入命令界面,輸入“:wq”保存並退出);

(6)重啓生效[root@localhost wyj]# source /etc/profile



4. 安裝完成查看java版本,驗證是否安裝成功。

[root@localhost wyj]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

這就賊尷尬了,明明安裝的是1.7.0咋就變成1.8.0了。


5.通過命令查看下linux下存在的jdk

root@localhost wyj]# rpm -qa | grep jdk
copy-jdk-configs-1.2-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64

很明顯,系統原來就有個1.8,自己又裝了一個1.7,完美!考慮目前使用暫時沒啥毛病,先這樣了。



PS:中間安裝JDK的時候遇到提示

Existing lock /var/run/yum.pid: another copy is running as pid 3404.
Another app is currently holding the yum lock; waiting for it to exit...

百度大神給出的建議直接幹掉pid,然後重啓,當時心裏就七上八下,萬一那啥咋辦,但一想虛擬機怕個毛線,執行後順利安裝。

[root@centos5 ~]# rm -r /var/run/yum.pid
rm:是否刪除 一般文件 “/var/run/yum.pid”? y
[root@centos5 ~]# /sbin/service yum-updatesd restart

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章