Sunday, March 13, 2011

Java on Ubuntu

As a Java developer like me, it is very common for us to always install Java in our box. But I had this experience in Ubuntu 10.10 that I cannot install Java from the terminal. Ubuntu Software Center offers alternatives like OpenJDK which is very easy to install, but if you're like me who preferred the official JDK (from Sun/Oracle) then you'll probably stressed yourself in finding ways to install the official one and ignore the alternative despite its compatibility and ease during installation.
Trying the following terminal command:
sudo apt-get install sun-java-jdk sun-java-jre sun-java-bin

will just give you a message:
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


For an unknown reason, the sun-java-jdk are not yet available in the partner repositories. Because of that, what I did was I simply added the Java ppa (Personal Package Archives) in the repository then updated it. To do this, use the following command:
sudo add-apt-repository ppa:sun-java-community-team/sun-java6
sudo apt-get update

After you update your Ubuntu repositories, you can now proceed with the installation of Java in your box.
Use the following command:
sudo apt-get install sun-java-jdk sun-java-jre sun-java-bin


There you go! You have now JDK on your Ubuntu box, you can now install Java IDE such as Eclipse or Netbeans, or installing nothing if you prefer of not using any IDEs.

Additional note:
If you experience problems during Java installation after you update your repositories, like the error message below:
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Try first the recommended command by Ubuntu first:
sudo apt-get update --fix-missing

If the problem still didn't fixed, simply modify your Software Sources. See the image below:


*Originally, Software Sources can be found in System>Administration>Software Sources, but in Ubuntu 10.04 and 10.10, it was removed on its default location. To add this, just right-click on System menu from the panel then select "Edit Menus". Select "Administration" then check Software Sources. See example below:


That's all! Enjoy! :D

1 comment:

  1. I have a question but it's not regarding java. I'm a newbie in ubuntu and I'm currently using 10.10. There is a prompt in the Update Manager that says 'upgrade to 11.04 is available'. However, if I click upgrade, will all the codecs and other libraries previously installed be nullified (i.e., .mp3, .avi, java, skype etc.)? What will happen to the files and documents I have? Is upgrading to a newer version similar to reformatting in windows? Thank you!

    ReplyDelete