≡ Menu

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

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
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 114 comments… add one }

  • Miguel March 12, 2008, 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.

    • sagar April 4, 2012, 7:54 am

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

      it will solve your problem….

    • 2manydependents April 28, 2012, 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:

      http://www.oracle.com/technetwork/java/javase/downloads/jre-7u4-download-1591157.html
      

      I have extracted the archive, now what?

      Lil’lost

  • Tor March 15, 2008, 2:49 pm

    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

  • ahmed May 11, 2008, 8:04 pm

    WinRAR en Java Sun JDk 6 download

  • jose June 8, 2008, 6:46 am

    thanks. works

    • amr mohammad June 26, 2010, 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

  • dru June 19, 2008, 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

    • samprsd July 29, 2010, 12:22 pm

      thanks guru

  • Pewo July 1, 2008, 7:22 pm

    thx dru (:

  • nixCraft July 1, 2008, 8:55 pm

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

  • pall July 3, 2008, 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….

  • Thelasko August 12, 2008, 4:18 pm

    This won’t work in 64-bit.

  • yadhi August 20, 2008, 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?

    thx

    • prasanna October 22, 2011, 9:00 am

      just remove and install following commands

      sudo apt-get install java jdk6 jre6

  • John August 22, 2008, 10:52 am

    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

  • Richard September 6, 2008, 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.

  • Deepak September 19, 2008, 11:36 am

    Thanks, nice tutorial.

  • Jud September 23, 2008, 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

  • chrond October 18, 2008, 10:44 am

    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?

  • mike October 20, 2008, 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’.

  • mfragin October 21, 2008, 1:02 am

    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.

  • John glenn November 24, 2008, 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
    /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

  • John glenn November 25, 2008, 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

  • Cyclotron December 18, 2008, 7:25 am

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

  • JBusse December 27, 2008, 8:34 pm

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

  • JP Grace January 22, 2009, 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.

  • Niels February 4, 2009, 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

  • nikhil ranjan February 8, 2009, 12:56 pm

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

  • Sebastian February 14, 2009, 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
    sebastian@sebastian-laptop:~$

    any ideas why this can’t be done?

  • ShireFolk March 23, 2009, 11:56 am

    Thanks pal!

  • Ejaz March 24, 2009, 7:38 am

    Thanks.
    This is very helpful.

  • sunil April 14, 2009, 11:15 am

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

  • hero12 April 17, 2009, 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.

  • vani April 23, 2009, 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.

  • Moonlight May 1, 2009, 10:31 am

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

  • eprue May 21, 2009, 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.

  • Romel May 30, 2009, 8:07 am

    Thanks for your nice nice Article.

  • Ove June 10, 2009, 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

  • Guntur July 2, 2009, 5:19 am

    thanks… helpfull!!!!

  • Steve Cohen July 2, 2009, 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?

  • tpcool July 16, 2009, 10:14 pm

    Thanks very helpful

  • chaudhari mohisn July 25, 2009, 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?

  • chaudhari mohisn July 25, 2009, 2:47 pm

    thats vary nice

  • rubson August 3, 2009, 4:29 am

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

  • Tynen August 5, 2009, 10:51 pm

    Thank you. :)

  • sabu August 8, 2009, 3:58 am

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

  • Neal August 16, 2009, 8:39 pm

    Excellent – concise, accurate and easy. Thank you.

  • sabu August 24, 2009, 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.

  • alves September 7, 2009, 1:58 pm

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

  • ayub September 14, 2009, 10:30 am

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

  • Mike September 29, 2009, 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.

  • Aris Boch November 1, 2009, 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.

    • nixCraft November 1, 2009, 10:37 am

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

  • Aris Boch November 1, 2009, 11:00 am

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

  • nixCraft November 1, 2009, 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

  • Aris Boch November 1, 2009, 12:15 pm

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

  • anon November 22, 2009, 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.

  • Henry James November 24, 2009, 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.

  • Asterios November 30, 2009, 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.

  • Nick December 1, 2009, 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!

    • ximing April 21, 2011, 6:24 pm

      sudo apt-get install sun-java6-plugin

  • sarah December 2, 2009, 10:40 am

    install java hotspot

  • lee December 6, 2009, 9:19 pm

    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

  • prince December 16, 2009, 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 ?

  • prince December 16, 2009, 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

  • jhang February 5, 2010, 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!!!

  • mobai February 10, 2010, 2:34 am

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

  • Spaulding Smails February 12, 2010, 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.

  • jhang February 17, 2010, 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????

  • shiplu February 26, 2010, 11:35 pm

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

  • Russell March 3, 2010, 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

  • suhas March 6, 2010, 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

  • Imran Lakhani March 8, 2010, 10:22 am

    thanks man,
    quite helpful :)

  • jessi March 12, 2010, 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

  • Marcos March 13, 2010, 12:16 am

    Thanks, Very good Tutorial!

  • jatin March 19, 2010, 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

    • Chandra Shekhar May 19, 2010, 11:06 am

      sudo apt-get update
      and than your command its done

  • Scott March 21, 2010, 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:

    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

  • Doreen A. Clemons April 22, 2010, 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!

    Cheers,

    Doreen Clemons

  • Eric May 1, 2010, 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

  • Shwetav Agarwal May 2, 2010, 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.

  • zucaritas May 14, 2010, 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

  • lilyzue May 15, 2010, 1:30 am

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

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

    Thanks, helped so much!

  • Ana Juaristi June 7, 2010, 3:34 pm

    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

    • deadsea June 24, 2010, 7:01 am

      thanks, it’s work for me

    • newbiejava October 31, 2010, 4:24 pm

      cool! thanx buddy!

  • Bidve June 14, 2010, 5:02 pm

    Thanku so much………..

  • zerc July 9, 2010, 9:00 am

    Hi,

    thx a good tutorial ;-)

  • Jacqueline August 15, 2010, 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?

    • Abhinav September 2, 2010, 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.

  • Serge October 5, 2010, 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.

    S

  • sara October 13, 2010, 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 ?:((

  • Mnemosyne October 15, 2010, 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

  • adilya November 23, 2010, 6:15 am

    Thanks!!! Helped a lot!!!

  • Aqib December 5, 2010, 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.

  • Dwi Cahyo December 10, 2010, 11:21 pm

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

  • Umid December 14, 2010, 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:
    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

  • yorgos December 15, 2010, 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???

  • Gabriel December 28, 2010, 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

  • shailendra February 9, 2011, 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

    Thanks
    Shailendra

  • bond February 17, 2011, 12:31 pm

    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.

  • sathish March 1, 2011, 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

  • Madhawa March 28, 2011, 8:02 am

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

  • Ashraf April 24, 2011, 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…

  • Mohan April 26, 2011, 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

  • Nuwan Arambage May 7, 2011, 4:38 pm

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

  • Maybe May 20, 2011, 3:35 am

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

    Plz. Thank in adavance.

    Best regards,

  • Nitheesh R July 4, 2011, 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)

    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

  • Kesavan August 30, 2011, 11:48 am

    Thanks Buddy. It worked for me.

  • Kevin October 17, 2011, 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)

  • abbasalim February 13, 2013, 2:06 pm

    benam khoda
    HI
    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 :(

  • Ajay Singh June 4, 2013, 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
    thanks…

Leave a Comment