Thursday 3 October 2013

Installing JDK on Ubuntu

This is an example of how to install JDK on Ubuntu. I wrote this when I was using JDK 7 with Ubuntu 10.04 -- so you may want to check Oracle's website for the latest version.

1. Download one of the following files:
http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz (for 32-bit)
http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz (for 64-bit)

2. Decompress the .tar.gz file.

3. Move the JDK files to /usr/lib/jvm/jdk1.7.0 or somewhere else as appropriate.

4. Run from bash shell:
sudo vim /etc/environment
You will see something like
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
Change the file to something like (also change the installation path if needed)
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/jdk1.7.0/bin"
CLASSPATH=.:/usr/lib/jvm/jdk1.7.0/lib
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
And then reload .bashrc file:
source ~/.bashrc
5. Run the following commands from bash shell:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0/bin/javac 300
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.7.0/bin/javap 300
sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.7.0/bin/javadoc 300
Installation is now complete. Run the following command from bash shell for a test:
java -version

No comments:

Post a Comment