Installing Sun Java on ubuntu 12.04 x64

It’s a little annoying that ubuntu does not provide a sun java (I don’t think iced-tea works all that well at the moment).  I found that this guide worked pretty well.  Of course you don’t need to install in /opt/java/64.

Go here and grab the linux x64 file (not the rpm).  And save it somewhere on your machine.

Then make the directory where java will end up living, and change into it: sudo mkdir -p /opt/java/64 && cd /opt/java/64

Move the file you’ve just downloaded to this directory (you’ll need sudo-powers again): mv ~/Downloads/jre-6u31-linux-x64.bin /opt/java/64

And make the file executable: sudo chmod +x jre-6u31-linux-x64.bin

And run it (you might have to agree to the license): sudo ./jre-6u31-linux-x64.bin

Set this java to the default:
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/64/jre1.6.0_31/bin/java" 1
sudo update-alternatives --set java /opt/java/64/jre1.6.0_31/bin/java

And setup for the browser:
mkdir -pv ~/.mozilla/plugins
sudo apt-get remove icedtea6-plugin
rm -v ~/.mozilla/plugins/libnpjp2.so
ln -s /opt/java/64/jre1.6.0_31/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

Slightly modified from: http://sites.google.com/site/easylinuxtipsproject/java

Posted in Tech. Tags: , , . 12 Comments »

12 Responses to “Installing Sun Java on ubuntu 12.04 x64”

  1. xnad Says:

    Stuck at here: Set this java to the default:
    sudo update-alternatives –install “/usr/bin/java” “java” “/opt/java/64/jre1.6.0_31/bin/java” 1
    sudo update-alternatives –set java /opt/java/64/jre1.6.0_31/bin/java

    • Joseph Says:

      Sorry, wordpress is mangling the dashes and quotes (which are important to get right). Try this (it’s two separate commands, both preceeded by sudo):
      sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/64/jre1.6.0_31/bin/java" 1
      sudo update-alternatives --set java /opt/java/64/jre1.6.0_31/bin/java

      • xnad Says:

        Sorry im noob :)
        i think also ” exclude .. i have done it :) as :
        sudo update-alternatives –install /usr/bin/java java /opt/java/64/jre1.6.0_31/bin/java 1

  2. xnad Says:

    now stuck @
    mkdir -v ~/.mozilla/plugins

    • xnad Says:

      Sorry for FLOOD .. Have done it completly.. Now it shows at firefox/tools/add-ons/plugins as: Java(TM) Plug-in 1.6.0_31 (and enabled) i dont know if it become default plugin in ubuntu but firefox is everything for me.
      At stuck place i closed terminal and open another so i went to default terminal folder, than i use worked command as well as down here and followed other lines in order. Thank u very much. I Keep learning.. :)))

      sudo mkdir -v ~/.mozilla/plugins

  3. bob marley Says:

    would like feedback on this option to install a LOCAL apt for sun-java

    https://github.com/flexiondotorg/oab-java6

    • Joseph Says:

      It’s certainly a clever idea but:
      1) you only have to do this once, so a couple extra commands isn’t a deal-breaker for me
      2) it requires getting the JSE instead of the JRE (slightly bigger download, slower)
      3) it requires doing so for both architectures (even slower)
      4) how that script determines the version to get isn’t quite clear withuot looking at the code for a little longer than I want to right now

      That said it is fewer commands and the end effect is pretty much the same (working java install), so go for it. Also, if you can add this repo to other machines on a LAN then suddenly the “only download from sun once” thing becomes a huge speedup (instead of forcing you to download bigger files you aren’t going to use).

      • bob marley Says:

        thanks for taking the time to flip through that for me/us.

        being not completely linux savvy does your /opt install allow you to keep openJDK and sun-java?

        and second with sun java do I replace iced-tea plug-in for firefox? Disable the extension or remove a file somewhere?

        cheers

  4. Mimi Says:

    Hi …I followed these instructions but the downloaded file is a ‘tar.gz’ file …I’m lost :/

    • Joseph Says:

      Mimi, .tar.gz is a standard extension for archives on linux. You can unpack it by running “tar -xf filename.tar.gz” and it will generally create a folder named filename in the current directory. Or if you use graphical interfaces I suppose right clicking on the file would present you with some variation of “extract here” as an option.

  5. William C Grisaitis (@caravaggisto) Says:

    What’s your reason for installing in /opt? Why not /usr/lib/jvm or /usr/local/java or what have you?

    I came across your post when searching where I should install the sun jdk… There seems to be no clearly best answer.

    Thanks, William

    • Joseph Says:

      William, at the end of the day it’s pretty arbitrary where you put it. I like to put packages that require a little bit of babysitting in /opt, those that are simple “./configure && make && make install” end up in /usr/local/bin, and the package manger puts things in /usr/bin. Then obviously things that are just for my user are in ~/scripts (scripts, also lives on dropbox so I don’t have to worry about syncing across machines) or ~/bin (binaries).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: