您好,登錄后才能下訂單哦!
本篇文章為大家展示了如何在CentOS環境中實現安裝jdk,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
環境
Linux版本:CentOS 6.5、Ubuntu 12.04.5
JDK版本:JDK 1.7
目錄
方法一:手動解壓JDK的壓縮包,然后設置環境變量
方法二:用yum安裝JDK
方法三:用rpm安裝JDK
方法四:Ubuntu 上使用apt-get安裝JDK
內容
方法一:手動解壓JDK的壓縮包,然后設置環境變量
1.在/usr/目錄下創建java目錄
[root@localhost ~]# mkdir/usr/java [root@localhost ~]# cd /usr/java
2.下載,然后解壓
[root@localhost java]# curl -O http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz [root@localhost java]# tar -zxvf jdk-7u79-linux-x64.tar.gz
3.設置環境變量
[root@localhost java]# vi /etc/profile
添加如下內容:
#set java environment JAVA_HOME=/usr/java/jdk1.7.0_79 JRE_HOME=/usr/java/jdk1.7.0_79/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
讓修改生效:
[root@localhost java]# source /etc/profile
4.驗證
[root@localhost java]# java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
方法二:用yum安裝JDK(CentOS)
1.查看yum庫中都有哪些jdk版本
[root@localhost ~]# yum search java|grep jdk ldapjdk-javadoc.x86_64 : Javadoc for ldapjdk java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle ldapjdk.x86_64 : The Mozilla LDAP Java SDK
2.選擇版本,進行安裝,我們這里安裝1.7版本
[root@localhost ~]# yum install java-1.7.0-openjdk
安裝完之后,默認的安裝目錄是在: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64
3.設置環境變量
[root@localhost ~]# vi /etc/profile
添加如下內容:
#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
讓修改生效:
[root@localhost java]# source /etc/profile
3.驗證 同上。
注:因為采用yum安裝jdk,系統考慮到多版本的問題,會用alternatives進行版本控制。開始,相應版本的jdk安裝在/usr/lib/jvm/之后,會在alternatives中注冊,在/etc/alternatives目錄下會產生一些鏈接到/usr/lib/jvm/中剛安裝好的jdk版本。
在/usr/bin下面會有鏈接到/etc/alternatives的相應的文件。比如,/usr/bin下面會有一個鏈接文件java的映射關系如下:
/usr/bin/java->/etc/alternatives/java /etc/alternatives/java-> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
這樣,java命令不用設置環境變量,就可以正常運行了。但如果對于tomcat或其他軟件來說還是要設置環境變量。
同樣,如果安裝新的版本jdk,就會重新鏈接到最新安裝的jdk版本。當然,也可以使用alternatives修改所要使用的版本。
具體方法可參照:《使用Linux的alternatives管理多版本的軟件》
方法三:用rpm安裝JDK
1.下載
[hadoop@localhost ~]$ curl -O http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm
2.使用rpm命令安裝
[root@localhost ~]# rpm -ivh jdk-7u79-linux-x64.rpm Preparing... ########################################### [100%] 1:jdk ###########################################[100%] Unpacking JAR files... rt.jar... jsse.jar... charsets.jar... tools.jar... localedata.jar... jfxrt.jar...
3.設置環境變量
[root@localhost java]# vi /etc/profile
添加如下內容:
#set java environment JAVA_HOME=/usr/java/jdk1.7.0_79 JRE_HOME=/usr/java/jdk1.7.0_79/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
讓修改生效:
[root@localhost java]# source /etc/profile
4.驗證
[root@localhost java]# java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
和yum安裝類似,不用設置環境變量就可以,運行java命令。rpm安裝方式默認會把jdk安裝到/usr/java/jdk1.7.0_79,然后通過三層鏈接,鏈接到/usr/bin,具體鏈接如下:
[root@localhost ~]# cd /bin [root@localhost bin]# ll|grep java lrwxrwxrwx. 1 root root 25 Mar 28 11:24 jar ->/usr/java/default/bin/jar lrwxrwxrwx. 1 root root 26 Mar 28 11:24 java -> /usr/java/default/bin/java lrwxrwxrwx. 1 root root 27 Mar 28 11:24 javac ->/usr/java/default/bin/javac lrwxrwxrwx. 1 root root 29 Mar 28 11:24 javadoc ->/usr/java/default/bin/javadoc lrwxrwxrwx. 1 root root 28 Mar 28 11:24 javaws ->/usr/java/default/bin/javaws lrwxrwxrwx. 1 root root 30 Mar 28 11:24 jcontrol ->/usr/java/default/bin/jcontrol [root@localhost bin]# cd /usr/java/ [root@localhost java]# ll total 4 lrwxrwxrwx. 1 root root 16 Mar 28 11:24 default-> /usr/java/latest drwxr-xr-x. 8 root root 4096 Mar 28 11:24 jdk1.7.0_79 lrwxrwxrwx. 1 root root 21 Mar 28 11:24 latest -> /usr/java/jdk1.7.0_79
方法四:Ubuntu 上使用apt-get安裝JDK
1.查看apt庫都有哪些jdk版本
root@Itble:~# apt-cache search java|grep jdk default-jdk - Standard Java or Java compatible Development Kit default-jdk-doc - Standard Java or Java compatible Development Kit (documentation) gcj-4.6-jdk - gcj and classpath development tools for Java(TM) gcj-jdk - gcj and classpath development tools for Java(TM) openjdk-6-dbg - Java runtime based on OpenJDK (debugging symbols) openjdk-6-demo - Java runtime based on OpenJDK (demos and examples) openjdk-6-doc - OpenJDK Development Kit (JDK) documentation openjdk-6-jdk - OpenJDK Development Kit (JDK) openjdk-6-jre-lib - OpenJDK Java runtime (architecture independent libraries) openjdk-6-source - OpenJDK Development Kit (JDK) source files openjdk-7-dbg - Java runtime based on OpenJDK (debugging symbols) openjdk-7-demo - Java runtime based on OpenJDK (demos and examples) openjdk-7-doc - OpenJDK Development Kit (JDK) documentation openjdk-7-jdk - OpenJDK Development Kit (JDK) openjdk-7-source - OpenJDK Development Kit (JDK) source files uwsgi-plugin-jvm-openjdk-6 - Java plugin for uWSGI (OpenJDK 6) uwsgi-plugin-jwsgi-openjdk-6 - JWSGI plugin for uWSGI (OpenJDK 6) openjdk-6-jre - OpenJDK Java runtime, using Hotspot JIT openjdk-6-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless) openjdk-7-jre - OpenJDK Java runtime, using Hotspot JIT openjdk-7-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless) openjdk-7-jre-lib - OpenJDK Java runtime (architecture independent libraries)
2.選擇版本進行安裝
root@Itble:~# apt-get install openjdk-7-jdk
3.設置環境變量
root@Itble:~# vi /etc/profile
添加如下內容:
#set java environment JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64 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
讓修改生效:
root@Itble:~# source /etc/profile
4.驗證
root@Itble:~# java -version java version "1.7.0_79" OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.12.04.1) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
上述內容就是如何在CentOS環境中實現安裝jdk,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。