Thursday, June 09, 2011

Installing Oracle Java on Ubuntu 10.04 LTS

It seems lately that I've installed Oracle Java on a number of Ubuntu systems, and while I have a small little "cheat sheet" on how I do it here, I thought putting it on the blog might be something useful for others. If nothing else I know where to look if I can't find it on my system here. This assumes you're running Ubuntu 10.04 LTS (I can't speak to other versions) and that you're using 1.6_26 (it's the current version as of this writing). Modify the file name accordingly if a newer version is available. This will install the java files into the /usr/local/java folder, create a link of /usr/local/java/latest that points to the latest version (makes it easy to change when you install a newer version of Java). Finally it sets up the environment variables and path on your system. Download the Java Development Kit
wget http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-x64.bin
Make the file executable and then execute the self-extraction
sudo chmod +x jdk-6u25-linux-x64.bin
sudo ./jdk-6u25-linux-x64.bin
Now we remove the JDK to the /usr/local/java folder, remove the downloaded file and setup the environment variables and path
    sudo rm -rf jdk-6u26-linux-x64.bin
    sudo mkdir -p /usr/local/java
    sudo mv jdk1.6.0_26 /usr/local/java/jdk1.6.0_26
    sudo ln -s /usr/local/java/jdk1.6.0_26 /usr/local/java/latest
    sudo mv /etc/environment /etc/environment.bak
    sudo echo "JAVA_HOME=\"/usr/local/java/latest\"" > ~/environment
    sudo echo "JRE_HOME=\"/usr/local/java/latest/jre\"" >> ~/environment
    sudo echo "PATH=\"\$JAVA_HOME/bin:$PATH\"" | cat >> ~/environment
    sudo mv ~/environment /etc/environment
    sudo echo "export JAVA_HOME=\"/usr/local/java/latest\"" > /etc/profile.d/javaenv.sh
    sudo echo "export JRE_HOME=\"/usr/local/java/latest/jre\"" >> /etc/profile.d/javaenv.sh
    sudo echo "export PATH=\"\$JAVA_HOME/bin:$PATH\"" | cat >> /etc/profile.d/javaenv.sh
    sudo /etc/profile.d/javaenv.sh
Confirm Java is installed and the version is correct
java -version

6 comments:

ben10 said...

I did as u told. but even now i can't run javac or java.help me plz.

ben10 said...

I did as u have told.But i cant run javac or java.help me.

ben10 said...

i did as u told but cant run javac or java.help me plz.

ben10 said...

i did as u told but i cant run javac or java.help me.

ben10 said...

i did as u told but i cant run javac or java.help me.

Troy said...

If you do /usr/local/java/latest/bin/java --version does it report to you the version of Java that you installed?