Friday, August 10, 2007

Downloading JDK to your Linux Server via SSH

This is a pretty common problem that I'm sure almost every java developer has had to deal with. Due to Sun's licensing restrictions, you cannot simply use up2date, apt-get or yast to get the latest JDK. Even if you add the extra repositories for them to look at, it's usually not the latest JDK. On Windows, it's easy since you generally always have a UI via Remote Desktop. Linux is usually accessed via SSH so all you have is your shell command line which means you can't surf on over to Sun's Java site, click "Ok, I accept all the terms and conditions", and download it. So you end up downloading it on your local machine, then uploading it to your server via SCP. But this takes forever because you download 60 MB on your slow local connection, then upload it even slower (assuming your upload speed is slower than you download speed). So an hour later you finally get your jdk on the server.

So is there a better, quicker way to do it?

I'm glad you asked. Yes there most definitely is:

  1. Go to jdk download site: http://java.sun.com/javase/downloads/
  2. Click Download button on the distro you want (usually the basic JDK)
  3. Accept the license agreement
  4. Right click the download link (usually the RPM in self extracting bin) and in the right click context menu choose Copy Link Location if using Firefox or Copy Shortcut in Internet Explorer.
  5. Now you have the location of the download so go to your SSH shell where you are logged into your Linux server and use the following command:
    wget PASTE_FILE_LOCATION_HERE -O jdk6-rpm.bin
    1. You need the -O otherwise the filename length is too long
  6. Now install it:
    1. chmod a+x jdk6-rpm.bin
    2. ./jdk6-rpm.bin
  7. And finally, add JAVA_HOME to your environment variables:
    1. create or edit .bash_profile file in /root and add "export JAVA_HOME=/usr/java/latest"
That's about it. Much much faster.