How to install Java on Ubuntu

What is Java Development Kit (JDK)?

The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. It is also the foundation for the technologies in the Java 2 Platform, Enterprise Edition (J2EE) for enterprise software development and deployment. The JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications.

What is Java Runtime Environment (JRE)?

The JDK is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications. The conceptual diagram above illustrates all the component technologies in Java SE platform and how they fit together.

Assumptions/Requirements

This document is assume that we are going to install Java JDK in /opt directory. Below is the directory structure after finish the installation.

  • /opt/jdk1.6.0_06 <-- original folder name
  • /opt/java <--symlink to /opt/jdk1.6.0_06
  • "root" privileges will be required

root@server:/opt$ ls -lrt | grep jdk
drwxr-xr-x 10 root   root   4096 2007-03-14 19:01 jdk1.6.0_06
lrwxrwxrwx  1 root   root     17 2007-05-28 15:33 java -> /opt/jdk1.6.0_06/

Steps to install Java JDK

Become a super user

user@server:~# sudo su -
Password:

Download latest JDK (Java Development Kit) from Sun's website (http://java.sun.com/javase/downloads). Choose the ''self-extracting file''.

root@server:~# mkdir ~/downloads
root@server:~# cd ~/downloads
root@server:~# wget <url_to_download>
root@server:~# ls
jdk-6u6-linux-i586.bin

* Please choose the correct file based on the system architecture.

Now make it as executable file and install it.

root@server:~# chmod +x jdk-6u6-linux-i586.bin
root@server:~# sh ./jdk-6u6-linux-i586.bin

Executing the .bin file creates a folder on same location named jdk1.6.0_01 (your version can be different). Now move that folder to /opt

root@server:~# mv jdk1.6.0_06 /opt/

Create a symlink

root@server:~# ln -s /opt/jdk1.6.0_06 /opt/java

We are almost done, the only thing left is to set the JAVA_HOME variable. Set the below lines in /etc/profile

export JAVA_HOME=/opt/java
export PATH=$PATH:$JAVA_HOME/bin

To make this settings take effect without restarting/logging-out:

root@server:~# source /etc/profile

root@server:~# update-alternatives --install /usr/bin/java java /opt/java/bin/java 1

And now the java runtime environment appears in your list of choices when running '''sudo update-alternatives --config java'''! Go ahead and run that, and chose the sun java option. Then to check to make sure it worked, run '''java -version''', which should output something like this:

root@server:~# java -version
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b06)
Java HotSpot(TM) Client VM (build 1.6.0_06-b06, mixed mode, sharing)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <b> <i> <p> <br> <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.