How to install a specific version of Java on Ubuntu

Ubuntu 7.04 supports Java and by default uses the free software “gj” compiler and runtimes.

However, some applications require other versions of Java. I recently wanted to run one such application, jUploadr, and I’m writing this note on how to install other Java implementations.

jUploadr requires “a version of Sun’s JRE version 1.4.x or later.”

I ran into a few problems before I finally got Sun’s JRE installed, enough so that I will describe that experience in a separate post.

For now I’ll just describe one approach that finally worked, the key idea being you don’t want to have two different Java’s on your system. One is enough, so if you have a version other than what you need on hand, you need to remove it before installing the one you want.

Is there a Java on my computer?

To see if you have Java at hand, open a terminal and run this command:

$ which java

If it prints out the name of a file then you have a Java installed. If it prints nothing then you can proceed directly to the install step.

If there is a Java on my computer, which version is it?

Run the command:

$ java -version

If it’s the stock Ubuntu version, the output will contain “GCJ” or such.

if it’s a version from Sun you will see “Java HotSpot (TM)” in the output.

If it’s something else, you’re on your own, but I hope this post provides some tips that will help you on your journey.

How do I remove gj Java?

You can use Synaptic or the command line. If you are running Ubuntu 7.04 the following commands should work; they also give the names of the packages you want to remove using Synaptic:

$ sudo apt-get remove gcj-4.1.-base gij gij-4.1

You know you’re done when you follow the instructions provided in Is there a Java on my computer? and confirm there is no longer a Java on your machine.

How do I install Sun’s Java JRE?

First confirm you have no Java on your machine, then run the command:

$ sudo apt-get install sun-java6-jre

The apt-get may fail, reporting that it can’t find this package, in which case you need to make available some additional repositories, as described in Unofficial Ubuntu 7.04 (Feisty Fawn) Starter Guide (search for “java” on this page).

By the way during the install an editor window will pop up and you will have to arrange to find and click on the “OK” part to confirm you accept Sun’s license. (This is not the open-source version of Sun Java — more on that later in a separate post.)

Once the apt-get you should confirm that the command

$ java -version

describes a Sun JRE, as described above.

2 Comments

  1. Posted September 17, 2007 at 04:58 | Permalink | Reply

    You don’t have to remove gij.

    > man update-java-alternatives

    should tell you all you want to know about managing multiple JRE/JDK installations. 😉

  2. Posted September 26, 2007 at 18:01 | Permalink | Reply

    Dalibor was correct about not needing to remove gij. It’s also possible to install multiple versions of Sun’s JRE, including ones that haven’t been packaged yet as .deb packages.

    Note that to run Java applets in the browser you’ll want a package which is named something like sun-java6-plugin. If you do this it will install a system-wide plugin which can’t easily be overridden by individual users. I can’t remember if I’ve filed a bug yet.

    Regards,

    -james.

5 Trackbacks

  1. […] Wayward’s author ← How to install a specific version of Java on Ubuntu […]

  2. […] September 15th, 2007 · No Comments I’ve written a series of posts recently on uploading photos to Flickr. When I tried to use a tool to help do that on Ubuntu Linux I wound up having to install a Sun implementation of Java; see my post How to install a specific version of Java on Ubuntu. […]

  3. […] unknown wrote an interesting post today onHere’s a quick excerptsudo apt-get remove gcj-4.1.-base gij gij-4.1. You know you’re done when you follow the instructions provided in Is there a Java on my computer? and confirm there is no longer a Java on your machine. How do I install Sun’s Java JRE? … […]

  4. […] this: How to install a specific version of Java on Ubuntu The Wayward Word Press […]

  5. […] this: man update-java-alternatives or this: How to install a specific version of Java on Ubuntu The Wayward Word Press […]

Leave a comment

  • Pages

  • September 2007
    M T W T F S S
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
  • RSS The Wayward Word Press

  • Recent Comments

    daveshields on SPITBOL for OSX is now av…
    Russ Urquhart on SPITBOL for OSX is now av…
    Sahana’s Respo… on A brief history of Sahana by S…
    Sahana’s Respo… on A brief history of Sahana by S…
    James Murray on On being the maintainer, sole…
  • Archives

  • Blog Stats

  • Top Posts

  • Top Rated

  • Recent Posts

  • Archives

  • Top Rated