How To: Install Sun Java in Ubuntu from Command-Line

Had to do a fresh install of Sun's Java on a remote Ubuntu machine this weekend. It's pretty easy to do in a graphical environment, but I only had ssh access. Since I couldn't find a set of instructions on how to install Sun's Java from the command line, I thought I'd put together my own how-to.

You'll use the apt-get command to grab the Sun java .deb files and install them. It works just like a command-line version of the Synaptic Package Manager you probably used to install software from the graphical environment.

But apt-get doesn't know how to find the Sun Java files unless you add some sources to its repositories: a list of all the places apt-get looks for software.

Once you've added the repositories to the source list for apt-get, one command will install everything for you. Here's a step-by-step way to do it:

  1. Type "nano /etc/apt/sources.list" to open a command-line text editor to edit the list of repositories apt-get will look through.
  2. You'll see some lines, starting with "deb" or "deb-src" already in the file. Add the following lines to the file:

    deb hardy universe deb-src hardy universe deb hardy-updates universe deb-src hardy-updates universe deb hardy multiverse deb-src hardy multiverse deb hardy-updates multiverse deb-src hardy-updates multiverse

  3. Press Ctrl-O to save the file. Press Return to agree to name the file sources.list, then press Ctrl-X to leave the editor.
  4. Type: "apt-get update"
  5. Type: "apt-get install sun-java6-jdk"

That should do it!

Ron Toland @mindbat