TShopping

 找回密碼
 註冊
搜索
查看: 886|回復: 2

[教學] (如何安裝JAVA在CentOS6)How to install and setup Oracle JAVA JDK in CentOS 6

[複製鏈接]
發表於 2014-4-28 19:24:20 | 顯示全部樓層 |閱讀模式
 
Push to Facebook Push to Plurk Push to Twitter 
1.Update the system(更新系統)
2.Remove any installed versions(移除任何JAVA版本)
3.Download JAVA JDK6, JDK7 or JDK8(下載JDK)
4.Install JAVA JDK6, JDK7 or JDK8(安裝JDK)
5.Set-up JAVA JDK6 or JDK7(設定JDK)
6.Confirm JAVA JDK6 or JDK7 installation(確認安裝JDK安裝完成)
If instead you want to do this on Debian Wheezy then check how to install and set-up Oracle JAVA 7 on Debian Wheezy article

1. The first thing I've done was to make sure the CentOS 6 system is fully up-to-date, so I ran(首先更新系統到最新)
  1. yum update
複製代碼
2. Once the update completed, I then checked the system for any other installed JAVA packages using(檢查JDK版本)
  1. rpm -qa | grep -E '^open[jre|jdk]|j[re|dk]'
複製代碼
there was the java-1.6.0-openjdk-1.6.0.0-1.56.1.11.8.el6_3.i686 package already installed so I removed it by running(移除JDK6版)
  1. yum remove java-1.6.0-openjdk
複製代碼
3. The next step was to go and download the required JAVA JDK package for the system I was working on. It was a 32 bit CentOS 6 so I needed to get the 32 bit JAVA JDK package from Oracle's JAVA download page(到JDK下載頁面)

Note that I needed to install an older version of JAVA JDK since it was specific to the software I was setting up.

You may also wget Oracle JDK 8, JDK 7 or JDK 6 using command line as in

JAVA JDK 8

for 64bit (x86_64) system(WGET JDK 8 64位元版本)
  1. wget --no-cookies \
  2. --no-check-certificate \
  3. --header "Cookie: oraclelicense=accept-securebackup-cookie" \
  4. "http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-x64.rpm" \
  5. -O /opt/jdk-8-linux-x64.rpm
複製代碼
for 32bit (x86) system(WGET JDK 8 32位元版本)
  1. wget --no-cookies \
  2. --no-check-certificate \
  3. --header "Cookie: oraclelicense=accept-securebackup-cookie" \
  4. "http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-i586.rpm" \
  5. -O /opt/jdk-8-linux-i586.rpm
複製代碼
JAVA JDK 7

for 64bit (x86_64) system(WGET JDK 7 64位元版本)
  1. wget --no-cookies \
  2. --no-check-certificate \
  3. --header "Cookie: oraclelicense=accept-securebackup-cookie" \
  4. "http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.rpm" \
  5. -O /opt/jdk-7-linux-x64.rpm
  6. for 32bit (x86) system
複製代碼
(WGET JDK 7 32位元版本)
  1. wget --no-cookies \
  2. --no-check-certificate \
  3. --header "Cookie: oraclelicense=accept-securebackup-cookie" \
  4. "http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-i586.rpm" \
  5. -O /opt/jdk-7-linux-i586.rpm
複製代碼
JAVA JDK 6

for 64bit (x86_64) system(WGET JDK 6 64位元版本)
  1. wget --no-cookies \
  2. --no-check-certificate \
  3. --header "Cookie: oraclelicense=accept-securebackup-cookie" \
  4. "http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-x64-rpm.bin" \
  5. -O /opt/jdk-6u45-linux-x64-rpm.bin
複製代碼
for 32bit (x86) system(WGET JDK 6 32位元版本)
  1. wget --no-cookies \
  2. --no-check-certificate \
  3. --header "Cookie: oraclelicense=accept-securebackup-cookie" \
  4. "http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-i586-rpm.bin" \
  5. -O /opt/jdk-6u45-linux-i586-rpm.bin
複製代碼
4. Once the JAVA JDK package got downloaded I proceeded with installing the package.

a) Installing the JAVA JDK6 package in CentOS 6(安裝JDK 6)

for 32bit (x86) system(設定32位元 系統權限)
  1. chmod +x /opt/jdk-6u45-linux-i586-rpm.bin
  2. /opt/./jdk-6u45-linux-i586-rpm.bin
複製代碼
for 64bit (x86_64) system

(設定32位元 系統權限)
  1. chmod +x /opt/jdk-6u45-linux-x64-rpm.bin
  2. /opt/./jdk-6u45-linux-x64-rpm.bin
複製代碼
b) Installing the JAVA JDK7 package in CentOS 6(安裝JDK 7)

for 64bit (x86_64) system(安裝64位元 系統)
  1. rpm -Uvh /opt/jdk-7-linux-x64.rpm
複製代碼
for 32bit (x86) system(安裝32位元 系統)
  1. rpm -Uvh /opt/jdk-7-linux-i586.rpm
複製代碼
c) Installing the JAVA JDK8 package in CentOS 6(安裝JDK 8)

for 64bit (x86_64) system(安裝64位元 系統)
  1. rpm -Uvh /opt/jdk-8-linux-x64.rpm
複製代碼
for 32bit (x86) system(安裝32位元 系統)
  1. rpm -Uvh /opt/jdk-8-linux-i586.rpm
複製代碼
5. Once the JAVA JDK package is installed, I then needed to configure it on the system using the alternatives command. This is in order to tell the system what are the default commands for JAVA. Most sys admins aren't aware about this and I think that it is a vital part when setting the JAVA package

a) Setting up the JAVA JDK6 package(設定JDK 6 alternatives進行管理)
  1. alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_45/jre/bin/java 20000
  2. alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_45/bin/jar 20000
  3. alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_45/bin/javac 20000
  4. alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.6.0_45/jre/bin/javaws 20000
  5. alternatives --set java /usr/java/jdk1.6.0_45/jre/bin/java
  6. alternatives --set javaws /usr/java/jdk1.6.0_45/jre/bin/javaws
  7. alternatives --set javac /usr/java/jdk1.6.0_45/bin/javac
  8. alternatives --set jar /usr/java/jdk1.6.0_45/bin/jar
複製代碼
this set the default commands for JAVA JDK6 and listing the /etc/alternatives/ directory showed the following(檢查alternatives設定是否完成)
  1. ls -lA /etc/alternatives/
  2. lrwxrwxrwx. 1 root root 29 Feb 22 03:39 jar -> /usr/java/jdk1.6.0_45/bin/jar
  3. lrwxrwxrwx. 1 root root 34 Feb 22 03:39 java -> /usr/java/jdk1.6.0_45/jre/bin/java
  4. lrwxrwxrwx. 1 root root 31 Feb 22 03:39 javac -> /usr/java/jdk1.6.0_45/bin/javac
  5. lrwxrwxrwx. 1 root root 36 Feb 22 03:39 javaws -> /usr/java/jdk1.6.0_45/jre/bin/javaws
複製代碼
b) Setting up the JAVA JDK7 package(設定JDK 7 alternatives進行管理)
  1. alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_51/jre/bin/java 20000
  2. alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0_51/bin/jar 20000
  3. alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_51/bin/javac 20000
  4. alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0_51/jre/bin/javaws 20000
  5. alternatives --set java /usr/java/jdk1.7.0_51/jre/bin/java
  6. alternatives --set javaws /usr/java/jdk1.7.0_51/jre/bin/javaws
  7. alternatives --set javac /usr/java/jdk1.7.0_51/bin/javac
  8. alternatives --set jar /usr/java/jdk1.7.0_51/bin/jar
複製代碼
this set the default commands for JAVA JDK7 and listing the /etc/alternatives/ directory showed the following(檢查alternatives設定是否完成)
  1. ls -lA /etc/alternatives/{jar,java*}

  2. lrwxrwxrwx. 1 root root 29 Mar 7 04:13 /etc/alternatives/jar -> /usr/java/jdk1.7.0_51/bin/jar
  3. lrwxrwxrwx. 1 root root 34 Mar 7 04:13 /etc/alternatives/java -> /usr/java/jdk1.7.0_51/jre/bin/java
  4. lrwxrwxrwx. 1 root root 31 Mar 7 04:13 /etc/alternatives/javac -> /usr/java/jdk1.7.0_51/bin/javac
  5. lrwxrwxrwx. 1 root root 36 Mar 7 04:13 /etc/alternatives/javaws -> /usr/java/jdk1.7.0_51/jre/bin/javaws
複製代碼
6. Finally I verified the installed version of JAVA(確認JDK版本)
  1. java -version

  2. java version "1.7.0_51"
  3. Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
  4. Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
複製代碼
I know this how-to will serve me as a quick reference for installing Oracle JAVA in the future and I truly hope this will help someone else too.

 

臉書網友討論
發表於 2014-6-9 08:26:24 | 顯示全部樓層
绝对喜欢,好帖子不多哦,顶一下

版主招募中

發表於 2014-9-4 21:58:07 | 顯示全部樓層
不看不知道,看了才知道,好帖











bjcars.net












北京搬家公司电话


您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2016-12-11 22:16 , Processed in 0.056019 second(s), 21 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表