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

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 114 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
114 comments… add one
  • Miguel Mar 12, 2008 @ 5:13

    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 Apr 4, 2012 @ 7:54

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

      it will solve your problem….

    • 2manydependents Apr 28, 2012 @ 22:34

      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?


  • Tor Mar 15, 2008 @ 14:49


    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 @ 20:04

    WinRAR en Java Sun JDk 6 download

  • jose Jun 8, 2008 @ 6:46

    thanks. works

    • amr mohammad Jun 26, 2010 @ 7:18

      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 Jun 19, 2008 @ 2:12

    $ 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 Jul 29, 2010 @ 12:22

      thanks guru

  • Pewo Jul 1, 2008 @ 19:22

    thx dru (:

  • 🐧 nixCraft Jul 1, 2008 @ 20:55

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

  • pall Jul 3, 2008 @ 8:37

    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 Aug 12, 2008 @ 16:18

    This won’t work in 64-bit.

  • yadhi Aug 20, 2008 @ 10:55

    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?


    • prasanna Oct 22, 2011 @ 9:00

      just remove and install following commands

      sudo apt-get install java jdk6 jre6

  • John Aug 22, 2008 @ 10:52


    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.


  • Richard Sep 6, 2008 @ 23:03

    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 Sep 19, 2008 @ 11:36

    Thanks, nice tutorial.

  • Jud Sep 23, 2008 @ 3:51

    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 Oct 18, 2008 @ 10:44

    Hi, i need your help.

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

    please set PLUGIN_JAVA_HOME

    any one can help me on this?

  • mike Oct 20, 2008 @ 19:09

    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 Oct 21, 2008 @ 1:02


    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.

  • John glenn Nov 24, 2008 @ 4:39

    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:

  • John glenn Nov 25, 2008 @ 6:51

    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 Dec 18, 2008 @ 7:25

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

  • JBusse Dec 27, 2008 @ 20:34

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

  • JP Grace Jan 22, 2009 @ 5:25

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

  • Niels Feb 4, 2009 @ 10:03

    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 Feb 8, 2009 @ 12:56

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

  • Sebastian Feb 14, 2009 @ 7:43

    :~$ 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?

  • ShireFolk Mar 23, 2009 @ 11:56

    Thanks pal!

  • Ejaz Mar 24, 2009 @ 7:38

    This is very helpful.

  • sunil Apr 14, 2009 @ 11:15

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

  • hero12 Apr 17, 2009 @ 17:02

    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 Apr 23, 2009 @ 10:35

    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

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

  • eprue May 21, 2009 @ 6:55

    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

    Thanks for your nice nice Article.

  • Ove Jun 10, 2009 @ 3:13

    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 Jul 2, 2009 @ 5:19

    thanks… helpfull!!!!

  • Steve Cohen Jul 2, 2009 @ 21:10

    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 Jul 16, 2009 @ 22:14

    Thanks very helpful

  • chaudhari mohisn Jul 25, 2009 @ 14:45

    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 Jul 25, 2009 @ 14:47

    thats vary nice

  • rubson Aug 3, 2009 @ 4:29

    step by step
    java sun it’s work !

  • Tynen Aug 5, 2009 @ 22:51

    Thank you. :)

  • sabu Aug 8, 2009 @ 3:58

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

  • Neal Aug 16, 2009 @ 20:39

    Excellent – concise, accurate and easy. Thank you.

  • sabu Aug 24, 2009 @ 12:20

    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 Sep 7, 2009 @ 13:58

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

  • ayub Sep 14, 2009 @ 10:30

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

  • Mike Sep 29, 2009 @ 20:38

    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 Nov 1, 2009 @ 10:15

    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 Nov 1, 2009 @ 10:37

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

  • Aris Boch Nov 1, 2009 @ 11:00

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

  • 🐧 nixCraft Nov 1, 2009 @ 12:06

    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 Nov 1, 2009 @ 12:15

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

  • anon Nov 22, 2009 @ 18:45

    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 Nov 24, 2009 @ 3:57

    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 Nov 30, 2009 @ 23:33

    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 Dec 1, 2009 @ 0:44

    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 Apr 21, 2011 @ 18:24

      sudo apt-get install sun-java6-plugin

  • sarah Dec 2, 2009 @ 10:40

    install java hotspot

  • lee Dec 6, 2009 @ 21:19

    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.

  • prince Dec 16, 2009 @ 1:41

    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 Dec 16, 2009 @ 2:21

    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 Feb 5, 2010 @ 7:20

    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 Feb 10, 2010 @ 2:34

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

  • Spaulding Smails Feb 12, 2010 @ 10:02

    @ 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 Feb 17, 2010 @ 6:47

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

  • shiplu Feb 26, 2010 @ 23:35

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

  • Russell Mar 3, 2010 @ 16:13

    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 Mar 6, 2010 @ 13:31

    @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 Mar 8, 2010 @ 10:22

    thanks man,
    quite helpful :)

  • jessi Mar 12, 2010 @ 17:47

    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 Mar 13, 2010 @ 0:16

    Thanks, Very good Tutorial!

  • jatin Mar 19, 2010 @ 19:18

    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

      sudo apt-get update
      and than your command its done

  • Scott Mar 21, 2010 @ 16:05

    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,

  • Doreen A. Clemons Apr 22, 2010 @ 1:46

    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

  • Eric May 1, 2010 @ 15:23

    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

    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 @ 13:50

    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

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

  • Júlio Cézar May 17, 2010 @ 14:37

    Thanks, helped so much!

  • Ana Juaristi Jun 7, 2010 @ 15:34


    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 Jun 24, 2010 @ 7:01

      thanks, it’s work for me

    • newbiejava Oct 31, 2010 @ 16:24

      cool! thanx buddy!

  • Bidve Jun 14, 2010 @ 17:02

    Thanku so much………..

  • zerc Jul 9, 2010 @ 9:00


    thx a good tutorial ;-)

  • Jacqueline Aug 15, 2010 @ 2:19

    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 Sep 2, 2010 @ 8:53

      $ 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 Oct 5, 2010 @ 22:54

    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.


  • sara Oct 13, 2010 @ 9:37

    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 Oct 15, 2010 @ 10:17

    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 Nov 23, 2010 @ 6:15

    Thanks!!! Helped a lot!!!

  • Aqib Dec 5, 2010 @ 17:48

    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 Dec 10, 2010 @ 23:21

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

  • Umid Dec 14, 2010 @ 7:25

    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

    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

  • yorgos Dec 15, 2010 @ 7:45

    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 Dec 28, 2010 @ 16:56

    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 Feb 9, 2011 @ 6:35

    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


  • bond Feb 17, 2011 @ 12:31


    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 Mar 1, 2011 @ 11:39

    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 Mar 28, 2011 @ 8:02

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

  • Ashraf Apr 24, 2011 @ 5:57

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

    Thanks for the tutorials vivek…

  • Mohan Apr 26, 2011 @ 6:13

    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 @ 16:38

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

  • Maybe May 20, 2011 @ 3:35

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

    Plz. Thank in adavance.

    Best regards,

  • Nitheesh R Jul 4, 2011 @ 5:12

    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.


  • Kesavan Aug 30, 2011 @ 11:48

    Thanks Buddy. It worked for me.

  • Kevin Oct 17, 2011 @ 11:18

    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 Feb 13, 2013 @ 14:06

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

  • Ajay Singh Jun 4, 2013 @ 7:58

    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 Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz