Install Java in Linux (Ubuntu / Debian)

Last modified on August 1st, 2014 by Joe.

This manual is to help install java (jdk) in Ubuntu / Debian Linux. Previously we discussed about how java’s installation has evolved over a period, then I promised to write an article on installing java on Linux. Yes I love Linux!

Before install you should be aware of couple of things.

  1. Which package I need to install
  2. Is that package already installed in my linux box

Which Package to Install?

‘Generally’ we use sun’s (oracle) jdk. If you do not have precondition on which package, then use sun’s package. FOSS equivalent alternative for sun JDK is openjdk.

To know the list of jdk packages available for you to install, use the following command:

$ dpkg-query -l '*jdk*'

Is java already installed in my linux?

$ which java 

or

$ java -version

Above two commands is the easiest way to identify if java is installed in your linux. But this will work only if you have installed jdk using standard means and the path are setup correctly.

Otherwise,

$ dpkg-query -W -f='${Status} ${Version}\n' sun-java6-jdk

in the above command, sun-java6-jdk is the package name.

If your jdk is not installed you will get the following response:
“No packages found matching sun-java6-jdk.”

or you can use the following command to get a detailed output

$ dpkg -s sun-java6-jdk

Java Installed but path not set or don’t know the path

Use the following commands to know the path of jdk installation

 $ sudo updatedb
$ locate java 

Install Jdk

As of the time of writing this article sun’s package is not available in the partner repositories. Therefore you will not be able to do live installation using defalut repositories.

Either, you need to add additional repository to your list or download package from available site and install it offline.

Method 1: Live Install

You need a live internet connection. Run the following commands sequentially.

$ sudo apt-get install python-software-properties

$ sudo add-apt-repository ppa:sun-java-community-team/sun-java6

$ sudo apt-get update

$ sudo apt-get install sun-java6-jdk

Method 2: Download and Install

http://archive.canonical.com/pool/partner/s/sun-java6/

This url has list of Sun’s packages available. Download the appropriate package and use the following command:

 $ sudo dpkg -i package.deb 

After this, your JAVA_HOME will be:

JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.06"

Wishing you Merry Christmas!

Comments on "Install Java in Linux (Ubuntu / Debian)"

  1. Mohan says:

    Nice one

  2. vidyasagar says:

    This post is really helpful. Thanks and Merry Christmas..! I want to install java in Fedora. Even though Fedora has Linux kernel, I think it will be different from this. Please help in this regard.

  3. kishore says:

    this really helps…..Thanks

  4. nizam says:

    this is very usefull formr

  5. shubham says:

    Thanks, really a good stuff.

  6. craigevil says:

    Useless.

    apt-get install openjdk-6-jre icedtea

    Or download Java from Oracle.

  7. Anders says:

    As craigevil noted.

    The reference implementation of Java is not Sun Java 7 or Oracle Java 7 any more. It is OpenJDK 7, which is in the repositories now.

    So no need of downloading Oracle Java, if there are no bugs in the program that relies on specific bugs in Oracle Java.

  8. R S Chakravarti says:

    Oracle has recently stopped issuing the sun-java6 packages (the old packages are still available on Debian Stable). Now we can either use openjdk (6 or 7) or the binary from Oracle’s site

  9. JavabynataraJ says:

    Thanks ..i will install in my system right now.

  10. Torstein Krause Johansen says:

    Hi, thanks for the write-up.

    I had to do two more things to get it to work on Debian (wheezy) changing sourceslistd in /usr/lib/python2.6/dist-packages/softwareproperties/ppa.py to sourceslistd = apt_pkg.config.find_dir(“Dir::Etc::sourceparts”)
    as well as purging my old Debian packages before using the PPA ones.

  11. vignesh says:

    The words comes from my heart, this is the information, i am looking for over a long period!!
    thanks…

  12. Kishore says:

    I like your effort for this blog..keep it up.This is very nice blog and can know more things about Java..

  13. GeekDude says:

    Actually, i too have a thought to install linux in my machine. After that i will follow your steps to install java in to that.

    Thanks.

  14. Rasha says:

    please I have a problem in the install,
    the following message:
    E: Couldn’t find package sun-java6-jdk
    what can I do?

  15. jsl says:

    Thanks a lot. I just installed java in my system.

  16. Apurwa says:

    Is there any way to install java without using the terminal and also how to install java if the tar.gz file is already downloaded

Comments are closed for "Install Java in Linux (Ubuntu / Debian)".