How To Install Java JDK or JRE on Ubuntu or Debian

by Ramesh Natarajan on September 25, 2009

Question: How do I Install Java on Ubuntu or Debian OS?

Answer: If Java is not installed, you’ll get the following error message when you do java -version.

# java -version
The program 'java' can be found in the following packages:
 * gij-4.3
 * java-gcj-compat-headless
 * openjdk-6-jre-headless
 * cacao
 * gij-4.2
 * jamvm
 * kaffe
Try: apt-get install

-su: java: command not found

Search for Java Package that needs to be Installed

Before installing, you may want to do apt-cache search to find out all available packages that starts with sun-java.

As shown below, you’ll find both Java5 and Java6 JDK and JRE related packages.

# sudo apt-get update

# apt-cache search ^sun-java
sun-javadb-client - Java DB client
sun-javadb-common - Java DB common files
sun-javadb-core - Java DB core
sun-javadb-demo - Java DB demo
sun-javadb-doc - Java DB documentation
sun-javadb-javadoc - Java DB javadoc
sun-java5-bin - Sun Java(TM) Runtime Environment (JRE) 5.0 (architecture dependent files)
sun-java5-demo - Sun Java(TM) Development Kit (JDK) 5.0 demos and examples
sun-java5-doc - Sun JDK(TM) Documention -- integration installer
sun-java5-fonts - Lucida TrueType fonts (from the Sun JRE)
sun-java5-jdk - Sun Java(TM) Development Kit (JDK) 5.0
sun-java5-jre - Sun Java(TM) Runtime Environment (JRE) 5.0 (architecture independent files)
sun-java5-plugin - The Java(TM) Plug-in, Java SE 5.0
sun-java5-source - Sun Java(TM) Development Kit (JDK) 5.0 source files
sun-java6-bin - Sun Java(TM) Runtime Environment (JRE) 6 (architecture dependent files)
sun-java6-demo - Sun Java(TM) Development Kit (JDK) 6 demos and examples
sun-java6-doc - Sun JDK(TM) Documention -- integration installer
sun-java6-fonts - Lucida TrueType fonts (from the Sun JRE)
sun-java6-javadb - Java(TM) DB, Sun Microsystems' distribution of Apache Derby
sun-java6-jdk - Sun Java(TM) Development Kit (JDK) 6
sun-java6-jre - Sun Java(TM) Runtime Environment (JRE) 6 (architecture independent files)
sun-java6-plugin - The Java(TM) Plug-in, Java SE 6
sun-java6-source - Sun Java(TM) Development Kit (JDK) 6 source files

Install Java on Ubuntu

Execute sudo apt-get install sun-java6-jdk to install the Java 6 JDK on Ubuntu as shown below. If you need only the run time environment, install sun-java6-jre.

# sudo apt-get install sun-java6-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-2.6.28-11 linux-headers-2.6.28-11-generic
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  gsfonts-x11 java-common odbcinst1debian1 sun-java6-bin sun-java6-jre unixodbc
Suggested packages:
  equivs sun-java6-demo openjdk-6-doc sun-java6-source sun-java6-plugin ia32-sun-java6-plugin sun-java6-fonts
  libmyodbc odbc-postgresql libct1
The following NEW packages will be installed:
  gsfonts-x11 java-common odbcinst1debian1 sun-java6-bin sun-java6-jdk sun-java6-jre unixodbc
0 upgraded, 7 newly installed, 0 to remove and 68 not upgraded.
Need to get 54.5MB of archives.
After this operation, 161MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://us.archive.ubuntu.com jaunty/main java-common 0.30ubuntu4 [80.3kB]
Get:2 http://us.archive.ubuntu.com jaunty-updates/multiverse sun-java6-jre 6-16-0ubuntu1.9.04 [6421kB]
Get:3 http://us.archive.ubuntu.com jaunty/main odbcinst1debian1 2.2.11-16build3 [66.3kB]
Get:4 http://us.archive.ubuntu.com jaunty/main unixodbc 2.2.11-16build3 [295kB]
Get:5 http://us.archive.ubuntu.com jaunty-updates/multiverse sun-java6-bin 6-16-0ubuntu1.9.04 [29.1MB]
Get:6 http://us.archive.ubuntu.com jaunty-updates/multiverse sun-java6-jdk 6-16-0ubuntu1.9.04 [18.5MB]
Get:7 http://us.archive.ubuntu.com jaunty/main gsfonts-x11 0.21 [10.5kB]
Fetched 54.5MB in 4min 53s (186kB/s)
Preconfiguring packages ...
Selecting previously deselected package java-common.
(Reading database ... 142715 files and directories currently installed.)
Unpacking java-common (from .../java-common_0.30ubuntu4_all.deb) ...
Selecting previously deselected package sun-java6-jre.
Unpacking sun-java6-jre (from .../sun-java6-jre_6-16-0ubuntu1.9.04_all.deb) ...
Selecting previously deselected package odbcinst1debian1.
Unpacking odbcinst1debian1 (from .../odbcinst1debian1_2.2.11-16build3_i386.deb) ...
Selecting previously deselected package unixodbc.
Unpacking unixodbc (from .../unixodbc_2.2.11-16build3_i386.deb) ...
Selecting previously deselected package sun-java6-bin.
Unpacking sun-java6-bin (from .../sun-java6-bin_6-16-0ubuntu1.9.04_i386.deb) ...
sun-dlj-v1-1 license has already been accepted
Selecting previously deselected package sun-java6-jdk.
Unpacking sun-java6-jdk (from .../sun-java6-jdk_6-16-0ubuntu1.9.04_i386.deb) ...
sun-dlj-v1-1 license has already been accepted
Selecting previously deselected package gsfonts-x11.
Unpacking gsfonts-x11 (from .../gsfonts-x11_0.21_all.deb) ...
Processing triggers for doc-base ...
Processing 3 added doc-base file(s)...
Registering documents with scrollkeeper...
Processing triggers for man-db ...
Processing triggers for shared-mime-info ...
Setting up java-common (0.30ubuntu4) ...
Setting up odbcinst1debian1 (2.2.11-16build3) ...
Setting up unixodbc (2.2.11-16build3) ...
Setting up gsfonts-x11 (0.21) ...
Setting up sun-java6-bin (6-16-0ubuntu1.9.04) ...
Setting up sun-java6-jre (6-16-0ubuntu1.9.04) ...
Setting up sun-java6-jdk (6-16-0ubuntu1.9.04) ...
Processing triggers for libc6 ...
ldconfig deferred processing now taking place

During the installation, you’ll be prompted with the following window, where you have to read the “Operating System Distributor License for Java” and click on OK.

Fig: Sun Java License Terms - Click OK

Fig: Sun Java License Terms - Click OK

After reading the license terms, you’ll be prompted with the following window, where you have to agree to the “license terms” by clicking on Yes.

Fig: Accept Java JDK/JRE License Terms - Click Yes

Fig: Accept Java JDK/JRE License Terms - Click Yes

Verify the Java Installation

Finally, execute java -version and make sure Java is installed properly as shown below.

# java -version
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 26 comments… read them below or add one }

1 James October 31, 2009 at 4:45 pm

I’m looking to have Sun Java 6 Update 16 but when I install I get Sun Java 6 Update 15 not update 16
System Ubuntu Karmic 64bit

your installation says it’s update 16 not 15 any idea why???

Setting up sun-java6-bin (6-16-0ubuntu1.9.04) …
Setting up sun-java6-jre (6-16-0ubuntu1.9.04) …
Setting up sun-java6-jdk (6-16-0ubuntu1.9.04) …

2 Anthony Wang January 16, 2010 at 5:02 am

I clicked on the license term screen. But it just won’t go away.
Never get to see that screen. I also pressed “Enter” key. Doesn’t work either.
Why?
I use Ubuntu 9.04.

3 Bill Guinan January 30, 2010 at 4:56 am

@Anthony If you hadn’t figured it out, I had to press the Tab key to get focus on the field. Just Tab until is highlighted in red.

4 Ulrich January 31, 2010 at 1:05 am

@Bill Guinan THE bloody TAB key – you saved my afternoon. Thanks.

5 chris February 8, 2010 at 2:36 pm

thank you.
i’m always learning and this helped clear things up a lot.

6 rajashekar February 24, 2010 at 9:07 am

i fallowed u r steps but getting this error
rajashekar@rajashekar:~/java$ sudo apt-get install sun-java6-jdk
Reading package lists… Done
Building dependency tree
Reading state information… Done
You might want to run `apt-get -f install’ to correct these:
The following packages have unmet dependencies:
sun-java6-jdk: Depends: sun-java6-bin (= 6-16-0ubuntu1.9.04) but it is not going to be installed
sun-java6-jre: Depends: sun-java6-bin (= 6-16-0ubuntu1.9.04) but it is not going to be installed or
ia32-sun-java6-bin (= 6-16-0ubuntu1.9.04) but it is not installable
Recommends: gsfonts-x11 but it is not going to be installed
E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).

7 rajashekar February 24, 2010 at 9:24 am

sudo apt-get install htop
Reading package lists… Done
Building dependency tree
Reading state information… Done
You might want to run `apt-get -f install’ to correct these:
The following packages have unmet dependencies:
sun-java6-jre: Depends: sun-java6-bin (= 6-16-0ubuntu1.9.04) but it is not going to be installed or
ia32-sun-java6-bin (= 6-16-0ubuntu1.9.04) but it is not installable
Recommends: gsfonts-x11 but it is not going to be installed
E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
rajashekar@rajashekar:~/java$ apt -get -f install
The program ‘apt’ can be found in the following packages:
* openjdk-6-jdk
* sun-java5-jdk
* sun-java6-jdk
Try: sudo apt-get install
bash: apt: command not found
rajashekar@rajashekar:~/java$ sudo apt-get install sun-java6-jdk
Reading package lists… Done
Building dependency tree
Reading state information… Done
You might want to run `apt-get -f install’ to correct these:
The following packages have unmet dependencies:
sun-java6-jdk: Depends: sun-java6-bin (= 6-16-0ubuntu1.9.04) but it is not going to be installed
sun-java6-jre: Depends: sun-java6-bin (= 6-16-0ubuntu1.9.04) but it is not going to be installed or
ia32-sun-java6-bin (= 6-16-0ubuntu1.9.04) but it is not installable
Recommends: gsfonts-x11 but it is not going to be installed
E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
rajashekar@rajashekar:~/java$
rajashekar@rajashekar:~/java$

8 Jatin March 25, 2010 at 11:15 am

Thanx for dis article.
It is really helpful.

9 naba May 1, 2010 at 11:59 pm

when i try to install java :
root@naba-laptop:~# sudo apt-get install sun-java6-jdk
E: dpkg was interrupted, you must manually run ‘sudo dpkg –configure -a’ to correct the problem.

10 Arne September 21, 2010 at 3:53 pm

Thank you Bill for saving me from a lot of frustration. I think I tried just about every key-combo, but I never thought about pressing TAB.

11 mangal September 22, 2010 at 8:12 am

Thanks !!!!! silly TAB !

12 Tushar October 6, 2010 at 12:58 am

Can you refer where i can updated deb package for Oracle JDK?

13 dmitry February 27, 2011 at 5:38 am

@Bill Guinan Thanks for the TAB key. I’m new to Ubuntu and have been struggling for 15 minutes, until I finally found this post!

14 openallnight March 9, 2011 at 2:34 pm

Ahhhhhhh, the TAB key!!!! Thanks!

15 Fhighlander May 5, 2011 at 1:48 pm

If you just installed Ubuntu Natty i386, try apt-get update first, before user apt-cache search ^sun-jdk, and everything will just be fine =)

16 sai September 18, 2011 at 9:54 am

osho@ubuntu:~$ apt-get install sun-java6-jdk sun-java6-jre
E: Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

17 sai September 18, 2011 at 9:57 am

this is an error msg shwn in terminal while installing java. how can i solve the problem…

18 mahender September 28, 2011 at 4:39 am

how to open java frame,,,,
sothing hav to type in terminal to open editor right wats tat command

19 Anonymous October 15, 2011 at 12:24 am

where the jdk software going to be installed.I didn’t find where it is..for to set path and classpath.

20 swathi October 23, 2011 at 1:48 am

Hi sir,
Gud afrn…
I installed Ubuntu10.4 server in my system.while installing java,i got this error message.Error is : package sun-java6-jdk has no installation candidate.
Can you tell me,how to solve and how will i install java into VMware???
reply me..

21 Thyagaraj November 19, 2011 at 9:22 am

@sai: If ‘passwd’ prompts for existing password, then the root password might have already set. If you want to reset your root password, execute the below command and enter your currently logged-in password:
sudo -s

You would have switched to root, now reset the root password by ‘passwd’

@sai: All the installation and configuration should be done with root privileges. Switch to root executing the below command:
su – root
and enter the root password

If your machine is new, you might now have root password set. Set the root password by executing the below command:
passwd

Probably ‘sun-java6-jdk’ is upto the version karmic(9.10). It’s now ‘openjdk’ from 10.04 onwards. You might need the below command:

apt-get install openjdk-6-jdk openjdk-6-jre

Of-course sun-java6 can also be installed making some change sources.list.

22 Thyagaraj November 19, 2011 at 9:25 am

@Anonymous: You could find under /usr/lib/jvm/

23 Adam November 27, 2011 at 9:03 pm

Thank you so much for the screen shots. It greatly assisted me while walking a computer-phobia through the process over the phone. I cannot thank you enough.

24 mahender November 28, 2011 at 8:14 am

tankxxxxxxxx

25 tin May 15, 2012 at 2:57 am

Thanks Thyagaraj…

26 Venkateshkumar S December 2, 2013 at 11:13 am

Hi,
I am unable to lookup the sudo apt get it for java 6-jre.Could you assist me in doing manual installation,it will be good.

Leave a Comment

Previous post:

Next post: