How to Install JAVA 7 (JDK 7u72) on CentOS/RHEL 7/6/5 and Fedora

During installation of Java using rpm files I faced issues many times. After that i found a better way to install java from Sun site. Using below steps i have installed java successfully many times without facing any issues. We can also install multiple version of java easily if required. Oracle has also released Java 8. To install it read article Install Java 8 in CentOS, Redhat and Fedora.


Use following step by step instructions to install or update java. I recommend to read carefully instruction for downloading java from Linux command line.

Step 1: Download Archive File

Download latest version of java from

For 32 Bit –

# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""

For 64 Bit –

# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""

Note: In any case if above command failed to download and you need to download java through Linux terminal, watch below screen cast ( ), You are required a graphical browser.

After completing download, Extract archive using following command. Use archive file as per your system configuration. For this example we are using 32 bit machine.

# tar xzf jdk-7u72-linux-x64.tar.gz
Step 2: Install JAVA using Alternatives

After extracting java archive file, we just need to set up to use newer version of java using alternatives. Use the following commands to do it.

# cd /opt/jdk1.7.0_72/
# alternatives --install /usr/bin/java java /opt/jdk1.7.0_72/bin/java 2
# alternatives --config java
There are 4 programs which provide 'java'.

  Selection    Command
*  1           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
 + 2           /opt/jdk1.7.0_60/bin/java
   3           /opt/jdk1.7.0_67/bin/java
   4           /opt/jdk1.7.0_72/bin/java

Enter to keep the current selection[+], or type selection number: 4 [Press Enter]

Now you may also required to setup javac and jar commands path using alternatives

# alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_72/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_72/bin/javac 2
# alternatives --set jar /opt/jdk1.7.0_72/bin/jar
# alternatives --set javac /opt/jdk1.7.0_72/bin/javac 
Step 3: Check JAVA Version

Use following command to check which version of java is currently being used by system.

# java -version

java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b01, mixed mode)
Step 4: Setup Environment Variables

Most of java based application’s uses environment variables to work. Use following commands to set up it.

  • Setup JAVA_HOME Variable
  • # export JAVA_HOME=/opt/jdk1.7.0_72
  • Setup JRE_HOME Variable
  • # export JRE_HOME=/opt/jdk1.7.0_72/jre
  • Setup PATH Variable
  • # export PATH=$PATH:/opt/jdk1.7.0_72/bin:/opt/jdk1.7.0_72/jre/bin

I hope above steps will help you for installing java on your Linux system. You can follow above steps to install multiple version of java as same time but you can use only one version at a time.


Founder of I love to work with Linux and other open source application. Also I like to share knowledge with my friends and other Linux users. Follow me on Twitter, Add me on Google+ or Like Facebook page.


  1. Tried to do this but at Step 1, after copy/pasting the wget command, I get:

    Connecting to||:80… connected.
    HTTP request sent, awaiting response… 403 Forbidden
    2013-08-30 22:21:20 ERROR 403: Forbidden.

  2. If i am using yum install jdk1.7.0 means ,where is the java _home path?
    how to set the java path
    if i ive which java
    i got /usr/bin/java
    i am in confusion to export java_home path..
    please help

  3. Thanks, its great post

  4. Thank you so much for this guide. This helped me a lot.

  5. Outstanding! I read carefully, followed your directions exactly and it went smoothly on the first try! You’re amazing!

  6. Nice article thanks for posting it.

    It should be noted that there are other commands from the JDK/JRE referenced in the alternatives directory that may cause problems if not all of the alternatives are updated. If you look at /etc/alternatives and look for all of the associated applications that are provided with java (maybe something like ls -l /etc/alternatives |grep ‘jvm\|java\|jre\|jdk’ ) you will notice much more than just the java command.

    For example, if you followed steps 1-2 and then ran javac, javaws, javadoc, jar, keytool, appletviewer, javah, etc… you will not get those installed from the jdk tarball in /opt but rather those installed via package (if something like the java-1.6.0-openjdk-devel package is installed) .

    After step 4 you will get it but not because of the alternatives system but because of the change in the PATH variable in step 4 which is user specific unless set in /etc/profile, /etc/profile.d/, or other system wide environment. So if you have a system process that uses javac, javadoc or a command other than java I believe you will not get the version in /opt. I believe that debian based systems (mint, ubuntu, etc.) have an update-java-alternatives command used for this purpose (to update all java related commands) but I don’t know at the moment if it is available for RHEL and derivatives like CentOS.

    Just thought I would share this in case other ran into issues.

    • Thanks Tomas, That is great help.
      I run into this because I typed java after I finished these commands:
      # cd /opt/jdk1.7.0_67/
      # alternatives –install /usr/bin/java java /opt/jdk1.7.0_67/bin/java 2
      # alternatives –config java
      and it works.
      but I can’t make it work after I finish these command:
      # alternatives –install /usr/bin/jar jar /opt/jdk1.7.0_67/bin/jar 2
      # alternatives –install /usr/bin/javac javac /opt/jdk1.7.0_67/bin/javac 2
      # alternatives –set jar /opt/jdk1.7.0_67/bin/jar
      # alternatives –set javac /opt/jdk1.7.0_67/bin/javac
      System told me “-bash: javac: command not found”.

  7. HI Team

    i not able to configure java. but i face this error “””Error: dl failure on line 863
    Error: failed /opt/jdk1.7.0_51/jre/lib/i386/client/, because /opt/jdk1.7.0_51/jre/lib/i386/client/ cannot restore segment prot after reloc: Permission denied””” while java -version run this command.

    i am using centos 5.8

    please help me

  8. HI, i have a clean install of centos 6.5 and i did everything only instead of JDK i installed JRE because i don’t need JDK

    when i come to the part of checkin java -version centos returned

    -bash: java: command not found

    did i miss something??

  9. Thank you so much. It worked like a charm on Centos 5.9

  10. Thanks. Simple and useful.

  11. Its made very simple to understand and install. Thnx a lot Rahul

  12. Very good step-by-step instructions. Worked for me perfect first time. Many thanks for sharing. Keep up the good work! Best, Abramo

  13. I installed all the steps, however, I am facing issue setting-up JAVA_HOME and JRE_HOME. Once I export both the home and exit, the path resets to its original states.. JAVA_HOME turns to null when I echo $JAVA_HOME or echo $JRE_HOME

    I am using su to set them up.

    Otherwise the installation instructions are superb. The only issue I found in the step is that the directory structure you mentioned is hadoop/hadoop whereas (if I am not wrong) it should have been hadoop/hadoop-1.2.1 Please let me know if I am wrong so I can rectify it.

    Thanks in advance.

  14. Sorry! I mixed two things in the above email… only first portion was for your reference ….I am missing something here. In UNIX environment we used .profile. What is the equivalent file in linux to set PATH?

  15. Rahul, big stacks of thanks for posting this and sharing your knowledge, worked perfectly. You get a gold star today.

  16. Just thank you very much for these clear instructions.

  17. If you use the RHEL Supplementary Repo, java-1.7.0-oracle* is already provided as an RPM and does all this for you (including the mess with alternatives). It is more comprehensive.

  18. Thanks, Rahul! That’s a perfect instruction. :-)

  19. Hi Rahul

    How to upgrade tomcat 7.0.50 to 7.0.54 in Windows OS ?

  20. I am installing 32 bit jdk on centos 64 bit .
    After following yours steps when i fire command “java -version ” i got error
    bash:/usr/bin/java:/lib/ bad elf interpreter no such file or directory
    Please help, why is it so.

  21. If the system didnot find the “alternatives” command in centos(redhat), You could use “/usr/sbin/alternatives” instead of “alternatives”

  22. Thanks Rahhul
    Very nice and informative article.

    Rahul do you have any Idea about GTK package on linux. I am trying to install Java Eclipse editor on my Linux bot bit its failing to start. Installation success but unable to start . It would be very kind help if you give some pointer. below is error. I googled a lot but did not found solution.

    00:00.72 ERROR [main] org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory safeLogged
    Application error
    org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]
    org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]
    at org.eclipse.swt.SWT.error(
    at org.eclipse.swt.widgets.Display.createDisplay(
    at org.eclipse.swt.widgets.Display.create(

    Please help karo bahe , mai bahut pareshani mei hu ..


  23. Wonderful instructions. It worked without an incident.

  24. thanks for your help

  25. Hello Rahul sir..

    I hope sir yor are doing well and sir i have install many things on linux with the of you webiste and but i need more help i always get so many issue during compiling MYsql 5.5 or 5.6 ,so please try to help me in same topic and if you have already worked on it , than share the URl with me , i will be thankfull to you..

  26. I am setting path of java but it is not getting executed. Kindly guide me to set path of java for hadoop installation in rhel6

  27. Thanks for the help.
    I’m getting this error:

    alternatives –set jar /opt/jdk1.7.0_67/bin/jar
    /opt/jdk1.7.0_67/bin/jar has not been configured as an alternative for jar

    The command to do the same for javac worked though.

  28. You did not mention where do we have to update the JAVA_HOME , JRE_HOME and PATH variable…

  29. kushal palli Reply to kushal

    when formate namenode it is showing following : and when jps it only showing Namenode jobtracker secondary namenode,datanode and tasktracker is missing.
    please tell me what are the steps to resolve this issue.
    thanks in advance.

  30. On step 2 you missed a hyphen. It should be… “tar -xzf”

  31. worderfull, easy to follow and works. thanks your article save my time

  32. You really helped me out with this tutorial! Thanks!

  33. Thank you so much. This was very helpful.

  34. thanks was looking for this tutorial

  35. Hii Rahul.

    Thanks for share this wonderful topic .I have downloaded java as ur instruction.but when i’m going to extract that,i’m getting some error…i.e

    [root@[-a opt]# cd /opt/
    [root@[-a opt]# ls
    [root@[-a opt]# tar xzf jdk-7u72-linux-x64.tar.gz
    tar: jdk-7u72-linux-x64.tar.gz: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now
    tar: Child returned status 2
    tar: Error exit delayed from previous errors

    i’m getting these errors…plz help me Rahul…plz…

    • It looks downloaded file is created with name jdk-7u72-linux-x64.tar.gz?AuthParam=1420273038_bb9a14b7dc51ed48b49522bb2b5b6680. So rename file first before extracting

      # mv jdk-7u72-linux-x64.tar.gz?AuthParam=1420273038_bb9a14b7dc51ed48b49522bb2b5b6680 jdk-7u72-linux-x64.tar.gz
      # tar xzf jdk-7u72-linux-x64.tar.gz

  36. Hi Rahul, this is just to say I am migrating an old CentOS 4 to CentOS 6 as an occasional sysadmin (I am a software architect) and all the tips in your blog have worked great so far, thanks.

  37. hank you =3 a lot for your sweet and forward article.

  38. Hello !!!

    New on Redhat….

    My problem is that I can’t get this command “java -version” to work after installation according to description above…

    I got a nice download done, but install failed somewhere here at the end of commands…:

    I have this release of Redhat:

    [root@docutv etc]# cat redhat-release
    Red Hat Enterprise Linux Server release 6.6 (Santiago)

    or maybe even bettwer like this

    [root@docutv /]# yum version
    Loaded plugins: product-id, refresh-packagekit, subscription-manager
    Installed: 6Server/ppc64 1226:3a2b2ccb8c91fdd603df3f3ea4aedb6a7a0f8a91
    Group-Installed: yum 15:22a4df6bb11e577f2c2c00cdd8113bfaac3fc27b

    [root@docutv jdk1.7.0_72]# alternatives –config java
    There is 1 program that provides ‘java’.
    Selection Command
    *+ 1 /opt/jdk1.7.0_72/bin/java
    Enter to keep the current selection[+], or type selection number: 1

    [root@docutv jdk1.7.0_72]# pwd

    [root@docutv jdk1.7.0_72]# alternatives –install /usr/bin/jar jar /opt/jdk1.7.0_72/bin/jar 2

    [root@docutv jdk1.7.0_72]# alternatives –install /usr/bin/javac javac /opt/jdk1.7.0_72/bin/javac 2

    [root@docutv jdk1.7.0_72]# alternatives –set jar /opt/jdk1.7.0_72/bin/jar

    [root@docutv jdk1.7.0_72]# alternatives –set javac /opt/jdk1.7.0_72/bin/javac

    [root@docutv jdk1.7.0_72]# java -version
    -bash: /usr/bin/java: cannot execute binary file

    [root@docutv jdk1.7.0_72]# export JAVA_HOME=/opt/jdk1.7.0_72

    [root@docutv jdk1.7.0_72]# export JRE_HOME=/opt/jdk1.7.0_72/jre

    [root@docutv jdk1.7.0_72]# export PATH=$PATH:/opt/jdk1.7.0_72/bin:/opt/jdk1.7.0_72/jre/bin

    [root@docutv jdk1.7.0_72]# java -version
    -bash: /usr/bin/java: cannot execute binary file

    [root@docutv jdk1.7.0_72]#

    Thx in advance for help — Micael

Leave a Reply


Support us!

If you like this site please help and make click on any of these buttons!