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:

Type “nano /etc/apt/sources.list” to open a command-line text editor to edit the list of repositories apt-get will look through.

You’ll see some lines, starting with “deb” or “deb-src” already in the file. Add the following lines to the file: