Installing Oracle Java 6 on Ubuntu 10.04

Some Linux distros pre-install Java, and some don't. Even when they do, the distro may not be various implementations of Java while I prefer Oracle's (formerly Sun's). After some googling, I found a way to successfully download and install Sun's latest implementation. In my case, today, that was Java 6 update 21 on Ubuntu 10.04 (freshly updated today).

I'll share the steps I took. Caveat: I'm a Linux newbie, so inform yourself with further research, and proceed at your own risk.

  • Download Java installer from Oracle, and prepare it to execute.
  • Run the installer.
  • Verify install.
  • Add that Java implementation to the PATH so it may be found and used by your computer.
  • Install a plugin to enable web browsers to run Java applets.


You may find it easiest to obtain Java here
But if you are more technically minded, go here
  1. Look for "Java SE" where 'SE' means "Standard Edition" aimed at regular desktop and laptop computers, as opposed to phones/handhelds and servers. 
  2. If you merely want to run Java, download the "JRE" where the 'R' means "Runtime". If you may want to write and compile your own Java programs, download the "JDK" where the 'D' means "Development". 
  3. Choose "Linux" if you have a 32-bit version of Ubuntu, or "Linux x64" if you have 64-bit Ubuntu. 
  4. Notice a link elsewhere on this page for "Installation Instructions". Open that link in a a separate browser window/tab for more info. For me, the link was: http://java.sun.com/javase/6/webnotes/install/index.html#linux
  5. Click Continue. 
  6. When asked for you to register your name, notice the option to skip that step.
In my case today, I downloaded "Java SE Development Kit 6u21". That means the 21st update to Java version 6 (technically known as Java 1.6).

You will have downloaded a .bin file. In my case, "jdk-6u21-linux-i586.bin". Next we ensure that the security settings for this file allow us to run the installer software contained inside. We do so using the command-line. 
  1. Choose Accessories > Terminal. 
  2. Type: chmod a+x jdk-6u<version>-linux-i586.bin


Now we can run the installer stored in that .bin file. 
  1. Move the file to the directory where you want to install Java. For me, I chose my own home directory. 
  2. In the Terminal, switch to the place you chose to install. For me that was home: cd ~
  3. Run the installer. In the Terminal type: ./jdk-6u<version>-linux-i586.bin
  4. When the installer finishes, find the new directory named: jdk1.6.0_<version>.

Let's see if the newly installed Java works. 
  1. Change to the new "jdk" (or "jre" if you chose that installer) directory. 
  2. Within the "jdk" directory, change to the "bin" directory.
  3. Test your Java install by typing ./java -version to print a few lines describing the version of Java.

To run Java above, we had to switch to the "bin" directory. Instead, we should tell the computer where to find the Java install. To do that, we add that directory location to a "System Variable" (a.k.a. "Environment Variable") called PATH. The PATH variable is a list of all the directories the computer should check when trying to run a program from the command line. 

Changing the PATH should happen every time we login to Ubuntu. During login, Ubuntu reads several configuration files. We can add instructions for changing the PATH in one of those files.While I am not sure which of the various files is the ideal place to change the PATH, I have found one that works. The configuration file I used is named ".profile". The period in the front of the file name means the file normally hidden. To see this file in the command line, type ls -a where the '-a' means show all files including the normally hidden ones. You can also tell your File Manager to show these files by checking Edit > Preferences > Default View > Show hidden and backup files.
  1. Go to your home directory, and verify the file .profile exists.
  2. Make a copy of that file. You can do so in the Terminal by typing: cp .profile .profile_backup
  3. Open the ".profile" file in the a text editor such as Applications > Accessories > gedit Text Editor.
  4. Add these two lines (exactly, case sensitive) to the bottom of that file, and save:
    export PATH
  5. Logout
  6. Login
  7. Test your work by changing to any directory in Terminal, and type: java -version

Browser Plugin

Your web browser may not yet be set up to run Java applets. You can test this easy by using the "Do I have Java?" link at Java.com.

I followed these instructions to install the browser plugin for Java.

I found my Firefox 3.6.6 plugins folder here:
Surprisingly, I found that folder to be empty. If you find any old Java plugins, delete them.

I found the Java plugin file here:

The directories nested in /usr are protected. So you need an 'SuperUser' administrator's password to make changes. If you installed Ubuntu, then your own password should work. Below you'll see that I used the 'ln' command to create a link file, but added the word 'sudo' in front. 'sudo' is a command that means "do the following as a superuser rather than a normal user".

So in Terminal I…

  1. Closed any open Firefox windows.
  2. Changed to the plugins directory by typing: cd /usr/lib/firefox-addons/plugins
  3. Created a symbolic link (like an Alias in Mac OS X and Shortcut in Windows) by typing: sudo ln -s /my_user_name/jdk1.6.0_21/jre/lib/i386/libnpjp2.so
  4. Typed in my superuser password
  5. Confirmed the creation of the link file by typing: ls -a
  6. Launched Firefox.
  7. Verified the plugin's presence by typing in the Firefox address bar: about:plugins
  8. Verified that the Java plugin works by visiting Sun/Oracle's page "Verify Java Version". 
That was a chore, but well worth the trouble. Java is a wonderful thing. For example, try this amazing stock market applet.

No comments:

Post a Comment