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]#
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!
run as “su -” not just “su”
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
@Ranganath
Thanks!
@Dallas
Thanks for the update Dallas!
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:
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
@Helikaon
Thanks for the additional notes, glad it helped out!
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
@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.
thanks! it helped.
Thanks for the tutorial, it was very helpful for me.
Thank you very much! This tutorial saves my day.
Thanks! it works
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…
Very good tutorial.
Dallas’s alternative is working too.
Many thanks.
Nice short article. Thanks halikaon as well. Did work in centos 5.3 as well.
Paras.
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
“
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.
is step 1 just to determine the URL? why would you need to download it twice? first time in step 1 and then in step 2 with wget. what am i missing?
hello julia here…….microsoft certificateI’m not very smart on installing packages on Linux, but today I need to configure a Tomcat on a CentOS 5.2. The CentOS 5.2 has Tomcat 5 available as yum package, with gcc-java. But Java gurus tell me to use the original Sun JDK to run Tomcat without problems. I know that Tomcat can run with a JRE which is a lot smaller, so I started with download the Java JRE 6 Update 11 from here. I choosed Linux/Multilanguage and accepted the Sun Terms. I downloaded the jre-6u11-linux-i586.bin file wich is an autoinstaller for Linux. After uploading the file in the /root dir, I did a chmod to make the file executable: chmod u+x jre-6u11-linux-i586.bin and then ran it
./jre-6u11-linux-i586.bin
I can not thank you enough for this. Linux noob. Have spent about 6 hard hard hours trying to do this. Thanks so much for taking the time to post this.
@ last its working. Thanks. Must tell you this was the first time I used alternatives.
I followed your tutorial, but i can’t get reponse from command java -version. My system is a rhel 5.4 64-bits and java 1.6 by sun (rpm binaries). On my tomcat logs shows:
dl failure on line 685Error: failed /usr/java/jdk1.6.0_18/jre/lib/amd64/server/libjvm.so, because /usr/java/jdk1.6.0_18/jre/lib/amd64/server/libjvm.so: cannot enable executable stack as shared object requires: Operation not permitted
I’m tried run:
execstack -c /usr/java/jdk1.6.0_18/jre/lib/amd64/server/libjvm.so
execstack -q /usr/java/jdk1.6.0_18/jre/lib/amd64/server/libjvm.so
but does not work.
What am i doing wrong?
Gracias por el tutorial con ejemplo. thanks for the example.
Pingback: Installing Java on CentOS 5.5 « Quonn's Blog
Thanks for this manual!!!, I couldnt make my java work
Thanks for the great mini article. Needed to replace GNU Java with Sun Java to run a Minecraft server on one of my CentOS boxes and this sorted us out
Thank you! This was very helpful! I was looking for simple step by step instructions versus paragraphs and paragraphs of information.
Pingback: CentOS5.5にJavaをインストール – rab.bit
Thanks for the tips, that is by far the easy way to get Java Sun on centos.
Thanks alot!
My VPS Configuration
OS: centos-5-x86_64
VPS Platform: OpenVZ
HDD : 50 GB
Ram : 1 GB
I am trying to install 1 software on my VPS. But java is giving me some problem
[property] java.io.IOException: Cannot run program “/bin/env”: java.io.IOException: error=12, Cannot allocate memory
So then I am tried to allocate heap memory to JVM by using command
# java -Xms128m -Xmx128m DoRunTime
It will give such type of error
Exception in thread “DoRunTime” java.lang.NoClassDefFoundError: DoRunTime
Caused by: java.lang.ClassNotFoundException: DoRunTime
I am install JAVA using Command # yum install java-1.6.0-openjdk-devel
I have set my JAVA_PATH=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64
Also I have set my CLASSPATH=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/ext/
Also is there need to set PATH???
I Don’t know what is going wrong.
Thanks a lot.. The wiki page of Cent OS was really misdirecting.. I followed this without any problems.. appreciate this blog..
This was very helpful. Got the latest Sun Java easily installed on CentOS 6 with these instructions. Thanks!