Ubuntu Linux Install Sun Java Development Kit ( JDK ) and Java Runtime Environment ( JRE )

by on February 2, 2008 · 114 comments· LAST UPDATED September 17, 2008

in , ,

Q. How do I install Sun Java Development Kit (JDK) and Java Runtime Environment (JRE) under Ubuntu Linux? It appears that there are multiple JRE installed by default under Ubuntu. How do I select and use Sun JRE only? Can you explain steps required to set the environment to run java programs or apps?

A. Ubuntu Linux 7.10 has following packages from Sun:
=> sun-java6-bin : Sun Java Runtime Environment (JRE) 6

=> sun-java6-demo : Sun Java Development Kit (JDK) 6 demos

=> sun-java6-jdk : Sun Java Development Kit (JDK) 6

=> sun-java6-jre : Sun Java Runtime Environment (JRE) 6

Install Sun Java 6

To install proprietary Java, you must have the Multiverse repository enabled. Click on System > Administration > Software Source > Select Multisource > Close
Adding the Universe and Multiverse Repositories

Open a shell prompt (terminal) and type the following to install JDK and JRE:
$ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk

Setup the default Java version

Ubuntu Linux comes with update-java-alternatives utility to updates all alternatives belonging to one runtime or development kit for the Java language. To select, Sun's JVM as provided in Ubuntu 7.10, enter:
$ sudo update-java-alternatives -s java-6-sun
You also need to edit a file called /etc/jvm. This file defines the default system JVM search order. Each JVM should list their JAVA_HOME compatible directory in this file. The default system JVM is the first one available from top to bottom. Open /etc/jvm
$ sudo vi /etc/jvm
Make sure /usr/lib/jvm/java-6-sun is added to the top of JVM list
At the end your file should read as follows:

Save and close the file.

Setup the environment variable

You also need to setup JAVA_HOME and PATH variable. Open your $HOME/.bash_profile or /etc/profile (system wide) configuration. Open your .bash_profile file:
$ vi $HOME/.bash_profile
Append following line:
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

Save and close the file.

Test your new JDK

Type the following command to display version:
$ java -version

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode) 

Try HelloWorld.java - first java program

$ vi HelloWorld.java
Append code:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");

Save and close the file. Compile HelloWorld.java and execute program by typing following two instructions:
$ javac HelloWorld.java
$ java HelloWorld


Hello, World!

Further readings:

  • Official Sun Java tutorial - The Java Tutorials are practical guides for programmers who want to use the Java programming language to create applications. They include hundreds of complete, working examples, and dozens of lessons. Groups of related lessons are organized into "trails".
  • man pages java, javac
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 114 comments… read them below or add one }

1 Miguel March 12, 2008 at 5:13 am

When I execute:
$ javac HelloWorld.java

Show me this error:
El programa «javac» puede encontrarse en los siguientes paquetes:
* jikes-sun
* jikes-sablevm
* gcj-4.2
* kaffe
* ecj
* java-gcj-compat-dev
* j2sdk1.4
* jikes-classpath
* jikes-gij
* gcj-4.1
* sun-java5-jdk
* jikes-kaffe
* sun-java6-jdk
Pruebe: sudo apt-get install
bash: javac: orden no encontrada

Thanks, any help would be greatly appreciated.


2 sagar April 4, 2012 at 7:54 am

sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk

it will solve your problem….


3 2manydependents April 28, 2012 at 10:34 pm

Oracle has taken over and Sun has set.
We are now up to ‘jre-7u4-linux-x64.tar.gz’. The repositories are not current!
I have downloaded from here:


I have extracted the archive, now what?



4 Tor March 15, 2008 at 2:49 pm


I had the same problem. I solved it by running:
sudo update-java-alternatives -s java-6-sun

You will also need to install sun-java6-jdk if you have not done that already


5 ahmed May 11, 2008 at 8:04 pm

WinRAR en Java Sun JDk 6 download


6 jose June 8, 2008 at 6:46 am

thanks. works


7 amr mohammad June 26, 2010 at 7:18 am

my friend you forget to install The Java(TM) Plug-in, Java SE 6 and if this not installed the Java will not work


8 dru June 19, 2008 at 2:12 am

$ sudo apt-get install sun-java6-bin sun-java6-jre

should be

$ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk

to solve the compile problem


9 samprsd July 29, 2010 at 12:22 pm

thanks guru


10 Pewo July 1, 2008 at 7:22 pm

thx dru (:


11 nixCraft July 1, 2008 at 8:55 pm

Thanks for the heads up. The faq has been updated.


12 pall July 3, 2008 at 8:37 am

Thanks yeah!!!! I could install java… I m not a newbie but was still facing lots of problem… and all was resolved following these simple steps religiously….


13 Thelasko August 12, 2008 at 4:18 pm

This won’t work in 64-bit.


14 yadhi August 20, 2008 at 10:55 am

I follow the instructions. but if I type
$ java -version
java version “1.5.0_14″
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode, sharing)

jdk1.5.0_14 installed at /usr/java/jdk1.5.0_14/

should I remove jdk1.5.0_14 first?



15 prasanna October 22, 2011 at 9:00 am

just remove and install following commands

sudo apt-get install java jdk6 jre6


16 John August 22, 2008 at 10:52 am


When I build the opennms-1.5.93 in Ubutu, when I entered the ./build.sh compile. I will have the following error:

java.lang.OutOfMemoryError: PermGen space

Anyone could help me ?

Thanks in advance.



17 Richard September 6, 2008 at 11:03 pm

Thanks for this. I’ve been setting up several Ubuntu laptops for students in my AP Computer Science class and this was very helpful.


18 Deepak September 19, 2008 at 11:36 am

Thanks, nice tutorial.


19 Jud September 23, 2008 at 3:51 am

Apparently I was able to install SE Runtime Environment build 1.6.0_03-b05 successfully since it shows up on my terminal window when i call it up. I still am not able to get my active window in my stock account which went away when I installed Firefox 3.01. When I was working in FF 3, I had to install the plug in to make it work. What else do I need?
Ubuntu 7.10 Firefox 3.01


20 chrond October 18, 2008 at 10:44 am

Hi, i need your help.

when i going to install some third party program,
it pop up this message:


any one can help me on this?


21 mike October 20, 2008 at 7:09 pm

Above under Setup Default Java Version, at the end it says to save and close the file. How do you save? I can’t find a command for ‘save’.


22 mfragin October 21, 2008 at 1:02 am


You can also use the nano editor, which may be easier for you.

But, if you’re using vi/vim:


will write the file and exit it.


23 John glenn November 24, 2008 at 4:39 am

I am a beginner,I am having a problem in doing the following steps :

You also need to edit a file called /etc/jvm. This file defines the default system JVM search order. Each JVM should list their JAVA_HOME compatible directory in this file. The default system JVM is the first one available from top to bottom. Open /etc/jvm
$ sudo vi /etc/jvm
Make sure /usr/lib/jvm/java-6-sun is added to the top of JVM list
At the end your file should read as follows:


24 John glenn November 25, 2008 at 6:51 am

I had done all the steps in which i am facing problem , Hello world program works nicely but when i run the program of classes I am getting the error that is :

Caused by: java.lang.ClassNotFoundException: Classes
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

PLese help me


25 Cyclotron December 18, 2008 at 7:25 am

Am now internet banking using firefox and my bank’s java dependent website, thanks.


26 JBusse December 27, 2008 at 8:34 pm

very helpful, all problems around “jaolt” are solved with this entry


27 JP Grace January 22, 2009 at 5:25 am

Thanks for the great writeup! This is exactly what I was looking for and I was up and running in no time.


28 Niels February 4, 2009 at 10:03 am

Hi, for a course I have to use java again and I was looking for a quick installation guide and yours did the trick on Ubuntu 8.10! Thanks


29 nikhil ranjan February 8, 2009 at 12:56 pm

i followed the instruction but i m not able install jdk in linux..
plse help me….
i m


30 Sebastian February 14, 2009 at 7:43 am

:~$ sudo apt-get install sun-java5-jdk
[sudo] password for sebastian:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.

Since you only requested a single operation it is extremely likely that
the package is simply not installable and a bug report against
that package should be filed.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
sun-java5-jdk: Depends: sun-java5-demo (= 1.5.0-16-2ubuntu2) but it is not going to be installed
Depends: sun-java5-jre (= 1.5.0-16-2ubuntu2) but it is not going to be installed
E: Broken packages

any ideas why this can’t be done?


31 ShireFolk March 23, 2009 at 11:56 am

Thanks pal!


32 Ejaz March 24, 2009 at 7:38 am

This is very helpful.


33 sunil April 14, 2009 at 11:15 am

i am try but i am not able to install jdk so please help me


34 hero12 April 17, 2009 at 5:02 pm

I was having trouble with the /etc/jvm part, so I just tried running one of my own java programs and they seemed to work fine.


35 vani April 23, 2009 at 10:35 am

jee@jee-desktop:~$ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
E: dpkg was interrupted, you must manually run ‘dpkg –configure -a’ to correct the problem.
anyone can help me.After i installed java in ubuntu8.04,i got this error.


36 Moonlight May 1, 2009 at 10:31 am

thanks a lot these informations are very helpfull=)I solved completly my problems about that…


37 eprue May 21, 2009 at 6:55 am

Thanks a lot for the post! Anything that’s not config/make/make install is a bit confusing to me — Ubuntu’s like Windows with less-slick graphics :) Anyway, no religious wars — your post was *really* helpful.


38 Romel May 30, 2009 at 8:07 am

Thanks for your nice nice Article.


39 Ove June 10, 2009 at 3:13 am

Plase help me I’m having same as VANI.Now I can not able to install any soft in my Ubuntu.Please PLEASE help me


40 Guntur July 2, 2009 at 5:19 am

thanks… helpfull!!!!


41 Steve Cohen July 2, 2009 at 9:10 pm

Why is the Ubuntu multiverse repository for Sun-JDK 1.6 only on 1.6.0_07 while Sun says it’s up to 1.6.0_14?


42 tpcool July 16, 2009 at 10:14 pm

Thanks very helpful


43 chaudhari mohisn July 25, 2009 at 2:45 pm

Why is the Ubuntu multiverse repository for Sun-JDK 1.6 only on 1.6.0_07 while Sun says it’s up to 1.6.0_14?


44 chaudhari mohisn July 25, 2009 at 2:47 pm

thats vary nice


45 rubson August 3, 2009 at 4:29 am

step by step
java sun it’s work !


46 Tynen August 5, 2009 at 10:51 pm

Thank you. :)


47 sabu August 8, 2009 at 3:58 am

i see instal the java instructin .that methord folow.cannot instal java in ubuntu 8.04 lts.please help me


48 Neal August 16, 2009 at 8:39 pm

Excellent – concise, accurate and easy. Thank you.


49 sabu August 24, 2009 at 12:20 pm

thank u for previous information.
i install some software in way to terminal.that time i see dpkg error i ubuntu 8.04.I can’t install softwares.
please help me.


50 alves September 7, 2009 at 1:58 pm

I am facing same problem as vani face.
help me out


51 ayub September 14, 2009 at 10:30 am

when i input the root password on the terminal i get “sorry try again” HELP


52 Mike September 29, 2009 at 8:38 pm

I have done the steps and it all works but I cant get Scanner working when I write code anyone got any idea why not.


53 Aris Boch November 1, 2009 at 10:15 am

When i want to run a java prog any more sophisticated than hello world or similar, the jvm gives me the following:
baruch@baruch-laptop:~/jdownloader$ java -jar jdupdate.jar
Exception in thread “main” java.lang.NoClassDefFoundError: jd.update.Main
at java.lang.Class.initializeClass(libgcj.so.90)
Caused by: java.lang.ClassNotFoundException: com.sun.java.swing.plaf.windows.WindowsLookAndFeel not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:jdupdate.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.90)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.Class.forName(libgcj.so.90)
at java.lang.Class.initializeClass(libgcj.so.90)
What is wrong with my current java installation (i have installed an parallel one, it worked like a charm). Does anybody know how to solve this problem? And how to set the parallelly installed jvm to be the standard one? TIA.


54 nixCraft November 1, 2009 at 10:37 am

You are using GNU java. Install Sun JAVA and switch to it.


55 Aris Boch November 1, 2009 at 11:00 am

I have installed Sun java. How to “switch”? TIA.


56 nixCraft November 1, 2009 at 12:06 pm

Run update-java-alternatives -l to all installed java versions:
update-java-alternatives -l
Set it to Sun java
update-java-alternatives -s java-6-sun
Verify it:
java -version


57 Aris Boch November 1, 2009 at 12:15 pm

Works! Java VM ist alive and kicking again:) Thx a lot!!!!


58 anon November 22, 2009 at 6:45 pm

MicroSoft has nothing to worry about.
I thought I would try Ubuntu on an old computer.
I got Ubuntu 9.1 installed and running.
Then I just spent 5 frustrating hours TRYING to install Java jdk on Ubuntu 9.1. WTF!!!
Monday is trash day. That old computer with Ubuntu 9.1 Will be in the pile.


59 Henry James November 24, 2009 at 3:57 am

Remember to set “JAVA_JDK” for intelliIDE to run. Also make sure it’s not using openjava jdk which may have installed if you installed icetea jre in firefox, then you’re JRE and JDK may have switched. Remember to reset your JAVA_HOME env (which java install never does for you) if you updated and they’ve decided to break your symlink. Updated Ubuntu? No problem someone will have decided that .bash_profile is now to be called .bachrc, why you ask? God knows – but I’m sure they will change it back again to piss you off on the next update. Java would be great if it wasn’t for all the moronic bullshit you have to configure and their insane versioning… oh yeah it’s JEE now with Java6 that I work with not 1.6!!. Couple this with Linux vendors stupid changing of config files with every release and you’ve got one giant mess.


60 Asterios November 30, 2009 at 11:33 pm

Hello. Sorry for my english but i am not good in this language. I have a problem. I compile a java file which has this class: class Pan extends java.applet.Applet implements Runnable { …

but i have many warnings like this : warning: [deprecation] size() in java.awt.Component has been deprecated —- x1 = size().width
I make compile : javac name.java -Xlint

Is anybody who can help me please????

Thank you.


61 Nick December 1, 2009 at 12:44 am

Hi, most everything went well except when I did:

$ sudo update-java-alternatives -s java-6-sun
update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-alternatives: error: no alternatives for pluginappletviewer.
update-alternatives: error: no alternatives for xulrunner-1.9-javaplugin.so.
update-alternatives: error: no alternatives for xulrunner-1.9-javaplugin.so.

Everything in the write up works though, will this be a problem with other things you think? I am not sure what this line is supposed to accomplish. Can you give me some insight on that? Thanks, much!


62 ximing April 21, 2011 at 6:24 pm

sudo apt-get install sun-java6-plugin


63 sarah December 2, 2009 at 10:40 am

install java hotspot


64 lee December 6, 2009 at 9:19 pm

i got a problem when i install sun java.
here is errors.
how can i fix it?
apt-get install sun-java6-jre
E: dpkg was interrupted, you must manually run ‘dpkg –configure -a’ to correct the problem.


65 prince December 16, 2009 at 1:41 am

prince@THOTTATHIL:~$ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
[sudo] password for prince:
E: dpkg was interrupted, you must manually run ‘sudo dpkg –configure -a’ to correct the problem.
how to solve this ?


66 prince December 16, 2009 at 2:21 am

i solved the above but new problem is i dont know how to do sudo vi /etc/jvm
wen i entered this command to terminal and the following /usr/lib/jvm/java-6-sun
got error E486: pattern not found: usr
pls help me


67 jhang February 5, 2010 at 7:20 am

when i’m trying to install java in my ubuntu these message appeared
jhang@ubuntu:~$ sudo apt-get install sun-java6-jdk
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Couldn’t find package sun-java6-jdk

i could not compile my java source code!! HELP PLEASE!!!


68 mobai February 10, 2010 at 2:34 am

use this way,i have successed install jdk on my ubuntu9.10.
many tks!


69 Spaulding Smails February 12, 2010 at 10:02 am

@ jhang

Try sudo apt-get install default-jdk. This installed the open jdk which is (afaik) just sun java with a friendlier foss license.


70 jhang February 17, 2010 at 6:47 am

i could not play my videos and music on my ubuntu.. what’s the better way to enable me to do so????


71 shiplu February 26, 2010 at 11:35 pm

after installing jdk and jre
next instruction are not working properly in my ubuntu(9.04)
please help …..


72 Russell March 3, 2010 at 4:13 pm

Thank you, Vivek. As a newbie to Ubuntu, installing and configuring the individual components has been very frustrating to learn. Your post was clear and precise, allowing me to get java up and running (after numerous failed attempts).

– Russell


73 suhas March 6, 2010 at 1:31 pm

@jhang, for your earlier problem try sudo apt-get update.
then to play audio/videos u need to install players.
for tht u can try sudo apt-get install vlc mplayer gmplayer


74 Imran Lakhani March 8, 2010 at 10:22 am

thanks man,
quite helpful :)


75 jessi March 12, 2010 at 5:47 pm

when i used this command in terminal $ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk ia getting error as
E: Couldn’t find package sun-java6-bin
i am new to ubuntu can any one help me out


76 Marcos March 13, 2010 at 12:16 am

Thanks, Very good Tutorial!


77 jatin March 19, 2010 at 7:18 pm

when i used this command in terminal $ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk ia getting error as
E: Couldn’t find package sun-java6-bin
i am new to ubuntu can any one help me out


78 Chandra Shekhar May 19, 2010 at 11:06 am

sudo apt-get update
and than your command its done


79 Scott March 21, 2010 at 4:05 pm

You can download the Sun JDK from http://java.sun.com.

Once downloaded, set it executable, expand it and copy it to your desired directory. I put mine in /opt. I have /opt/jdk1.6.0_18 now.

Next I created a symbolic link for convenience using sudo ln -s /opt/jdk1.6.0_18 /opt/java

In your home directory, create or edit a file called .bash_profile (the “.” (dot) is important) and add the following:

export JAVA_HOME

Log out and back in to set the environment variables or alternatively you can:

source ~/.bash_profile

Once done you should be able to type “java -version” and see

java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) 64-Bit Server VM (build 16.0-b13, mixed mode)

If you don’t it is probably a type somewhere. The commands can help troubleshoot problems.
which java to see which executable you are calling.
echo $PATH will allow you to check your path variable.
echo $JAVA_HOME shows your java home environment variable

Good Luck,


80 Doreen A. Clemons April 22, 2010 at 1:46 am

Much obliged for the help! Somehow I was under the impression that Sun’s JDK had been “rebranded” and OpenJDK until I saw it labeled as “IcedTea” in Eclipse and NetBeans and figured out what was going on.

After installing the “real” JDK from Sun, NetBeans picked up on it after the next launch. Eclipse did not, so anyone using Eclipse will have to manually set that.

The annoying thing was that code that I knew darned well was working broke in Eclipse and NetBeans and only started working again after the switch in JDKs. Sigh…

Again, thanks so much for the help! Wish I’d seen this sooner!


Doreen Clemons


81 Eric May 1, 2010 at 3:23 pm

This is my problem, and ideas?

eric@jurgen:~$ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
Reading package lists… Done
Building dependency tree
Reading state information… Done
sun-java6-bin is already the newest version.
sun-java6-bin set to manually installed.
sun-java6-jre is already the newest version.
sun-java6-jre set to manually installed.
Package sun-java6-jdk is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package sun-java6-jdk has no installation candidate


82 Shwetav Agarwal May 2, 2010 at 12:04 pm

The following changes are applicable for installing Sun JDK in Ubuntu 10.04 Lucid Lynx:
In order to enable the repository for downloading the packages for Sun JDK execute:
sudo add-apt-repository “deb http://archive.canonical.com/ lucid partner”
sudo apt-get update

NOTE: Be mindful of the double-quotes in case you are doing a copy-paste from the webpage.


83 zucaritas May 14, 2010 at 1:50 pm

Hey, thanx 4 the tut. Although you might want to add that for ubuntu 10.04 you have to enable partener repository on the “Other software” tab at the Software sources. Just that will do it. Then apt-get the packages.
Thank you


84 lilyzue May 15, 2010 at 1:30 am

thanks for the help! It works for Ubuntu 10.04 ;D


85 Júlio Cézar May 17, 2010 at 2:37 pm

Thanks, helped so much!


86 Ana Juaristi June 7, 2010 at 3:34 pm


I had just the problem mentioned
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package sun-java6-jdk has no installation candidate

I tried the solution given:
sudo add-apt-repository “deb http://archive.canonical.com/ lucid partner”
sudo apt-get update

But it did not work for me since, after that I obtained the error:
E:Línea 57 mal formada en lista de fuentes /etc/apt/sources.list (análisis de dist),
Nevermind, it gave me the clue, so…
I solved like this:
sudo gedit /etc/apt/sources.list
Delete the line that it is causing the mal formed line error.
Find the lines where canonical repositories are commented with #
Uncomment lines.
Save file
Execute again
sudo apt-get update

Try again installing with
sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk

Thank you everybody


87 deadsea June 24, 2010 at 7:01 am

thanks, it’s work for me


88 newbiejava October 31, 2010 at 4:24 pm

cool! thanx buddy!


89 Bidve June 14, 2010 at 5:02 pm

Thanku so much………..


90 zerc July 9, 2010 at 9:00 am


thx a good tutorial ;-)


91 Jacqueline August 15, 2010 at 2:19 am

I have been trying these source codes and browsing forums and the ubuntu community for three days and I cannot get this to work. I get this:
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Couldn’t find package sun-java6-bin

And when I go to software center I get this:
Sorry, “Sun Java 6.0 plug-in” is not available for this computer (amd64).

I am new to Linux and I am also not real tech savvy. Can anyone please help me with this?


92 Abhinav September 2, 2010 at 8:53 am

$ javac Hello.java

$ java Hello
Exception in thread “main” java.lang.NoClassDefFoundError: Hello
Caused by: java.lang.ClassNotFoundException: Hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

$ java -version
java version “1.6.0_20″
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)

I have installed SUN JDK and JRE and have set etc file and bash file too.


93 Serge October 5, 2010 at 10:54 pm

Excellent step by step guide. There’s one little detail missing which isn’t a big deal for advanced users but I can see beginners stumbling on. After you modify .bashrc with the $JAVA_HOME and PATH changes, you should let readers know to run:
source ~/.bashrc

or else the changes won’t take affect.



94 sara October 13, 2010 at 9:37 am

E: Could not get lock /var/lib/dpkg/lock – open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
what is this error ?:((


95 Mnemosyne October 15, 2010 at 10:17 am

It works : ) HUGA THXXXXXX for this wonderful tutorial, honestly I’ve been all over the Internet trying to find someone who explained this in English, and then you came. Thank You


96 adilya November 23, 2010 at 6:15 am

Thanks!!! Helped a lot!!!


97 Aqib December 5, 2010 at 5:48 pm

Most of this worked for me but I got stuck when setting the path variables, what you actually have to do it run these two lines in the terminal:

export JAVA_HOME=/usr/java
export PATH=$PATH:$JAVA_HOME/bin

Obviously change “/usr/java” to wherever java is installed.


98 Dwi Cahyo December 10, 2010 at 11:21 pm

thanks, i just want to show where I to place my java PATH.
thank very much


99 Umid December 14, 2010 at 7:25 am

I’m configuring my JDK1.6.0_23 on Ubuntu 10.04 as follows…

Edit profile file:
sudo nano ~/.profile

add these lines:
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_23
export PATH=$JAVA_HOME/bin:$PATH

Apply profile changes:
. .profile

Check JAVA_HOME environment variable:

Configure alternatives for java, javac, jar
sudo update-alternatives –install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_23/bin/java 100
sudo update-alternatives –install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_23/bin/javac 100
sudo update-alternatives –install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_23/bin/jar 100

Check java, javac version:
java -version

java version “1.6.0_23″
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) Server VM (build 19.0-b09, mixed mode)

javac -version

javac 1.6.0_23


100 yorgos December 15, 2010 at 7:45 am

Hello good people,
first sorry for any mistakes in language(i am not native :-) ).
Very good instructions, still i could use some help.
I am running Ubuntu 10.04.1 LTS and i have to install Java SE 6.0 JDK release from Oracle’s Sun. Also i must “”Install the JDK, typically in the /opt directory, i.e. /opt/java. and Install the JRE in a different directory (usually the default directory) or you may experience run-time issues””. I have to install it this way because the installation manual of Sakai says so “http://wiki.sakaiproject.org/display/DOC/Sakai+2.7″
i am almost a newbie. Any help please???


101 Gabriel December 28, 2010 at 4:56 pm

Pls how can i install java on ubuntu 10.10
I’m a new user of ubuntu and almost know practically nothing about it


102 shailendra February 9, 2011 at 6:35 am

Hi All,

I tried all possible combination to install java at Generic Linux 2.6 version.

1. Tried changing all Profile/Bashrc etc…. but not able to remvoe error

When i type comman : java -version

VM initilization error : Java.lang.Object class not found



103 bond February 17, 2011 at 12:31 pm


here those who face problem configure sun-java6-jre terminal inside it
to press ok just press ctrl+o and u r ready to install.


104 sathish March 1, 2011 at 11:39 am

E: dpkg was interrupted, you must manually run ‘sudo dpkg –configure -a’ to correct the problem.
E: _cache->open() failed, please report.

i am using ubuntu 10.04 i need to install java jdk kit.
i went to system-> administrative->software sources-> then gave the required package installation
while installing package i am getting above mentioned error..
can u help me.. anyone


105 Madhawa March 28, 2011 at 8:02 am

Hey, thank you so much. Blog about “vim” if you can.


106 Ashraf April 24, 2011 at 5:57 am

Awesome Step by Step Tutorial…
Moreover the comments do help a lot more…
Keep up good work.

Thanks for the tutorials vivek…


107 Mohan April 26, 2011 at 6:13 am

Hello friends,
i also want to install JDK 1.6 to run my Netbeans IDE,but I encountererd the following error,when i type sudo apt-get install sun-java6-jdk :

Package sun-java6-jdk is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package sun-java6-jdk has no installation candidate


108 Nuwan Arambage May 7, 2011 at 4:38 pm

great tutorial……..it helps me a lot…….
thanks very much sharing knowledge


109 Maybe May 20, 2011 at 3:35 am

i have some problems. i could n’t use sctp library although i have installed jdk7.

Plz. Thank in adavance.

Best regards,


110 Nitheesh R July 4, 2011 at 5:12 am

How to set JAVA_HOME variable in Ubuntu:-

‘sudo’ open up /etc/bash.bashrc and add the following to the end of the file. (NOTE: Set the java path to whatever the actual path is on your environment if it does not match /usr/lib/jvm/java)

export JAVA_HOME
export PATH

you must reboot, try running the following:

$ echo $JAVA_HOME
echo $PATH
[probably lots of paths]:/usr/lib/jvm/java/bin

This is how problem is solved.



111 Kesavan August 30, 2011 at 11:48 am

Thanks Buddy. It worked for me.


112 Kevin October 17, 2011 at 11:18 am

I use an application regularly that relies on Java. Their support department insists you update to the latest and greatest version from Sun (will NOT help w/ support issues unless you are using newest Sun sanctioned version). I’m using Kubuntu, and have noticed that it is usually 1-2 versions behind (e.g. today I’m running 1.6.0-26, that is the most up-to-date version available through Apt. When I go to the Java website, it verifies I’m running 1.6.0-26, and says an update is available (0-27!))
Is there a way to install a newer/different version of Java from Sun w/o using Apt? Can I download a tarball and configure Kubuntu to use the newer downloaded version vs. the officially sanctioned version provided through Apt?
Thanks for the help (this has been a nagging problem since v. 0-15)


113 abbasalim February 13, 2013 at 2:06 pm

benam khoda
i have a problem in execute HelloWorld.class
Error: Could not find or load main class .home.armo372.Desktop.HelloWorld
im sorry for bad speak engelish :(


114 Ajay Singh June 4, 2013 at 7:58 am

while i m running my application on ubuntu 11.10 geting this error after successful compilation
android projects$ javac AjaySingh.java //compile successfully
android projects$ java AjaySingh //while running getting below error
error: Class names, ‘AjaySingh’, are only accepted if annotation processing is explicitly requested
1 error
if someone have any answer plz reply at my email


Leave a Comment

Tagged as: , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: