How to Install Oracle Java 7 update 21 on Ubuntu 12.10 Linux


This blog entry will guide you through the step-by-step installation of Java on Ubuntu. I selected Oracle Java 7 update 21 and Ubuntu Linux 12.10 32 bit for this post.


Installing Java on Linux follows the download-extract-configure pattern. We will begin by downloading Oracle Java from Oracle’s website, extracting the download in the appropriate folder, and finally informing Ubuntu about the newly installed version of Java.

Step 1: Verify that you do not already have the correct version of Java installed.

Open your console window and enter the following command:

java –version

If you get the following result, you already have Java 7 update 21 installed and can ignore the rest of the steps:

java version 1.7.0_21
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) Client VM (build 23.21-b01, mixed mode)

Step 2: Download Oracle Java.

New release of Java are featured on the main Java download page.
If Java 7 update 21 is no longer featured, you can find the download by following the Previous Releases link found on the main download page.
Open the Java download page in your browser and download jdk-7u21-linux-i586.bin.
Make a note of the folder to which you downloaded the file. For further reference in this blog, I will call this folder the “downloads folder”.

Step 3: Create the installation folder.

The usr/lib/jvm is the default installation location of the Java JDK. Enter the following command in your console to create this folder, if it does not already exist:

sudo mkdir -p /usr/lib/jvm

The –p option ensures that all folders in the mkdir path are created.

Step 4: Navigate to the “downloads folder”.

If you downloaded the file to your Home folder, you can use the following command:

cd ~/

or substitute "~/" with the path to the “downloads folder”.

Step 5: Move the downloaded archive to the installation folder.

sudo mv jdk-7u21-linux-i586.tar.gz /usr/lib/jvm

Step 6: Navigate to the “installation folder”.

cd /usr/lib/jvm

Step 7: Unpack the tarball archives.

sudo tar zxvf jdk-7u21-linux-i586.tar.gz

If you want to conserve space you may delete the tarball archives.

sudo rm jdk-7u21-linux-i586.tar.gz

Step 8: Display the contents of the installation folder.

ls -l



Make a note of the newly created folder names.

Step 9: Inform Ubuntu where your Java installation is located.

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_21/bin/javac" 1
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_21/bin/java" 1

Step 10: Inform Ubuntu that this is your default Java installation.

sudo update-alternatives --set "javac" "/usr/lib/jvm/jdk1.7.0_21/bin/javac"
sudo update-alternatives --set "java" "/usr/lib/jvm/jdk1.7.0_21/bin/java"

Step 11: Update your system-wide PATH.

Edit your /etc/profile file using:

sudo nano /etc/profile

Add the following entries to the bottom of your /etc/profile file:

export JAVA_HOME
export PATH

Save your /etc/profile file using CTRL + X.

Step 12: Reload your system-wide PATH.

. /etc/profile

Step 13: Test your new installation.

java –version


java version 1.7.0_21
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) Client VM (build 23.21-b01, mixed mode)
javac –version


javac 1.7.0_21

Step 14: Congratulations – You have just installed Java on Ubuntu. Share this fantastic news using one of the share buttons or leave a comment in the reply section below.


15 thoughts on “How to Install Oracle Java 7 update 21 on Ubuntu 12.10 Linux

  1. Pingback: [SOLVED] install java on ubuntu

  2. Vikram

    Hi, I am new to Ubuntu linux and am still having the following problems:

    1. in step 8, I get the following when I do ls -l
    total 4
    drwxr -xr -x 8 500 500 4096 Apr 4 07:52 jdk1.7.0_21

    What is total 4?

    2. The other steps 9 -12 seemed to run fine without any errors.(p.s. I did these steps many times)

    3. In step 13, when I type

    java -version or javac -version

    I get the following error:

    bash: /usr/bin/java: No such file or directory

    When I go to /usr/bin and type ls -l *j, I get

    java -> /etc/alternatives/java
    javac -> /etc/alternatives/javac

    Please let me know what I am doing wrong. Thanks in advance for your reply.

  3. Hendré

    Your directory ownership is incorrect in your first point. Your owner is 500:500 and it must be root:root. Issue the following command to correct this:

    sudo chown root:root /usr/lib/jvm/jdk1.7.0_21

    Issue these commands to correct your ubuntu alternatives system. The first two commands assume that you only want to use Oracle Java and not other flavours like OpenJDK.

    sudo update-alternatives --remove-all java
    sudo update-alternatives --remove-all javac
    sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_21/bin/javac 1
    sudo update-alternatives --set "javac" "/usr/lib/jvm/jdk1.7.0_21/bin/javac"
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_21/bin/java 1
    sudo update-alternatives --set "java" "/usr/lib/jvm/jdk1.7.0_21/bin/java"

    If this does not resolve your issue, let me know if the following command works:

    /usr/lib/jvm/jdk1.7.0_21/bin/java -version

  4. Vikram


    thanks for your response. I applied all of the commands you suggested and am still having the following error:
    bash: /usr/bin/java: No such file or directory

    even if I try /usr/lib/jvm/jdk1.7.0_21/bin/java -version

    1. After applying

    sudo chown root:root /usr/lib/jvm/jdk1.7.0_21

    I did an ls -l and got

    dxwxr -xr -x 8 root root 4096 Apr 4 07:52 jdk1.7.0_21

    2. One issue is that the files underneath the jdk1.7.0_21 still have -rwxr -xr x 1 500 500 permissions

    I changed the jdk1.7.0_21/bin directory permission to root:root and also changed java and javac within the bin directory to root:root permission but the two java -version commands did not work.

    Most of the other files in the jdk1.7.0_21 directory are 500:500. I tried sudo chown -R but many file permissions could not be changed.

    3. In /usr/bin, here are the permissions for java and javac

    lrwxrwxrwx 1 root root 22 May 28 13:57 java -> /etc/alternatives/java
    lrwxrwxrwx 1 root root 22 May 28 13:46 javac -> /etc/alternatives/javac

    4. I am using ChrUbuntu (ubuntu 12.04 LTS) on an acer c7 chromebook.

    Any further suggestions would be greatly appreciated. Thanks.

  5. Hendré

    This installation procedure have not been tested on ChrUbuntu and I do not have any ChrUbuntu experience either. If the following commands do not work, I suggest you post on a ChrUbuntu forum:

    sudo chown -R root:root /usr/lib/jvm/jdk1.7.0_21/
    /usr/lib/jvm/jdk1.7.0_21/bin/java -version

    If you do get the problem solved, please post the answer here. :)

  6. Vikram


    I tried sudo chown -R root:root /usr/lib/jvm/jdk1.7.0_21/

    and all of my permissions under jkd1.7.0_21 changed to root root

    but I still get the error bash: /usr/lib/java even when I use /usr/lib/jvm/jdk1.7.0_21/bin/java -version

    Here is some additional information:

    1. If i type sudo java -version (or sudo javac -version) and hit enter, I simply go to the prompt


    This is my standard prompt in one of my terminals.

    2. If i type sudo /usr/lib/jvm/jdk1.7.0_21/bin/java -version and hit enter, I also go to the same prompt

    3. When I typed the following command

    sudo update-alternatives –install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_21/bin/javac 1

    I got the following response:

    Update-alternatives: using /usr/lib/jvm/jdk1.7.0_21/bin/javac to provide /usr/bin/javac (javac) in auto mode

    Is this a problem? what is auto mode?

    4. I got a similar response to the update-alternative –install command for java as well

    5. When I look at my system details for my ChrUbuntu partition on my Acer c7 chromebook, it states the OS version is ubuntu 12.04 LTS.

    If you have any additional suggestions based on my latest observations, please let me know. I will also go to a ChrUbuntu forum to see if they can provide some help as well. Thanks so much.

  7. Hendré

    If sudo /usr/lib/jvm/jdk1.7.0_21/bin/java -version does not work, the issue is between ChrUbuntu and Java. Running the command using sudo voids any permission restrictions and using the full path /usr/lib/jvm/jdk1.7.0_21/bin/ voids any update-alternatives or path related issues. Best option is to jump on a ChrUbuntu forum. (:

  8. shashi

    After giving all the commands, at following command
    java –version
    I am getting following response,

    Unrecognized option: –version
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.

    sudo /usr/lib/jvm/jdk1.7.0_21/bin/java -version
    the above command is telling the version of the java

  9. onebir

    I’d previously tried converting the rpm to a deb with alien & installing with dpkg but couldn’t get it working, but this worked perfectly! Thanks :)

  10. onebir

    (It’s java version “1.7.0_40″ now though, so the “21″s in the folder names become “40″s.)

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>