3

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)

5 Answers 5

8

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.

1
  • Does this answer need an update for Java 7? Sep 2, 2013 at 14:00
4

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.

HTH

Edit:
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!

4
  • 4
    If your Linux distribution has a package manager, you should use it to do all installs unless absolutely necessary. May 29, 2010 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. Oct 3, 2010 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, 2011 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, 2011 at 7:18
2

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

Installing

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:

http://ant.apache.org/bindownload.cgi

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 http://mirror.olnevhost.net/pub/apache/ant/binaries/apache-ant-1.7.1-bin.tar.gz

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

0

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.

0

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

http://wporta.wordpress.com/2010/07/06/installing-jdk-in-fedora-13/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .