Oracle Java JDK 7 on Ubuntu Linux

來源:互聯網
上載者:User
Oracle Java JDK 7 on Ubuntu Linux - Source or RPM Installation

    • 1. Introduction
    • 2. Download Oracle Java JDK 7
    • 3. Prepare Java's destination directory
    • 4. Install Java JDK 7
    • 5. Set system environment
    • 6. Installation from RPM package
    • 7. Conclusion
1. Introduction

In the previous article we have discussed how to install OpenJDK
java on ubuntu from the standard Ubuntu repository or Oracle's Java JDK 7 using Personal Package Archives ( PPA ). This article will cover installation of Oracle Java JDK 7 from a source package or by converting RPM Java package to the Debian software package
format.

2. Download Oracle Java JDK 7

First, we need to download Oracle Java JDK source package from the official
Oracle website. Navigate to JDK Downloads, accept license terms and download 
jdk-7<version>-linux-<architecture>.tar.gz. Current version of this source package is
jdk-7u11-linux-x64.tar.gz and this is also what we are going to use in this tutorial. Store this tarball source package into your home directory or some other arbitrary place. 

3. Prepare Java's destination directory

You can use Java by simply extracting it in any directory and then set your path to this location. However, in this article we will install Java into /usr/lib/jvm directory. Once we extract Java package to this directory we use this directory and set system's
environment appropriately to reflect the new Java installation. As a root or with help of the
sudo command create the directory /usr/lib/jvm:

$ sudo mkdir /usr/lib/jvm
4. Install Java JDK 7

The initial installation involves a simple tar file extraction for the Java's source package to /usr/lib/jvm. This can be achieved with the following command:

$ sudo tar -C /usr/lib/jvm -xzf jdk-7u11-linux-x64.tar.gz

 This will create a Java directory with a name appropriate to your Java version. For example, in this case it is:

$ ls /usr/lib/jvmjdk1.7.0_11
5. Set system environment

Although we have copied Java to the right location we still need to set up working environment to recognize our new Java directory. If we now test for the Java version we will get error message:

$ java -versionThe program 'java' can be found in the following packages: * default-jre * gcj-4.6-jre-headless * openjdk-6-jre-headless * gcj-4.5-jre-headless * openjdk-7-jre-headlessTry: sudo apt-get install <selected package>

First, we need to check whether there are already some Java alternatives installed on the system. To do that we can use the update-alternatives command:

$ sudo update-alternatives --list javaupdate-alternatives: error: no alternatives for java.

Currently, we have no other Java installations on the system so let us add our new installation:

$ sudo update-alternatives --install /usr/bin/java java \ /usr/lib/jvm/jdk1.7.0_11/jre/bin/java 1

 Do not forget "1" ( priority ) of the above command. To confirm validity of this new environment settings use again the
update-alternatives command:

$ sudo update-alternatives --list java/usr/lib/jvm/jdk1.7.0_11/jre/bin/java

or check directly for the Java version:

$ java -versionjava version "1.7.0_11"Java(TM) SE Runtime Environment (build 1.7.0_11-b21)Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

This confirms that the installation of Oracle Java JDK 7 on your Ubuntu Linux system was performed correctly.

In case that you have had already installed OpenJDK Java from the Ubuntu's repository you would still need to add your new Oracle Java JDK 7 installation into the system's environment with the above
update-alternatives --install command. Once you add another Java alternative to your system you can switch between both alternatives as shown in our previous article on how to install

java on ubuntu from Ubuntu's PPA.

6. Installation from RPM package

The above should provide a clear and easy way to install Oracle Java JDK 7 on your Ubuntu Linux system. Another install alternative is to convert Oracle's official RPM package to DEB and install it with the
dpkg command as follows:

First download Oracle's official RPM package suited for your architecture and convert it with the
alien command.

$ sudo alien --scripts jdk-7u11-linux-x64.rpm jdk_1.7.011-1_amd64.deb generated

This may take a while. Once ready, install this package with the dpkg command:

$ java -versionThe program 'java' can be found in the following packages:

at this point no Java is available on the system.

$ sudo dpkg -i jdk_1.7.011-1_amd64.deb Selecting previously unselected package jdk.(Reading database ... 48744 files and directories currently installed.)Unpacking jdk (from jdk_1.7.011-1_amd64.deb) ...

Now test for the Java version:

$ java -versionjava version "1.7.0_11"Java(TM) SE Runtime Environment (build 1.7.0_11-b21)Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
7. Conclusion

Since we have installed Java from the source package the above instruction should work for any Java version including older versions such as Oracle Java JDK 6.

Make sure you tune in to our
RSS and Linux jobs portal to stay informed about the latest opportunities in the field. Also visit our
Linux Forum if you want to share your Linux experiences with us or require additional help.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.