Install Java in Linux (Ubuntu / Debian)

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.

Ads by Google

Otherwise,

  • If you know the exact package name, you can use following command:
$ 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!

This Core Java tutorial was added on 25/12/2011.

«

»

Comments on “Install Java in Linux (Ubuntu / Debian)”

  1. vidyasagar

    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.

  2. kishore

    this really helps…..Thanks

  3. nizam

    this is very usefull formr

  4. shubham

    Thanks, really a good stuff.

  5. craigevil

    Useless.

    apt-get install openjdk-6-jre icedtea

    Or download Java from Oracle.

  6. Anders

    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.

  7. R S Chakravarti

    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 http://www.java.com.

  8. JavabynataraJ

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

  9. 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. I’ve summarised it all here: http://tkj.freeshell.org/bytes/2012/01/11/installing-sun-java-on-debian-after-it-was-removed-from-the-official-repositories/

  10. vignesh

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

  11. Kishore

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

  12. GeekDude

    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.

  13. Rasha

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

  14. jsl

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

  15. Apurwa

    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

Your Comment