Oracle Java JDK 7 on Ubuntu Linux

来源:互联网 发布:百叶窗算法 编辑:程序博客网 时间:2024/05/22 15:35

    • 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 isjdk-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 thesudo 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 theupdate-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 aboveupdate-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 installjava 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 thedpkg command as follows:

First download Oracle's official RPM package suited for your architecture and convert it with thealien 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 ourLinux Forum if you want to share your Linux experiences with us or require additional help.