Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a Ubuntu Server.

From the terminal, how should I install JDK?

In this guide it says to use this command:

sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk

But on Suns website, it says JDK includes the JRE, so why the JRE in the line above?

Anybody know how to actually install Java?

Every guide and every forum shows different ways of doing it.

BTW: It is a VPS (virtual private server)

share|improve this question

5 Answers 5

up vote 8 down vote accepted

Use apt-get install sun-java6-jre sun-java6-jdk. Just because Oracle's (Sun's) JDK distribution also contains a JRE does not necessarily mean that the Ubuntu team packaged it the same way.

Of course, if you do not want to develop Java applications on your server but only want to run them, sun-java6-jre should be enough.

share|improve this answer
Does this answer need an update for Java 7? –  Nathan Long Sep 2 '13 at 14:00

Here is how I do it:
I download jdk-6u20-linux-i586.bin from sun, unpack it by executing sh jdk-6u20-linux-i586.bin.
Move the resulting directory to ~/bin directory (/home/username/bin) and add it your path in .bash_profile.


Well, in a server environment, when I have to use a specific version of jdk (tomcat application as an example) I install jdk as above. Cheers!

share|improve this answer
If your Linux distribution has a package manager, you should use it to do all installs unless absolutely necessary. –  Dennis Williamson May 29 '10 at 15:08
I also take the same approach. It's much easier to control specific java version, especially if you have multiple applications with different version needs. It's also cleaner (IMHO) since it's isolated to a specific user, not filling up the whole system with N java installations. –  Cristian Vat Oct 3 '10 at 9:33
Its better to not use the systems package manager IMHO. I would use the package manager to uninstall the "OpenJDK" distro, and instead , download the SUN JDK (as Paul suggests) and then manually update /etc/alternatives symbolic links to the new location at /usr/java/jdk1.6.0_24/bin . –  djangofan Apr 19 '11 at 22:37
I agree with Paul on this on, on a server running one or more server java applications I always install Java manually and specify JAVA_HOME and add it to PATH in the startup scripts. Take tomcat/jboss/weblogic/websphere/oc4j etc. Different applications may require different versions of the JDK. –  HampusLi Apr 20 '11 at 7:18

From my Trusty book of notes.

Acquiring JRE/JDK

First we need to download JDK and JRE 6 for CentOS. Download the following files to your root directory (~) with 'wget'. Note that you may need to change the file names as they may have some URL variables added to the name. Be sure to not download the RPM files.

  • JDK Download
  • JRE Download


Now that we have the files downloaded we need to create an installation directory for Java.

sudo mkdir /usr/java cd /usr/java

Now we need to execute the installation for Java Development Kit (JDK). In our example we will use specific file names. Keep in mind that your file names may vary.

sudo sh ~/jdk-6u14-ea-bin-b03-linux-amd64-10_mar_2009.bin

Press space to advance through the license agreement and type 'yes' to accept. Press enter to finish the installation.

Now we need to install the Java Runtime Edition (JRE). In our example we will use specific file names. Keep in mind that your file names may vary.

sudo sh ~/jre-6u14-ea-bin-b03-linux-amd64-10_mar_2009.bin

Press space to advance through the license agreement and type 'yes' to accept.

Verify the installation by typing ls. You should see two directories: jdk1.6.0_14 and jre1.6.0_14. Keep in mind that your version numbers may differ slightly.

Installing Ant and Tomcat

Next we will need to download and extract Apache Ant. Ant is an installation utility used by several Apache products.

To download Apache Ant you will need to visit the following website to download the installation file:

Scroll down the page and find the .tar.gz under Current Release of Ant. Copy the URL and use wget to download the file to the /usr/share directory. Your version number may differ.

cd /usr/share sudo wget

Next we need to unpack that file so we can install it. Note that your version number may be different.

sudo tar -xzf apache-ant-1.7.1-bin.tar.gz

share|improve this answer

I've setup an instant messaging server (using spark IM server software). It requires java so I installed as follows

apt-get install sun-java6-jre

works fine to me.

share|improve this answer

Here is a great example of the RIGHT way to do it, which is similar to Paul's answer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.