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.
- Which package I need to install.
- 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,
- 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.”
“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.
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
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"