[HOW TO] Install Oracle JDK 7 Manually in Ubuntu

The Java Development Kit (JDK) is mainly a set of tools for running, compiling and debugging Java applications.

There are a few other JDK, but in this article we'll see how to manually install the Oracle's JDK in any distribution from the Ubuntu family. The process consists of downloading the binary package, extract it and update the system so that the new version is used. By the way, if you installed the JDK via PPA, as described in my previous article, both can work alongside. The command update-alternatives can be used to choose one between them.

Download

The first step is to download the latest binaries package from Oracle's website. On the downloads webpage choose the JDK download button.

On the next page you'll see list of several files, but you should focus your attention on two: The file name ends with i586.tar.gz or x86_64.tar.gz. If your system is 32 bits you should select the first one and select the latter if it's 64 bits. If you're unsure, run the command uname -m on a terminal window. Now download the file you need and take note of its download location.

Install

We've downloaded the package, so now we must install it.

Start by opening a terminal window and changing the current directory, using cd command, to the download destination.

Then extract the package:

sudo tar -zxvf jdk*.tar.gz -C /usr/lib/jvm/

Add the new java alternative to the system:

for alt in java javac; do sudo update-alternatives --install /usr/bin/$alt $alt /usr/lib/jvm/jdk*/bin/$alt 1000; done

Finally, update the java alternatives, typing the selection number of the last choice presented by the command bellow. You'll be prompted twice, once for java and another time for javac.

for alt in java javac; do sudo update-alternatives --config $alt; done

Uninstall

If you want to remove Oracle's JDK, here's how to proceed: Choose another alternative for java and javac, then just remove the JDK directory.

for alt in java javac; do sudo update-alternatives --config $alt; done && sudo rm -rf /usr/lib/jvm/jdk1.7*

Comments

  1. I'm getting a syntax error on the following command:
    "for alt in java javac do; sudo update-alternatives --config $alt; done"
    returns
    "bash: syntax error near unexpected token `sudo'"

    ReplyDelete
    Replies
    1. It's fixed now. The semicolon was on the wrong place. Sorry.

      Delete

Post a Comment

Popular posts from this blog

[FIX] VLC is unable to open the MRL (smb://)

Add items to Xfce Applications Menu