• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Install JAVA 8 on CentOS/RHEL 7/6 and Fedora 28-23

Written by Rahul, Updated on May 2, 2019

This tutorial helps you to install Java 8 or update Java on your system. Read the instruction carefully before downloading Java from the Linux command line.

The Oracle Java 11 is the latest LTS version available to download and install. To install Oracle Java 11 on CentOS and Fedora system follow below tutorial.

IMPORTANT: Java 8 is no longer available to download publically. You can use below link to install Java 11.

  • How to Install Java 11 on CentOS & Fedora

Step 1 – Download Latest Java Archive

The Oracle team provides Java RPM packages as well as compiled source code. Many times I have tried Java installation using rpm packages but I faced some issues. So I decided to install Java using the compiled source code. Since then I have installed a large number of times Java on CentOS, Redhat based systems without any issues. To download the latest Java SE Development Kit 8 release from its official download page or use following commands to download from the shell.

cd /opt/
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz"
tar xzf jdk-8u201-linux-x64.tar.gz

Step 2 – Install Java 8 with Alternatives

The alternatives command is used for maintained symbolic links. This command used to creates, removes, maintains and displays information about the symbolic links comprising the alternatives system. Let’s use the alternatives command to configure Java on your system. The alternatives command is available in chkconfig package.

cd jdk1.8.0_201/
alternatives --install /usr/bin/java java /opt/jdk1.8.0_201/bin/java 2
alternatives --config java

The newly installed Java version listed at number 4, So input 4 and press enter.

Select java version
There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /opt/jdk1.8.0_45/bin/java
*  2           /opt/jdk1.8.0_144/bin/java
 + 3           /opt/jdk-11/bin/java
  4           /opt/jdk1.8.0_201/bin/java

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

At this point, JAVA 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives

alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_201/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_201/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_201/bin/jar
alternatives --set javac /opt/jdk1.8.0_201/bin/javac

Step 3 – Check Installed Java Version

Java and javac binaries are available under PATH environment variable. You can use them from anywhere in your system. Let’s check the installed version of Java runtime environment (JRE) on your system by executing the following command.

java -version

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Step 4 – Setup Java Environment Variables

Most of Java based application’s uses environment variables to work. Set the Java environment variables using following commands

Set the JAVA_HOME, JRE_HOME and PATH environment variables.

export JAVA_HOME=/opt/jdk1.8.0_201
export JRE_HOME=/opt/jdk1.8.0_201/jre
export PATH=$PATH:/opt/jdk1.8.0_201/bin:/opt/jdk1.8.0_201/jre/bin

Also add the above commands to /etc/bashrc or /etc/environment file to auto set environment variables during the system reboot.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

139 Comments

  1. Avatar G0LDEN_key Reply
    June 26, 2019 at 10:13 am

    $ wget ‘https://download.oracle.com/otn/java/jdk/8u211-b12/478a62b7d4e34b78b671c754eaaf38ab/jdk-8u211-linux-x64.rpm?AuthParam=1561543343_db87fc4729c3230513c85594dd6ffddd’
    $ mv jdk-8u211-linux-x64.rpm\?AuthParam\=1561543343_db87fc4729c3230513c85594dd6ffddd jdk-8u211-linux-x64.rpm
    $ sudo rpm -i jdk-8u211-linux-x64.rpm
    warning: jdk-8u211-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
    Unpacking JAR files…
    tools.jar…
    plugin.jar…
    javaws.jar…
    deploy.jar…
    rt.jar…
    jsse.jar…
    charsets.jar…
    localedata.jar…
    $ java -version
    java version “1.8.0_211”
    Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
    $

  2. Avatar Rahul Reply
    May 24, 2019 at 6:41 am

    URL is throwing Error 403:

    wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz”

    –2019-05-23 23:40:44– https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
    Resolving download.oracle.com… 23.35.182.109
    Connecting to download.oracle.com|23.35.182.109|:443… connected.
    HTTP request sent, awaiting response… 302 Moved Temporarily
    Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz [following]
    –2019-05-23 23:40:45– https://edelivery.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
    Resolving edelivery.oracle.com… 23.79.166.37, 2600:1406:1400:69d::366, 2600:1406:1400:690::366
    Connecting to edelivery.oracle.com|23.79.166.37|:443… connected.
    HTTP request sent, awaiting response… 403 Forbidden
    2019-05-23 23:40:45 ERROR 403: Forbidden.

  3. Avatar roland Reply
    April 28, 2019 at 1:29 pm

    Hi,
    Thank you for the detailed instructions. It’s straight forward to perform the manual steps to set a specific java version. I’m trying to perform the same steps in a shell script on CentOS 7. I’. using “expect” to set the specific Java version but no luck. Have you been successful in setting the Java version with “expect” to set the value when executing:
    alternatives –config java
    This command opens an interactive subshell that requires the user to select a numerical value for the Java version.

    function configure_java() {
    yum -y install expect
    EXPECT=$(which expect)
    JAVA_HOME=”
    update-alternatives –install /usr/bin/java java ${JAVA_HOME%*/}/bin/java 2000
    ${EXPECT} <<EOD
    spawn update-alternatives –config java
    expect "Enter to keep the current selection[\+], or type selection number:"
    send 2
    EOD
    }

    However, when listing the JAVA_HOME version it has not been set. When I do it manually JAVA_HOME has the correct java version listed
    echo $JAVA_HOME

    Any thoughts?

    Cheers,
    Roland

  4. Avatar Zsolt Reply
    April 20, 2019 at 9:12 pm

    Since 8u211/212 you need to login to your Oracle account to download JDK, so this method isn’t working anymore.
    A new cookie called “OAMAuthnCookie_edelivery.oracle.com:443” is needed for downloading JDK, but the value of this cookie is generated by Oracle when you login.

    • Avatar paul Reply
      May 2, 2019 at 11:24 am

      Yes confirmed, this does not work any longer. Can we update this guide please? Thanks in advance Rahul!

  5. Avatar Ezequiel Reply
    April 10, 2019 at 11:20 am

    Thanks too much.

  6. Avatar Jaideep Reply
    March 17, 2019 at 1:43 pm

    Thanks buddy.
    Helped alot.

  7. Avatar Shubham Singh Reply
    February 13, 2019 at 10:21 am

    Thank you so much. This is a link that I was recommended. Very kind of you to save us trouble, all those you faced. May all your experience bring you a good fortune.

    Thank you once again.

  8. Avatar Abdo Reply
    December 30, 2018 at 6:53 am

    Big thanks

  9. Avatar IvanG Reply
    December 10, 2018 at 1:17 pm

    Hello. Does anyone known where is hash in download link comes from?
    For example 750e1c8617c5452694857ad95c3ee230
    in https://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-linux-x64.tar.gz

  10. Avatar jayBird Reply
    December 7, 2018 at 3:07 pm

    Hello,
    I am getting this error on my RHEL 7.5 server:

    alternatives –install /usr/bin/jar jar /usr/local/java/jdk1.8.0_192/bin/jar 2
    failed to link /usr/bin/jar -> /etc/alternatives/jar: /usr/bin/jar exists and it is not a symlink

    Please help! Thanks!

  11. Avatar Ravi Reply
    November 29, 2018 at 11:57 am

    Bacause of Oracle’s Worst/selfish behaviour not able to download from oracle site. Its too bad even though he bought it. Can you please provide an alternative as you are an expert on all these things and maintaining BlogSpot.

    • Rahul Rahul K. Reply
      November 30, 2018 at 4:50 am

      Hi Ravi,

      This article has been updated with the latest version and download link. Please check if this helps you.

      • Avatar Massimo Coreni Reply
        April 17, 2019 at 8:45 am

        wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz” again does not work, yesterday everything was okay. Seems that they ban

  12. Avatar Sumit Sahay Reply
    September 14, 2018 at 10:14 am

    Hi Rahul,

    I am trying to install jenkins on my centos vm instance but unable to do so as its need java 8 and the java version in my system is 1.7. Now, I am trying to update the java version but due to proxy issue I am getting error so I downloaded the java 8 couple of times “jre-8u181-linux-x64.rpm” and whenever I am trying to execute this rpm file, like below,
    sudo yum install jre-8u181-linux-x64.rpm
    But I am getting error like below,
    Trying other mirror.
    Error: Cannot retrieve repository metadata (repomd.xml) for repository: local. Please verify its path and try again

    Could you please navigate me to the correct direction.

    Looking forward for your reply.

    Regards
    Sumit Sahay

    • Rahul Rahul K. Reply
      September 14, 2018 at 10:16 am

      Try below command:

      sudo yum localinstall jre-8u181-linux-x64.rpm

      • Avatar siva Reply
        November 29, 2018 at 11:58 am

        Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
        Cannot open: jre-8u181-linux-x64.rpm. Skipping.
        Nothing to do

  13. Avatar Santiago Alamos Reply
    August 29, 2018 at 2:09 pm

    Nice update !
    Please fix this:
    export PATH=$PATH:/opt/jdk1.8.0_171/bin:/opt/jdk1.8.0_181/jre/bin

    it should be 181 in both

    • Rahul Rahul K. Reply
      August 30, 2018 at 4:31 am

      Thanks Alamos, tutorial has been updated.

  14. Avatar Pulkit Reply
    August 19, 2018 at 5:31 am

    Hi!
    When i am trying to execute the below command:
    wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz”
    It’s coming with 404 not found HTTP request, can you help me, please?

  15. Avatar Anoop Reply
    August 7, 2018 at 11:55 pm

    Very helpful and clearly documented. Thanks Rahul

  16. Avatar Colin Reply
    July 11, 2018 at 7:04 pm

    I just wanted to add that this is very helpful for anyone using SAP Hybris. The system and its Apache Ant builder are very sensitive to Java changes and build paths. Thank you for the content.

  17. Avatar saikiran Reply
    July 10, 2018 at 6:23 pm

    nice expalnation its worked for me

  18. Avatar vam Reply
    July 6, 2018 at 5:01 am

    nice article
    tq

  19. Avatar Mike Reply
    June 21, 2018 at 12:38 pm

    Works like a charm, thank you Rahul!

  20. Avatar Steven Reply
    June 8, 2018 at 10:07 pm

    Fantastic article, thank you!

  21. Avatar shahama Reply
    April 12, 2018 at 5:17 am

    I’m getting below error when I try java -version command
    -bash: /usr/bin/java: cannot execute binary file
    Any Solutions?

    • Rahul Rahul K. Reply
      April 13, 2018 at 6:23 am

      Try:

      chmod +x /opt/jdk1.8.0_161/bin/java

  22. Avatar shahama Reply
    April 2, 2018 at 4:43 am

    I need to upgrade my Oracle Java 1.7.0_79 to 1.8. Is this above method will work? or is there any other method?

    • Rahul Rahul K. Reply
      April 2, 2018 at 6:39 am

      Yes, it will work with Java upgrade also.

      • Avatar shahama Reply
        April 12, 2018 at 4:54 am

        Thank you. It is working fine. This article is very helpful. Keep on Posting

  23. Avatar junghan Reply
    March 26, 2018 at 5:08 am

    Thank you. It helps a lot and working.

  24. Avatar Neeraj Sharma Reply
    March 11, 2018 at 12:31 pm

    Hi Rahul,

    I’ve following you for quite some time and I really appreciate your contribution. However I’ve never been able to fathom how alternative command works.

    Will you please enlighten me.

  25. Avatar Abhishek Reply
    February 22, 2018 at 6:36 am

    Please for god’s sake remove the /etc/environment update section…. that’s not correct and it screws up the system

    • Avatar sripada sarma Reply
      April 7, 2018 at 5:47 am

      I followed it verbatim and later I saw your comment. Now it is not working and as good as not installed. The .sh file is not running as exe program. Pl how to undo /etc/bashrc.

  26. Avatar Noor Reply
    February 7, 2018 at 8:13 am

    I followed above steps but unfortunately i cannot edit /etc/environment file now, due to change in this file i am unable to run any command from my user even i cannot run sudo, sudo su or ls chown etc..
    I am working on AWS Linux instance.
    please help i can access files via ssh and winscp but with no permission to edit.

    • Avatar Victo Reply
      February 24, 2018 at 4:08 pm

      Reboot from dvd with rescue option, then remove the lines in de environment file.

      • Avatar Noor Khan Reply
        March 20, 2018 at 10:33 am

        really VICTO ? how to do this on AWS linux instance? i am unable to see such option on aws

  27. Avatar Aleksandrk Reply
    February 1, 2018 at 8:30 am

    Good tutorial. Thank you!

  28. Avatar Luis Urzua Arenas Reply
    January 31, 2018 at 6:23 pm

    Thank you, very usefyll!

  29. Avatar Amar Reply
    January 31, 2018 at 10:20 am

    Thank you. saved lot of time

  30. Avatar sd Reply
    January 18, 2018 at 1:35 pm

    Download Path incorrect

  31. Avatar Giri Reply
    January 5, 2018 at 12:41 am

    Even after following the instructions, the java version on my Centos is still at 1.7. I can see the folders for 1.8 are created but ‘java -version’ still returns 1.7. Any reasons?

    • Avatar madhukar Reddy Reply
      January 9, 2018 at 5:52 am

      instructions messed up the root login PATH

      subsequent root login gives these errors
      Last login: Tue Jan 9 00:45:24 2018 from 116.74.251.1
      bash: tty: command not found…
      Similar command is: ‘tty’
      bash: ls: command not found…
      Similar command is: ‘lz’
      /usr/libexec/grepconf.sh: line 5: grep: command not found
      bash: grep: command not found…
      bash: grep: command not found…
      bash: uname: command not found…

      • Avatar madhukar Reddy Reply
        January 9, 2018 at 6:08 am

        Found the problem. Last instruction to update /etc/environment messing up login.

        Removed the contents of /etc/environment and it works fine.

        For generic java 8 I would suggest the following

        cd /opt
        ln -s /opt/jdk1.8.0_151 jdk1.8
        export JAVA_HOME=/opt/jdk1.8
        export JRE_HOME=/opt/jdk1.8/jre
        export PATH=$PATH:/opt/jdk1.8/bin:/opt/jdk1.8/jre/bin

        • Avatar Noor Reply
          February 7, 2018 at 8:10 am

          I have same issue but unfortunately i cannot edit /etc/environment file now, due to change in this file i am unable to run any command from my user even i cannot run sudo, sudo su or ls chown etc..
          I am working on AWS Linux instance.
          please help i can access files via ssh and winscp but with no permission to edit.

  32. Avatar Giri Reply
    January 4, 2018 at 12:23 pm

    After following the instructions, my java version is still at 1.7. It has not changed to 1.8. Any reasons?

  33. Avatar ged Reply
    December 18, 2017 at 9:01 pm

    crap, it did not work

    • Rahul Rahul K. Reply
      December 19, 2017 at 4:47 am

      Hi Ged. What issue are you facing?

  34. Avatar Reshma Reply
    November 27, 2017 at 6:36 pm

    This is really saved my time. Thanks!

  35. Avatar shaun Reply
    November 9, 2017 at 11:37 pm

    Please update step 1. to tar xzf jdk-8u151-linux-x64.tar.gz. It still says tar xzf jdk-8u144-linux-x64.tar.gz

    • Rahul Rahul K. Reply
      November 10, 2017 at 3:19 am

      Thanks, Shaun to point out… The tutorial has been updated.

  36. Avatar Daniel Reply
    October 26, 2017 at 5:05 pm

    Hi!

    Apparently it’s going to work yes but i am having a problem with this command:

    wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u152-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz” Changed it to the last arquive (152)

    It’s coming with 404 not found HTTP request, can you help me, please?

  37. Avatar David Reply
    October 14, 2017 at 10:09 pm

    Thank you so much Tecadmin.net! I love this post, THANK YOU!

  38. Avatar chetan Reply
    September 1, 2017 at 10:16 am

    Thank you for the tutorial it saves a lot of time now.

  39. Avatar BugsDanny Reply
    August 23, 2017 at 1:43 pm

    Thank you! amazing and usefull tutorial! just what i need!.

  40. Avatar suman Reply
    August 7, 2017 at 6:06 am

    Its was a great article for java config also had clear approach to solve the install conflicts for Jenkins installation. Thanks a lot I look forward for your future articles.

  41. Avatar Boboto Reply
    August 1, 2017 at 10:03 pm

    Thank you very much for this rewarding article! It was worth the try

  42. Avatar Jaydeep Reply
    July 18, 2017 at 3:00 pm

    Hi,

    I am not sure what I did wrong while installing java 1.8
    I have followed the same steps as mentioned but when checking for JAVA version, it says 1.7.0.67 rather than 1.8.

    [[email protected] jdk1.8.0_131]# java -version
    java version “1.7.0_67”
    Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
    Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

    • Avatar Deepak A Reply
      December 4, 2017 at 11:48 am

      Hi Jaydeep,
      Could you please let me know if you could resolve this? I am stuck at this point and don’t know how to proceed. I believe this is the reason I am not able to proceed with my SparkR set up too and getting the below error:
      ————————————————–
      > sc = sparkR.session(master=’local’)
      Spark package found in SPARK_HOME: /home/cloudera/.cache/spark/spark-2.2.0-bin-hadoop2.7
      Launching java with spark-submit command /home/cloudera/.cache/spark/spark-2.2.0-bin-hadoop2.7/bin/spark-submit “–conf” “spark.debug.maxToStringFields=100” /tmp/RtmpvEvWZD/backend_port2cd67996e589
      Error: Cannot load main class from JAR file:/tmp/RtmpvEvWZD/backend_port2cd67996e589
      Run with –help for usage help or –verbose for debug output
      Error in sparkR.sparkContext(master, appName, sparkHome, sparkConfigMap, :
      JVM is not ready after 10 seconds

  43. Avatar Roberto Marquez Reply
    June 28, 2017 at 3:06 pm

    Thanks, I needed a way to upgrade Java from the server (command line).

  44. Avatar Marc Raygoza Reply
    June 16, 2017 at 9:50 pm

    Great article. Worked perfectly

  45. Avatar Eduardo Felipe Reply
    June 9, 2017 at 1:33 pm

    Thank you, these were very especific and easy to follow instructions.

  46. Avatar Ryanto Reply
    May 23, 2017 at 3:30 am

    Hello could you explain more specific on what we’re doing on
    “Also put all above environment variables in /etc/environment file for auto loading on system boot.” on the last step. /

  47. Avatar R.Muthukumar Reply
    April 26, 2017 at 12:48 pm

    Hi Team,

    After exporting the path, ls command and most of the command is not working. Could you please help me on this. I am so tired.

    • Avatar Vergi Reply
      November 9, 2017 at 11:04 am

      Did you solve your problem on this?

      • Rahul Rahul K. Reply
        November 9, 2017 at 11:40 am

        Hi Vergi,

        Make sure you have included $PATH: in command like

        export PATH=$PATH:

  48. Avatar Ayoub Reply
    April 21, 2017 at 5:44 pm

    I don’t understand the Setup “Install Java with Alternatives”???.?

  49. Avatar yo! Reply
    April 19, 2017 at 11:54 am

    Thanks man!

  50. Avatar Paolo Reply
    April 8, 2017 at 9:11 am

    Thank you very much!

  51. Avatar David B. Reply
    February 6, 2017 at 8:51 am

    Used this to install it on 32 bit CEntos 6.5 successfully, great work!

  52. Avatar Mo Chi Reply
    January 25, 2017 at 3:55 am

    Thank you so much.

  53. Avatar Fher Reply
    September 13, 2016 at 7:43 pm

    Hi. From I run this commands:
    echo “export JAVA_HOME=/opt/jdk1.8.0_51” > /etc/profile.d/jre.sh
    echo “export JRE_HOME=/opt/jdk1.8.0_51/jre” >> /etc/profile.d/jre.sh
    echo “export PATH=$PATH:/opt/jdk1.8.0_51/bin:/opt/jdk1.8.0_51/jre/bin” >> /etc/profile.d/jre.sh

    I am getting this when I open the terminal

    bash: $’\342\200\234export’:order not found
    bash: $’\342\200\234export’: order not found
    bash: $’\342\200\234export’: order not found
    [[email protected] ~]$

    How this could affects?
    Thanks a lot

    • Avatar Rubens Pinto Reply
      November 17, 2016 at 1:22 am

      See if you have a JRE.SH on /etc/profile.d

      I had this one and was point to a old java version. Just deleted and is working fine.

    • Avatar Max Pavlov Reply
      November 24, 2016 at 2:05 pm

      1. Remove your jre.sh via rm /etc/profile.d/jre.sh
      2. Use these commands to correctly export variables:

      echo ‘export JAVA_HOME=”/opt/jdk1.8.0_111″‘ >> /etc/profile.d/jre.sh
      echo ‘export JRE_HOME=”/opt/jdk1.8.0_111″‘ >> /etc/profile.d/jre.sh
      echo ‘export PATH=”$PATH:/opt/jdk1.8.0_111/bin:/opt/jdk1.8.0_111/jre/bin”’ >> /etc/profile.d/jre.sh

      Reboot the machine and you’ll be fine.

  54. Avatar FherPie Reply
    September 13, 2016 at 7:40 pm

    Hi. From I run this commands:
    echo “export JAVA_HOME=/opt/jdk1.8.0_51” > /etc/profile.d/jre.sh
    echo “export JRE_HOME=/opt/jdk1.8.0_51/jre” >> /etc/profile.d/jre.sh
    echo “export PATH=$PATH:/opt/jdk1.8.0_51/bin:/opt/jdk1.8.0_51/jre/bin” >> /etc/profile.d/jre.sh

    I am getting this when I open the terminal

    bash: $’\342\200\234export’:order not found
    bash: $’\342\200\234export’: order not found
    bash: $’\342\200\234export’: order not found
    [[email protected] ~]$

    How this could affects?
    Thanks a lot

  55. Avatar Amir Bahmanyari Reply
    August 11, 2016 at 11:27 pm

    Works perfectly as is. Put your env. vars in $HOME/.bashrc (if bash is the preferred shell). And you are all set.

  56. Avatar Juan Carlos Paz H Reply
    July 21, 2016 at 3:31 am

    Thanks , Seguí estos pasos en un sistema operativo oracle Linux y todo fue correcto muchas gracias me ahorro mucho tiempo

  57. Avatar hayam Reply
    July 6, 2016 at 2:39 pm

    Hi, this is an amazing post, and I benefited a lot ! But I met a problem. After installing, i checked the version and it was successful. However, I wanted to use the java 1.8 on system boot, and as you suggested I put the last three commands in the “/etc/environment” file. However, after I did that, my machine is not starting (my machine is a CentOS machine created with Cloudera training vm with help of virtualbox), and giving the following error:

    Starting jexec servicesDevice, “eth0” does not exist

    Do you know what is wrong ? Can you please reply ? Thanks !

  58. Avatar Matt Reply
    July 6, 2016 at 7:26 am

    Could any one advise on how to sort out the envionment paths properly on Centos 7? Putting them as written in the article in /etc/environment messes up the path meaning normal commands are missing from /bin/.

    • Avatar Andre Reply
      August 14, 2016 at 6:12 pm

      Yes I also have this issue.

  59. Avatar Anna Reply
    June 29, 2016 at 3:34 pm

    Thank you. This article was really helpful.

    One difference: setting the variables in /etc/environment file almost disabled the bash shell on my CentOS 7. So I defined them in /etc/profile.d/custom.sh, it works.

    It was the line with “$PATH” that had spoiled /etc/environment.
    I used a command “/bin/sudo mc” to edit /etc/environment again and fix the problem.

  60. Avatar Jeremy Reply
    June 27, 2016 at 2:57 pm

    Thanks for the awesome instructions! I ran into one issue that someone else may have already mentioned, but I did not see it. On ubuntu Alternatives has been replaced with update-alternatives. hope that saves someone a minute or two.

  61. Avatar Diogo Reply
    June 20, 2016 at 1:44 pm

    Thanks

  62. Avatar pkpdeveloper Reply
    June 19, 2016 at 7:58 am

    Thanks Great Tutorial.Perfect

  63. Avatar Ashok Reply
    June 13, 2016 at 12:22 pm

    This is a very good article. Concise and proper steps to setup java on any Linux box. Make a shell script with all the above commands and run it every-time you need to setup java

  64. Avatar Kevin Emery Reply
    March 4, 2016 at 5:40 am

    This was rather useful, thank you

  65. Avatar J Reply
    February 23, 2016 at 12:19 am

    I removed the step of setting environment file which was empty on my machine, because adding those lines to environment file caused serious problem (path lost).

  66. Avatar Sriram Reply
    January 19, 2016 at 7:38 am

    Helped me in setting up on linode VPS when all other tutorials failes. Simple, hats off rahul

  67. Avatar Dcf Reply
    January 1, 2016 at 8:04 am

    Excellent nicely explained the steps. thanks.

  68. Avatar ademian Reply
    December 21, 2015 at 10:17 pm

    Now, you have to change: download.oracle.com by edelivery.oracle.com

    • Rahul Rahul Reply
      December 23, 2015 at 6:58 am

      Hi Ademian,

      Yes edelivery.oracle.com is also working but it still redirecting (302) to download.oracle.com.

  69. Avatar AShutosh Reply
    November 4, 2015 at 1:57 pm

    I tried on ubuntu 14 and it worked.
    only deviation”
    I wrote
    export JAVA_HOME=/opt/jdk1.8.0_66
    export JRE_HOME=$JAVA_HOME/jre
    export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
    into ~/.profile

  70. Avatar Chris Reply
    August 26, 2015 at 4:52 pm

    Install is the easy part, but can anyone note the reason why you can no longer perform a “yum update jdk” with version 1.8. I have noticed that once the package is installed, the package name format is different than in versions 1.7 and 1.6.

    Where 1.7 was formatted like so: jdk-1.7.0_80

    Version 1.8 is now formatted like this: jdk1.8.0_60

    This does not allow for a yum update in CentOS or Red Hat.

    Thanks for any leads on this. It’s a real pain to manually update. Though I see a benefit in that you would not “yank out” the current version out from under your running java applications. It does appear to make the upgrade safer, but manual too.

    Thanks,

  71. Avatar Mark Smith Reply
    August 21, 2015 at 8:31 am

    For me, putting the “export PATH” stuff in /etc/environment causes all users to get thrown out when logging into the GUI.
    Instead, do this:
    echo “export JAVA_HOME=/opt/jdk1.8.0_51” > /etc/profile.d/jre.sh
    echo “export JRE_HOME=/opt/jdk1.8.0_51/jre” >> /etc/profile.d/jre.sh
    echo “export PATH=$PATH:/opt/jdk1.8.0_51/bin:/opt/jdk1.8.0_51/jre/bin” >> /etc/profile.d/jre.sh

    • Avatar Ankur Reply
      September 2, 2015 at 1:58 pm

      Hi Mark,

      I too put the “export PATH” stuff in /etc/environment and tried to restart my machine.
      Since then i am not able to login back into my Ubuntu machine. ;-(

      Could you please tell how i can get the login thing working again in my system ?

      So that i can apply the changes suggested in your post.

      • Avatar Paul Offord Reply
        October 17, 2015 at 2:24 pm

        Hi,

        I had this problem too with Centos 7. The reason is that if you put the entries in /etc/environment it messes up the PATH environment setting which includes removing reference to /bin.

        To recover do the following:

        1. Ctl-Alt-F2 to switch to a command line console
        2. Login with your account details – you’ll get errors as the shell script runs but don’t worry for the moment
        3. Enter the command PATH=$PATH:/bin
        4. Enter the command startx
        5. Once the desktop appears open a terminal session
        6. Enter the command su –
        5. Enter your root password at the prompt
        6. Again, enter PATH=$PATH:/bin
        7. Enter the command gedit /etc/environment
        8. Delete all lines in the file and save
        9. Restart Centos

        Best regards…Paul

        • Avatar sachin phadtare Reply
          August 5, 2017 at 9:34 am

          Thank a lot Paul

        • Avatar Dawood Reply
          August 7, 2017 at 2:11 am

          Hi, i messed up my centos 6 machine. i have the same problem. but i try to do what you have explained here, the instruction # 4 does not work. it says -bash: comand not found.

          am really having a terrible time

    • Avatar FherPie Reply
      September 13, 2016 at 6:08 pm

      Hi everyone I would to know how resolve this:

      bash: $’\342\200\234export’: order not found
      bash: $’\342\200\234export’: order not found
      bash: $’\342\200\234export’: order not found
      [[email protected] ~]$

      This happens from that I “installed java or detroyed with java my pc” I don’t know why:
      I have done this:
      echo “export JAVA_HOME=/opt/jdk1.8.0_101” > /etc/profile.d/jre.sh
      echo “export JRE_HOME=/opt/jdk1.8.0_101/jre” >> /etc/profile.d/jre.sh
      echo “export PATH=$PATH:/opt/jdk1.8.0_101/bin:/opt/jdk1.8.0_101/jre/bin” >> /etc/profile.d/jre.sh
      according to Mark Smith user. All run fine. after Reboot I get that message in my terminal.
      I am afraid. Because I don’t know if this affects only to java or all my apps in mi machine Centos7

  72. Avatar Peter Reply
    August 5, 2015 at 11:42 am

    I cannot install to Centos 6.X.

    I got the following error message:
    # java -version
    -bash: /usr/bin/java: cannot execute binary file

    It is file permission problem or something else?

    • Rahul Rahul Reply
      August 5, 2015 at 1:11 pm

      Hi Peter,

      Did you executed alternatives commands properly ?

      • Avatar Xavo Reply
        July 23, 2016 at 6:17 pm

        I cannot install to Centos 6.X. even I executed alternatives cmd properly

        I got the following error message:
        # java -version
        -bash: /usr/bin/java: cannot execute binary file

  73. Avatar ankit Reply
    July 15, 2015 at 6:48 am

    nice, not sure about export part but rest is helpfull

  74. Avatar Kamal Reply
    June 23, 2015 at 6:40 am

    Thanks a lot

  75. Avatar bmil Reply
    May 29, 2015 at 9:45 pm

    export PATH=$PATH:/opt/jdk1.8.0_45/bin:/opt/jdk1.8.0_45/jre/bin
    Also put all above environment variables in /etc/environment file for auto loading on system boot.

    export is not working, when you put it in /etc/environment file

    export is shell command and /etc/environment process only static variables
    variable=value

  76. Avatar Reyes Reply
    May 7, 2015 at 5:34 pm

    I followed yout guifr but I didn’t manage to install Java on my server so I asked my hosting provider (RoseHosting)to install Java for me. Thank you.

  77. Avatar Felix Reply
    April 25, 2015 at 1:28 am

    I tried to install on a RHEL5.10 server, but I got error when I checked the java version
    java –version
    Unrecognized option: –version
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.

    Please help!

    • Rahul Rahul Reply
      April 25, 2015 at 3:04 am

      HI Felix,

      Make sure you are using single hyphen ( – ) with option -version.

  78. Avatar ankuj Reply
    April 23, 2015 at 2:08 pm

    Work …centos 6.6
    can any one tell me what exactly “alternatives” command doing here.

  79. Avatar Tony Reply
    April 16, 2015 at 1:56 pm

    Followed the instructions and it worked like a charm. Thanks much Rahul.

  80. Avatar Tapas Reply
    April 9, 2015 at 4:10 am

    Hi Admin,

    I have followed your steps but getting following error when running command ‘java -version’

    -bash: /usr/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

    • Rahul Rahul Reply
      April 9, 2015 at 4:13 am

      Hey Tapas,

      You have downloaded wrong java archive as your system architecture. Check your system architecture using command below and download correct java archive.

       uname -m
      
    • Avatar Oscar Reply
      May 10, 2016 at 10:04 pm

      a little late, but for anyone having this error maku sure you used the sudo command, so:
      sudo wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz”

  81. Avatar Smith Reply
    February 3, 2015 at 2:00 pm

    Working nice…. thanks for easy steps…..

  82. Avatar Jonathan Willis Reply
    January 21, 2015 at 11:15 pm

    Following these instructions on CentOS 6 I get this error:

    /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

    • Rahul Rahul Reply
      April 9, 2015 at 4:16 am

      Hi Jonathan,

      You have downloaded wrong java archive as your system architecture. Check your system architecture using command below and download correct java archive.

      uname -m

  83. Avatar Jonathan Willis Reply
    January 21, 2015 at 11:14 pm

    Following these instructions on CentOS 6 I get this error:

    http://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/

  84. Avatar Jay Reply
    January 7, 2015 at 1:31 pm

    Hello sir, Im trying to install the latest java on my VPS to run a simple .jar file and the 1st step “tar xzf jdk-8u25-linux-x64.tar.gz” returns

    # tar xzf jdk-8u25-linux-x64.tar.gz
    tar (child): jdk-8u25-linux-x64.tar.gz: Cannot open: No such file or directory
    tar (child): Error is not recoverable: exiting now
    tar: Child returned status 2
    tar: Error is not recoverable: exiting now

    Running “uname -a” returns , which I presume is 64bit, Im using Centos 6. #1 SMP Mon Aug 11 18:47:39 MSK 2014 x86_64 x86_64 x86_64 GNU/Linux. I tried installing via both SSH and terminal of the VPS itself. Both returned the same result, what have I done wrong? Any help would be greatly appreciated.

  85. Avatar KENT Reply
    December 27, 2014 at 6:05 pm

    Thank you for this clear, easy-to-follow guide! With it I quickly installed Java 8 update 25.

    • Rahul Rahul Reply
      April 9, 2015 at 4:18 am

      Thanks Kent

  86. Avatar david+ Reply
    December 22, 2014 at 10:02 pm

    Yo no pude usar el mismo comando y use este “update-alternatives” y solo así pude lograrlo.

  87. Avatar Cyndy Looper Reply
    December 9, 2014 at 11:12 am

    Thanks alot i used it to install it on 32 bit CEntos 6.5 successfully.
    WHen i tried to set up the environment variables . I got no report whatsoever after running your code. Hope i got it correctly?

  88. Avatar ardhan Reply
    November 16, 2014 at 9:24 am

    This work… thanks a lot

  89. Avatar Alejandro Reply
    November 1, 2014 at 1:56 pm

    This is a great concise article, working fine to centOs 6.5, thanks a lot.

  90. Avatar Chris Reply
    October 28, 2014 at 9:57 am

    This is a great concise article. Thank you.

  91. Avatar felipe1982 Reply
    October 28, 2014 at 6:40 am

    you can append `-O jdk-8u25-linux-x64.tar.gz` to your wget line so that it renames it appropriately.

  92. Avatar Kent Reply
    October 24, 2014 at 10:19 pm

    This helped me with RedHat Linux 6. Thank you!

  93. Avatar Ying Reply
    October 15, 2014 at 2:23 am

    Thanks for the instructions first. I followed all the steps on CentOS. However, I got No such file or directory after typing “java -version”. Any idea what might have caused it?

    • Avatar Brad Reply
      July 16, 2015 at 4:35 am

      Ying, I had the same issue. I followed the steps exactly but when I tried to test that it was working I kept getting “No such file or directory”. I tried another version of java with the same results. Finally I traced it to (I think) to the alternative command. It seems it could not creating the symbolic link correctly between “/etc/alternatives” and “/opt/jdk1.8.0_45/bin/java”.
      I deleted the existing link “”/etc/alternatives/java” and then recreated it:

      ln -s /opt/jdk1.8.0_45/bin/java java

      and now the command “java -version” displays:
      java version “1.8.0_45”
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) Server VM (build 25.45-b02, mixed mode)

  94. Avatar Mazhar Reply
    September 22, 2014 at 12:43 pm

    Thanks a lot, very useful article. 🙂

  95. Avatar Rob Reply
    September 14, 2014 at 10:33 am

    Great article thanks

  96. Avatar Mauricio Reply
    August 29, 2014 at 4:31 pm

    Working fine to centOs 6.5, thanks a lot.

  97. Avatar Musta Reply
    August 28, 2014 at 1:05 am

    This work for Fedora 20?

  98. Avatar Ravikiran Patil Reply
    August 20, 2014 at 3:25 pm

    Thank you so much Rahul Kumar……. 🙂 This article is the best article that I found.

  99. Avatar Leo Reply
    April 30, 2014 at 4:18 pm

    Thank you so much.

    Maybe useful for other readers:
    – On a vanilla fedora (or at least on my system), ‘alternatives’ doesn’t seem to be in the path, so the full path has to be specified:
    sudo /usr/sbin/alternatives –install /usr/bin/java java /opt/jdk1.8.0_05/bin/java 2
    sudo /usr/sbin/alternatives –config java

    – In case folks are not familar, the export commands can go into ~/.bash_profile , but careful not to overwrite your existing “PATH”, instead append to it. This is an example of my ~/.bash_profile
    # .bash_profile

    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

    # User specific environment and startup programs

    PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/Dropbox/Apps/Bash_path_linux/:/opt/jdk1.8.0_05/bin:/opt/jdk1.8.0_05/jre/bin

    export JAVA_HOME=/opt/jdk1.8.0_05
    export JRE_HOME=/opt/jdk1.8.0_05/jre
    export PATH

    Hope it helps.

    • Avatar Jay Reply
      January 7, 2015 at 1:30 pm

      Hello sir, Im trying to install the latest java on my VPS to run a simple .jar file and the 1st step “tar xzf jdk-8u25-linux-x64.tar.gz” returns

      # tar xzf jdk-8u25-linux-x64.tar.gz
      tar (child): jdk-8u25-linux-x64.tar.gz: Cannot open: No such file or directory
      tar (child): Error is not recoverable: exiting now
      tar: Child returned status 2
      tar: Error is not recoverable: exiting now

      Running “uname -a” returns , which I presume is 64bit, Im using Centos 6. #1 SMP Mon Aug 11 18:47:39 MSK 2014 x86_64 x86_64 x86_64 GNU/Linux. I tried installing via both SSH and terminal of the VPS itself. Both returned the same result, what have I done wrong? Any help would be greatly appreciated.

      • Rahul Rahul Reply
        April 9, 2015 at 4:18 am

        Hi Jay,

        It looks jdk-8u25-linux-x64.tar.gz is not available at current directory. Make sure the file exists there with correct name.

        • Avatar Sumit Sahay Reply
          September 14, 2018 at 10:16 am

          Hi Rahul,

          I am trying to install jenkins on my centos vm instance but unable to do so as its need java 8 and the java version in my system is 1.7. Now, I am trying to update the java version but due to proxy issue I am getting error so I downloaded the java 8 couple of times “jre-8u181-linux-x64.rpm” and whenever I am trying to execute this rpm file, like below,
          sudo yum install jre-8u181-linux-x64.rpm
          But I am getting error like below,
          Trying other mirror.
          Error: Cannot retrieve repository metadata (repomd.xml) for repository: local. Please verify its path and try again

          Could you please navigate me to the correct direction.

          Looking forward for your reply.

          Regards
          Sumit Sahay

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Debian 10
  • Download Ubuntu 20.04 LTS – DVD ISO Images
  • Linux Run Commands As Another User
  • How to Check PHP Version (Apache/Nginx/CLI)
  • How To Install and Configure GitLab on Ubuntu 20.04
  • How to Install PyCharm on Ubuntu 20.04
  • How to Check Ubuntu Version with Command or Script
  • How to Set all directories to 755 And all files to 644
© 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy