ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Install Sun Java Alternative in Ubuntu

Updated on March 13, 2014

There are variety of ways you can have Java (JDK) installed on your Ubuntu. You can stick with the default OpenJDK (openjdk-6-jdk package in Ubuntu repository) or install Sun (it’s Oracle now actually) Java (sun-java6-jdk package) from Ubuntu’s multiverse repository using package manager (apt-get). Usually they are couple of revisions behind official Sun JDK releases, but most of the time it is enough.

Sometimes however you want to (or need to) install the latest version of Java. Downloading and unpacking it is quite easy. However making it the default Java installation in your system is harder. You can of course manually change all or part of the symbolic links pointing to java commands, but it just doesn’t feel like the proper way to do it. Why not use the update-java-alternatives command that makes changes system-wide and allows to easily change the default distribution at any time.
Unfortunately update-java-alternatives knows nothing about your manually downloaded JDK, so below are steps that adds new alternative to the registry of JDKs available.

Notice that all the commands presented here should be pasted as one line in your terminal (even if they are split by browser).

Install Java step by step

  1. Download JDK from Sun/Oracle. Choose bin version (not rpm). The file would be in form of jdk-version-platform.bin (in my case it was: jdk-6u25-linux-x64.bin )
  2. Add execution rights to the downloaded file

    $ chmod u+x jdk-6u25-linux-x64.bin

  3. Execute script. It will unpack its content to current directory (press Enter when asked)

    $ ./jdk-6u25-linux-x64.bin

    Now you should have directory i.e. jdk1.6.0_25/ with JDK files in it.
  4. Move unpacked JDK to final destination e.g. /opt/java/

    $ sudo mv jdk1.6.0_25/ /opt/java/

  5. Create symbolic link to that directory that will represent this JDK in general regardless current version. It will ease the future updates of JDK. I can any name. I have chosen sun-java6-manual

    $ cd /opt/java/
    $ sudo ln -s jdk1.6.0_25 sun-java6-manual

  6. Now create another symbolic link in /usr/lib/jvm pointing to previous one.

    $ cd /usr/lib/jvm/
    $ sudo ln -s /opt/java/sun-java6-manual

  7. I assume that you have already installed Sun JDK from Ubuntu repositories before. If this is the case then there should be .java-6-sun.jinfo file in /usr/lib/jvm/ directory. We will copy that file and modify it. If there is no such file you can download it to current directory with this command:

    $ sudo apt-get -d install sun-java6-bin && find /var/cache/apt/archives/ -iname sun-java6-bin* -exec ar -p '{}' data.tar.gz \; | tar -zxO ./usr/lib/jvm/.java-6-sun.jinfo | sudo tee .java-6-sun.jinfo

    You can delete it afterwards. The reason I am not using .java-6-openjdk.jinfo file that probably is present in your Ubuntu installation is that it is slightly different that Sun’s one (some browser plugin entries are missing).

    Copy file and replace path entries that they point to created link in /usr/lib/jvm/

    $ sudo sed s/java-6-sun/sun-java6-manual/ .java-6-sun.jinfo | sudo tee .sun-java6-manual.jinfo

  8. Now edit the beginning of file so it looks like below:

    $ sudo vim .sun-java6-manual.jinfo


    Choose whatever priority you like.
  9. Now we have to register new alternatives in update-alternatives mechanism.

    $ cat .sun-java6-manual.jinfo | grep -E '^(jre|jdk)' | awk '{print "/usr/bin/" $2 " " $2 " " $3 " 30 \n"}' | xargs -t -n4 sudo update-alternatives --verbose --install

  10. Do the same with plugins

    $ sudo update-alternatives --verbose --install /usr/lib/mozilla/plugins/ /usr/lib/jvm/sun-java6-manual/jre/lib/amd64/ 30

    $ sudo update-alternatives --verbose --install /usr/lib/xulrunner-addons/plugins/ /usr/lib/jvm/sun-java6-manual/jre/lib/amd64/ 30

  11. Now we are ready to switch default Java to the new one.

    $ update-java-alternatives -l

    It should list available java alternatives. It may look like:

    java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
    java-6-sun 63 /usr/lib/jvm/java-6-sun
    sun-java6-manual 1500 /usr/lib/jvm/sun-java6-manual

  12. Set chosen option with:

    $ sudo update-java-alternatives -s sun-java6-manual

  13. Now confirm that java command is the new installed one

    $ java -version
    java version "1.6.0_25"
    Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
    Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)

Updating JDK
When you want to update JDK, download and unpack somewhere and change link /opt/java/sun-java6-manual to point to it.


    0 of 8192 characters used
    Post Comment

    • profile image


      5 years ago

      On latest Ubuntu: step 7 doesn't work (can't get sun-java6-bin even if you force lucid repositories), just copy .java-1.6.0-openjdk-amd64.jinfo and change the last line to

      Step 9: add hl to the (jre or jdk) command (can't type the or symbol here)

      Step 10: no xulrunner, just run the first command (mozilla-javaplugin)

    • john pitt profile image

      john pitt 

      6 years ago

      nice !

    • maciek profile imageAUTHOR


      6 years ago from Poland

      Well - command is a bit complex but it does its job

    • profile image

      very disappointed 

      6 years ago

      Step 7: !? you must be joking

    • profile image


      6 years ago

      Impossible with a new installation

    • profile image


      6 years ago

      very confusing

    • profile image


      6 years ago


    • maciek profile imageAUTHOR


      6 years ago from Poland

      I am glad it was helpful :)

    • profile image


      6 years ago

      Thanks, just what I needed :) I think I will repost this at my blog (linking here of course) to have another copy of this tutorial out there for ppl to find.


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)