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

by Vivek Gite on February 2, 2008 · 109 comments

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
/usr/lib/jvm/java-6-sun
At the end your file should read as follows:
/usr/lib/jvm/java-6-sun
/usr/lib/jvm/java-gcj
/usr/lib/jvm/ia32-java-1.5.0-sun
/usr/lib/jvm/java-1.5.0-sun
/usr

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
Output:

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

Output:

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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 109 comments… read them below or add one }

1 Miguel March 12, 2008

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.

Reply

2 Tor March 15, 2008

Miguel:

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

Reply

3 ahmed May 11, 2008

WinRAR en Java Sun JDk 6 download

Reply

4 jose June 8, 2008

thanks. works

Reply

5 amr mohammad June 26, 2010

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

Reply

6 dru June 19, 2008

$ 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

Reply

7 samprsd July 29, 2010

thanks guru

Reply

8 Pewo July 1, 2008

thx dru (:

Reply

9 vivek July 1, 2008

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

Reply

10 pall July 3, 2008

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….

Reply

11 Thelasko August 12, 2008

This won’t work in 64-bit.

Reply

12 yadhi August 20, 2008

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?

thx

Reply

13 prasanna October 22, 2011

just remove and install following commands

sudo apt-get install java jdk6 jre6

Reply

14 John August 22, 2008

Hi,

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.

John

Reply

15 Richard September 6, 2008

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

Reply

16 Deepak September 19, 2008

Thanks, nice tutorial.

Reply

17 Jud September 23, 2008

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

Reply

18 chrond October 18, 2008

Hi, i need your help.

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

PLUGIN_JAVA_HOME
PLUGIN_JAVA_HOME
please set PLUGIN_JAVA_HOME

any one can help me on this?

Reply

19 mike October 20, 2008

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’.

Reply

20 mfragin October 21, 2008

mike:

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

But, if you’re using vi/vim:

:wq

will write the file and exit it.

Reply

21 John glenn November 24, 2008

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
/usr/lib/jvm/java-6-sun
At the end your file should read as follows:
/usr/lib/jvm/java-6-sun
/usr/lib/jvm/java-gcj
/usr/lib/jvm/ia32-java-1.5.0-sun
/usr/lib/jvm/java-1.5.0-sun
/usr

Reply

22 John glenn November 25, 2008

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

Reply

23 Cyclotron December 18, 2008

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

Reply

24 JBusse December 27, 2008

Hi@
very helpful, all problems around “jaolt” are solved with this entry
thx
J

Reply

25 JP Grace January 22, 2009

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

Reply

26 Niels February 4, 2009

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

Reply

27 nikhil ranjan February 8, 2009

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

Reply

28 Sebastian February 14, 2009

:~$ 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
sebastian@sebastian-laptop:~$

any ideas why this can’t be done?

Reply

29 ShireFolk March 23, 2009

Thanks pal!

Reply

30 Ejaz March 24, 2009

Thanks.
This is very helpful.

Reply

31 sunil April 14, 2009

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

Reply

32 hero12 April 17, 2009

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.

Reply

33 vani April 23, 2009

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.

Reply

34 Moonlight May 1, 2009

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

Reply

35 eprue May 21, 2009

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.

Reply

36 Romel May 30, 2009

Thanks for your nice nice Article.

Reply

37 Ove June 10, 2009

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

Reply

38 Guntur July 2, 2009

thanks… helpfull!!!!

Reply

39 Steve Cohen July 2, 2009

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?

Reply

40 tpcool July 16, 2009

Thanks very helpful

Reply

41 chaudhari mohisn July 25, 2009

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?

Reply

42 chaudhari mohisn July 25, 2009

thats vary nice

Reply

43 rubson August 3, 2009

step by step
excelent.
java sun it’s work !

Reply

44 Tynen August 5, 2009

Thank you. :)

Reply

45 sabu August 8, 2009

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

Reply

46 Neal August 16, 2009

Excellent – concise, accurate and easy. Thank you.

Reply

47 sabu August 24, 2009

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.

Reply

48 alves September 7, 2009

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

Reply

49 ayub September 14, 2009

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

Reply

50 Mike September 29, 2009

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.

Reply

51 Aris Boch November 1, 2009

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.

Reply

52 Vivek Gite November 1, 2009

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

Reply

53 Aris Boch November 1, 2009

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

Reply

54 Vivek Gite November 1, 2009

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

Reply

55 Aris Boch November 1, 2009

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

Reply

56 anon November 22, 2009

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.

Reply

57 Henry James November 24, 2009

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.

Reply

58 Asterios November 30, 2009

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.

Reply

59 Nick December 1, 2009

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!

Reply

60 ximing April 21, 2011

sudo apt-get install sun-java6-plugin

Reply

61 sarah December 2, 2009

install java hotspot

Reply

62 lee December 6, 2009

hello,everyone
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.
pls,help

Reply

63 prince December 16, 2009

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 ?

Reply

64 prince December 16, 2009

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

Reply

65 jhang February 5, 2010

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!!!

Reply

66 mobai February 10, 2010

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

Reply

67 Spaulding Smails February 12, 2010

@ jhang

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

Reply

68 jhang February 17, 2010

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

Reply

69 shiplu February 26, 2010

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

Reply

70 Russell March 3, 2010

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

Reply

71 suhas March 6, 2010

@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

Reply

72 Imran Lakhani March 8, 2010

thanks man,
quite helpful :)

Reply

73 jessi March 12, 2010

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

Reply

74 Marcos March 13, 2010

Thanks, Very good Tutorial!

Reply

75 jatin March 19, 2010

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

Reply

76 Chandra Shekhar May 19, 2010

sudo apt-get update
and than your command its done

Reply

77 Scott March 21, 2010

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:

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

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,
-Scott

Reply

78 Doreen A. Clemons April 22, 2010

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!

Cheers,

Doreen Clemons

Reply

79 Eric May 1, 2010

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

Reply

80 Shwetav Agarwal May 2, 2010

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.

Reply

81 zucaritas May 14, 2010

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

Reply

82 lilyzue May 15, 2010

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

Reply

83 Júlio Cézar May 17, 2010

Thanks, helped so much!

Reply

84 Ana Juaristi June 7, 2010

Hi:

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

Reply

85 deadsea June 24, 2010

thanks, it’s work for me

Reply

86 newbiejava October 31, 2010

cool! thanx buddy!

Reply

87 Bidve June 14, 2010

Thanku so much………..

Reply

88 zerc July 9, 2010

Hi,

thx a good tutorial ;-)

Reply

89 Jacqueline August 15, 2010

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?

Reply

90 Abhinav September 2, 2010

$ 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.

Reply

91 Serge October 5, 2010

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.

S

Reply

92 sara October 13, 2010

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 ?:((

Reply

93 Mnemosyne October 15, 2010

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

Reply

94 adilya November 23, 2010

Thanks!!! Helped a lot!!!

Reply

95 Aqib December 5, 2010

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.

Reply

96 Dwi Cahyo December 10, 2010

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

Reply

97 Umid December 14, 2010

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:
echo $JAVA_HOME
OUTPUT:
/usr/lib/jvm/jdk1.6.0_23

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

OUTPUT:
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

OUTPUT:
javac 1.6.0_23

Reply

98 Gabriel December 28, 2010

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

Reply

99 shailendra February 9, 2011

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

Thanks
Shailendra

Reply

100 bond February 17, 2011

Thanks,
but

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.

Reply

101 sathish March 1, 2011

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

Reply

102 Madhawa March 28, 2011

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

Reply

103 Ashraf April 24, 2011

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

Thanks for the tutorials vivek…

Reply

104 Mohan April 26, 2011

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

Reply

105 Nuwan Arambage May 7, 2011

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

Reply

106 Maybe May 20, 2011

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

Plz. Thank in adavance.

Best regards,

Reply

107 Nitheesh R July 4, 2011

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)

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

you must reboot, try running the following:

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

This is how problem is solved.

Nitheesh

Reply

108 Kesavan August 30, 2011

Thanks Buddy. It worked for me.

Reply

109 Kevin October 17, 2011

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)

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 15 + 5 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the simple math so we know that you are a human and not a script.




Previous post:

Next post: