Installing Sun’s Java on CentOS 5.2

By far the most messy thing on CentOS 5.2 is adding Sun’s Java.  I have never found great success from the different packages that are out there for installing java.  I prefer to simply use the packages from Sun.

Step (1) : Visit Sun’s web site and download the latest version of Java (the *.bin file not the *-rpm.bin) (http://java.sun.com/javase/downloads/index.jsp)(pay close attention if you want the 32bit or 64bit version)

Step (2) :

[user@www]# cd /opt/
[user@www]# wget "[GIANT_SUN_URL_TO_GET_THE_JAVA_BIN_FILE_x64_IN_THIS_CASE]"
[user@www]# /bin/sh jdk-6u7-linux-x64.bin

Step (3) : Setup the alternatives correctly

[user@www]# alternatives --install /usr/bin/java java /opt/jdk1.6.0_07/bin/java 2
[user@www]# alternatives --config java
 
There are 2 programs which provide 'java'.
 
  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
   2           /opt/jdk1.6.0_07/bin/java
 
Enter to keep the current selection[+], or type selection number: 2
[user@www]#

Step (4) : Check to make sure the install was a success

[user@www]# java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) 64-Bit Server VM (build 10.0-b23, mixed mode)
[user@www]#

17 Comments so far »

  1. Ranganath said

    November 14 2008 @ 3:17 am

    Atlast, this worked. Thanks a lot. Not many people tell how to utilise the alternatives command! Most of all the tutorials in misleading everywhere! Appreciate it!

  2. Zyrre Forslin said

    November 25 2008 @ 7:04 pm

    run as “su -” not just “su”

  3. Dallas said

    January 28 2009 @ 7:34 pm

    Excellent tutorial :)

    I followed your suggestions on my Centos 5.2 machine, opting to download the rpm from sun. If you do, use the following alternatives command:

    alternatives –install /usr/bin/java java /usr/java/jre1.6.0_11/bin/java 2

    Dallas

  4. Chris Schuld said

    January 28 2009 @ 8:00 pm

    @Ranganath
    Thanks!

    @Dallas
    Thanks for the update Dallas!

  5. helikaon said

    February 22 2009 @ 3:28 pm

    Thanks a lot for helping out, though i’ve got also small addition to this article (hope it can help someone):
    what i have:
    CentOS 5.2 2.6.18-92.1.22.el5 x86_64 GNU/Linux + firefox 3.0.6 x86_64 + java version “1.6.0_12″ (jre install)
    I went ok all the way down you described, so command java -version has shown the correct jre install. But java in firefox wasn working.
    Problem was in one plugin that i had to link.
    what i did:

    cd /usr/lib64/firefox-3.0.6/
    mkdir plugins
    cd plugins
    ln -s /opt/jre1.6.0_12/lib/amd64/libnpjp2.so libnpjp2.so

    That did the job for me.
    It took me some time to figure it out, because google search was making reference to missing plugin libjavaplugin_oji.so, but that pays for 32 bit firefox version.
    This thread at ubuntu helped to findout which plugin was missig for me:
    http://ubuntuforums.org/archive/index.php/t-1062477.html

    Thanks again, i hope i can help out in turn to someone :-)

  6. Chris Schuld said

    February 22 2009 @ 4:22 pm

    @Helikaon

    Thanks for the additional notes, glad it helped out!

  7. Robert said

    February 27 2009 @ 1:33 pm

    Hey.. thanks for this.. but when I installed everything.. still does not build jedit for me using jedit…. jar..

    getting exception in main..
    Exception in thread "main" java.lang.NoClassDefFoundError: jedit42install/jar
    Caused by: java.lang.ClassNotFoundException: jedit42install.jar
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: jedit42install.jar.  Program will exit.
    

    any help much appreciated .. thanks

  8. Chris Schuld said

    February 27 2009 @ 3:06 pm

    @Robert

    There could be several things going on here: your CLASSPATH could be incorrect (my guess) or you may need to run the alternates command for jar. Let me know if you solve it — tricky to debug without more information on your system.

  9. Andrei said

    April 30 2009 @ 6:48 am

    thanks! it helped.

  10. Samir said

    May 5 2009 @ 9:06 am

    Thanks for the tutorial, it was very helpful for me.

  11. Alex said

    May 13 2009 @ 8:11 am

    Thank you very much! This tutorial saves my day.

  12. Grey said

    May 13 2009 @ 10:23 pm

    Thanks! it works

  13. fledermaus said

    June 11 2009 @ 12:30 am

    Hi, I tried to install java following your tutorial. Everything worked like a charm, I mean, no errors.

    But when I do the test typing java -version it says: bash – command not found…

    I will try to look up how to set the classpath thingy… So far, no luck…

  14. RRaph said

    July 1 2009 @ 7:47 am

    Very good tutorial.
    Dallas’s alternative is working too.
    Many thanks.

  15. Paras Pradhan said

    July 14 2009 @ 7:54 am

    Nice short article. Thanks halikaon as well. Did work in centos 5.3 as well.

    Paras.

  16. Ilyse Kazar said

    August 3 2009 @ 4:34 am

    Well i gave your instructions a Profoundly Newb Test, since i am only a consultant who does largely PM and is trying to install scrumworks pro which needs java on my web server. CentOS 5.2.

    Here are my notes, from the perspective, then, of someone whom it is safe to presume does NOT have lots of experience doing this sort of thing.

    1. the wget command worked for my selected version but the file that was saved had the same long name as everything after the final slash in that superlong URL.

    IOW the filename also included everything after the ? in the URL (perhaps since i’d read bad things about 6_14 and therefore poked around on Sun’s site to find 6_13). I guess because the filename had all sorts of strange characters in it (% for example) I could not figure out how to use the mv command to change it to its basic jdk-6u13-linux-i586-rpm.bin format … so I went thru my ftp client (Cyberduck) that makes renaming stuff on my web server handy.

    2. THIS INSTRUCTION NEEDS … WELL … MORE INSTRUCTION:

    Step (3) : Setup the alternatives correctly
    [user@www]# alternatives –install /usr/bin/java java /opt/jdk1.6.0_07/bin/java 2

    Where does that string come from?? I used it (replacing the _07 with _13 for the version I’d dl’d) but felt very unsure whether it actually did anything. For the instructions to be valid beyond the particular 6_07 version you installed as an example, can you tell us how, after completing steps 1 and 2, one knows exactly what string to put after /opt/ in the above command? thanks

    3. SADLY MY INSTALL FAILED:
    [/opt]# java -version
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    Could not create the Java virtual machine.

    thanks anyway. it’s always scary and fun to do stuff to my web server :-D

  17. Barry Wadsworth said

    January 31 2010 @ 9:42 pm

    Thanks for you help! I’ve successfully installed jdk1.6.0_18 on CentOS 5.4!

    Here are a few notes that may help others:

    When I did wget the file name had the url prepended to it. I was able to rename it by putting double quotes around it.

    When I did the alternatives command, it isn’t recognized. I exited and used su – instead of su root, then it recognized the alternatives command.

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

Email: (Required)

Website:

Comment: