Clear the Java mucky muck from Ubuntu.
Java on Ubuntu
This article is for Java developers who use Ubuntu as a development platform who wants to install Sun’s range of tools manually, instead of installing it with Synaptic/aptitude/apt-get. The commands in this article was tested on Ubuntu 8.04 “Hardy Heron” and assumes knowledge of the Debian alternatives system.
The benefits of installing it manually are:
- you choose exactly which version of the JDK you install
- you choose which tools you enable, e.g. jhat
Depending on what you’ve installed before, you may be left with a mixture of non-Sun tools, like gcj or the Eclipse Java compiler. We’re going to remove these, install our own, then tell Ubuntu where to find the newly installed tools.
The below is just a sample of things that may or may not be installed on your machine. Use Synaptic Package Manager instead, and search for “java” and remove accordingly.
You may need to completely remove the historical alternatives:
As you can see, not only do I use java and javac, but also jhat, jvisualvm, etc.
I’m going to digress and explain the commands I used in the code snippet above. The
!!:gs/A/B/ command basically means repeat the previous command, but replace A with B, all occurrences, as opposed to the
^A^B command which will only replace the first occurrence. More weird and wonderful commands can be found at commandlinefu.com.
Install the JDK. For the purposes of this discussion, let’s set the
JAVA_HOME environment variable to the location where you installed the JDK to, e.g.
Tell the alternatives system where it can find the new utilities:
And a quick test:
The same can now be done for your other tools, like Ant and Maven.