How do I install Oracle Java JDK 7?

來源:互聯網
上載者:User

http://askubuntu.com/questions/55848/how-do-i-install-oracle-java-jdk-7

There is a similar question on how to install JRE 7.

Install the JDK
  • Download he 32bit or 64bit Linux "compressed binary file" - it has a ".tar.gz" file extension i.e. "[java-version]-i586.tar.gz" for 32bit and "[java-version]-x64.tar.gz" for 64bit
  • Uncompress it

    tar -xvf jdk-7u2-linux-i586.tar.gz (32bit)

    tar -xvf jdk-7u2-linux-x64.tar.gz (64bit)

JDK 7 package is extracted into ./jdk.1.7.0_02 directory. N.B. check carefully this folder name since Oracle seem to change this occasionally with each update.

  • Now move the JDK 7 directory to /usr/lib
sudo mkdir -p /usr/lib/jvmsudo mv ./jdk.1.7.0_02 /usr/lib/jvm/jdk1.7.0
  • Now run
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
  • Correct the permissions of the executables:
sudo chmod a+x /usr/bin/java sudo chmod a+x /usr/bin/javac sudo chmod a+x /usr/bin/javaws

N.B. remember - Java JDK has many more executables that you can similarly install as above. java, javac, javaws are probably the most frequently required.

This answer lists the other executables available.

  • Run
sudo update-alternatives --config java

You will see output similar one below - choose the number of jdk1.7.0 - for example 3 in this list:

$sudo update-alternatives --config javaThere are 3 choices for the alternative java (providing /usr/bin/java).Selection Path Priority Status————————————————————* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode3 /usr/lib/jvm/jdk1.7.0/jre/bin/java 3 manual modePress enter to keep the current choice[*], or type selection number: 3update-alternatives: using /usr/lib/jvm/jdk1.7.0/jre/bin/java to provide /usr/bin/java (java) in manual mode.

Check the version of you new JDK 7 installation:

java -version

java version “1.7.0”Java(TM) SE Runtime Environment (build 1.7.0-b147)Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode) 

Repeat the above for:

sudo update-alternatives --config javacsudo update-alternatives --config javaws

Enable mozilla firefox plugin:

32 bit:ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/64 bit:ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

N.B. you can link the plugin (libnpjp2.so) to /usr/lib/firefox/plugins/ for a system wide installation

Depending on your configuration, you might need to update the apparmor profile for firefox (or other browsers) in /etc/apparmor.d/abstractions/ubuntu-browsers.d/java

# Replace the two lines:#  /usr/lib/jvm/java-*-sun-1.*/jre/bin/java{,_vm} cx -> browser_java,#  /usr/lib/jvm/java-*-sun-1.*/jre/lib/*/libnp*.so cx -> browser_java,# with those (or adapt to your new jdk folder name)/usr/lib/jvm/jdk*/jre/bin/java{,_vm} cx -> browser_java,/usr/lib/jvm/jdk*/jre/lib/*/libnp*.so cx -> browser_java,

Then restart apparmor:

sudo /etc/init.d/apparmor restart

Confirm that the JRE has been successful by using the official oracle website.

For Java 6:

  • How do I install Oracle JDK 6?

If you're on a fresh installation of Ubuntu with no previous Java installations, this script automates the process outlined above if you don't want to type all that into a console. Remember, you still need to download Java from Oracle's website -- Oracle's links are not wget friendly.

Before using this make sure that this script is in the same directory as the .tar.gz file extension that you downloaded and there are no files that start with jdk-7 in the same folder -- if there are, please move them out of the folder temporarily. Remember to make the script executable, either by doing chmod +x <script's directory> or right clicking the document, pressing properties, going to the Permissions tab, and checking "Allow executing file as a program."

#!/bin/shtar -xvf jdk-7*sudo mkdir /usr/lib/jvmsudo mv ./jdk1.7* /usr/lib/jvm/jdk1.7.0sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1sudo chmod a+x /usr/bin/javasudo chmod a+x /usr/bin/javacsudo chmod a+x /usr/bin/javaws

If you want to install the plugin for Firefox then add this to the end of the script

mkdir ~/.mozilla/pluginsln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/sudo /etc/init.d/apparmor restart

Confirm if Java has been properly installed.

java -version

Confirm that the JRE Mozilla plugin has been successful by using the official oracle website.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.