Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»JAVA»How to Install JAVA 8 on CentOS/RHEL 7/6 and Fedora 28-23

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

    By RahulSeptember 7, 20223 Mins Read

    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.

    Advertisement

    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 is used to create, remove, maintain and display 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 is 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 Java-based applications use environment variables to work. Set the Java environment variables using the 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.

    Java java 8 Java_home jdk jdk-jre jre jre_home openjdk oracle java sun java
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Set JAVA_HOME environment variable on macOS

    How to Set JAVA_HOME environment variable on macOS

    What is the Access Modifiers in Java

    What are the Access Modifiers in Java

    Installing Java on Ubuntu 22.04

    How to Install JAVA on Ubuntu 22.04

    View 139 Comments

    139 Comments

    1. G0LDEN_key on June 26, 2019 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)
      $

      Reply
    2. Rahul on May 24, 2019 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.

      Reply
    3. roland on April 28, 2019 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

      Reply
    4. Zsolt on April 20, 2019 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.

      Reply
      • paul on May 2, 2019 11:24 am

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

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

      Thanks too much.

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

      Thanks buddy.
      Helped alot.

      Reply
    7. Shubham Singh on February 13, 2019 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.

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

      Big thanks

      Reply
    9. IvanG on December 10, 2018 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

      Reply
    10. jayBird on December 7, 2018 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!

      Reply
    11. Ravi on November 29, 2018 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.

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

        Hi Ravi,

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

        Reply
        • Massimo Coreni on April 17, 2019 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

          Reply
    12. Sumit Sahay on September 14, 2018 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

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

        Try below command:

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

        Reply
        • siva on November 29, 2018 11:58 am

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

          Reply
    13. Santiago Alamos on August 29, 2018 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

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

        Thanks Alamos, tutorial has been updated.

        Reply
    14. Pulkit on August 19, 2018 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?

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

      Very helpful and clearly documented. Thanks Rahul

      Reply
    16. Colin on July 11, 2018 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.

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

      nice expalnation its worked for me

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

      nice article
      tq

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

      Works like a charm, thank you Rahul!

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

      Fantastic article, thank you!

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

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

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

        Try:

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

        Reply
    22. shahama on April 2, 2018 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?

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

        Yes, it will work with Java upgrade also.

        Reply
        • shahama on April 12, 2018 4:54 am

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

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

      Thank you. It helps a lot and working.

      Reply
    24. Neeraj Sharma on March 11, 2018 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.

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

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

      Reply
      • sripada sarma on April 7, 2018 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.

        Reply
    26. Noor on February 7, 2018 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.

      Reply
      • Victo on February 24, 2018 4:08 pm

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

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

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

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

      Good tutorial. Thank you!

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

      Thank you, very usefyll!

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

      Thank you. saved lot of time

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

      Download Path incorrect

      Reply
    31. Giri on January 5, 2018 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?

      Reply
      • madhukar Reddy on January 9, 2018 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…

        Reply
        • madhukar Reddy on January 9, 2018 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

          Reply
          • Noor on February 7, 2018 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.

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

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

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

      crap, it did not work

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

        Hi Ged. What issue are you facing?

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

      This is really saved my time. Thanks!

      Reply
    35. shaun on November 9, 2017 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

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

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

        Reply
    36. Daniel on October 26, 2017 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?

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

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

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

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

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

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

      Reply
    40. suman on August 7, 2017 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.

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

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

      Reply
    42. Jaydeep on July 18, 2017 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)

      Reply
      • Deepak A on December 4, 2017 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

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

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

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

      Great article. Worked perfectly

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

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

      Reply
    46. Ryanto on May 23, 2017 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. /

      Reply
    47. R.Muthukumar on April 26, 2017 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.

      Reply
      • Vergi on November 9, 2017 11:04 am

        Did you solve your problem on this?

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

          Hi Vergi,

          Make sure you have included $PATH: in command like

          export PATH=$PATH:

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

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

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

      Thanks man!

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

      Thank you very much!

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

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

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

      Thank you so much.

      Reply
    53. Fher on September 13, 2016 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

      Reply
      • Rubens Pinto on November 17, 2016 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.

        Reply
      • Max Pavlov on November 24, 2016 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.

        Reply
    54. FherPie on September 13, 2016 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

      Reply
    55. Amir Bahmanyari on August 11, 2016 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.

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

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

      Reply
    57. hayam on July 6, 2016 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 !

      Reply
    58. Matt on July 6, 2016 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/.

      Reply
      • Andre on August 14, 2016 6:12 pm

        Yes I also have this issue.

        Reply
    59. Anna on June 29, 2016 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.

      Reply
    60. Jeremy on June 27, 2016 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.

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

      Thanks

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

      Thanks Great Tutorial.Perfect

      Reply
    63. Ashok on June 13, 2016 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

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

      This was rather useful, thank you

      Reply
    65. J on February 23, 2016 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).

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

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

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

      Excellent nicely explained the steps. thanks.

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

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

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

        Hi Ademian,

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

        Reply
    69. AShutosh on November 4, 2015 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

      Reply
    70. Chris on August 26, 2015 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,

      Reply
    71. Mark Smith on August 21, 2015 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

      Reply
      • Ankur on September 2, 2015 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.

        Reply
        • Paul Offord on October 17, 2015 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

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

            Thank a lot Paul

            Reply
          • Dawood on August 7, 2017 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

            Reply
      • FherPie on September 13, 2016 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

        Reply
    72. Peter on August 5, 2015 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?

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

        Hi Peter,

        Did you executed alternatives commands properly ?

        Reply
        • Xavo on July 23, 2016 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

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

      nice, not sure about export part but rest is helpfull

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

      Thanks a lot

      Reply
    75. bmil on May 29, 2015 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

      Reply
    76. Reyes on May 7, 2015 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.

      Reply
    77. Felix on April 25, 2015 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!

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

        HI Felix,

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

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

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

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

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

      Reply
    80. Tapas on April 9, 2015 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

      Reply
      • Rahul on April 9, 2015 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
        
        Reply
      • Oscar on May 10, 2016 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”

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

      Working nice…. thanks for easy steps…..

      Reply
    82. Jonathan Willis on January 21, 2015 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

      Reply
      • Rahul on April 9, 2015 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 Reply

  • Jonathan Willis on January 21, 2015 11:14 pm

    Following these instructions on CentOS 6 I get this error:

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

    Reply
  • Jay on January 7, 2015 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.

    Reply
  • KENT on December 27, 2014 6:05 pm

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

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

      Thanks Kent

      Reply
  • david+ on December 22, 2014 10:02 pm

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

    Reply
  • Cyndy Looper on December 9, 2014 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?

    Reply
  • ardhan on November 16, 2014 9:24 am

    This work… thanks a lot

    Reply
  • Alejandro on November 1, 2014 1:56 pm

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

    Reply
  • Chris on October 28, 2014 9:57 am

    This is a great concise article. Thank you.

    Reply
  • felipe1982 on October 28, 2014 6:40 am

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

    Reply
  • Kent on October 24, 2014 10:19 pm

    This helped me with RedHat Linux 6. Thank you!

    Reply
  • Ying on October 15, 2014 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?

    Reply
    • Brad on July 16, 2015 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)

      Reply
  • Mazhar on September 22, 2014 12:43 pm

    Thanks a lot, very useful article. 🙂

    Reply
  • Rob on September 14, 2014 10:33 am

    Great article thanks

    Reply
  • Mauricio on August 29, 2014 4:31 pm

    Working fine to centOs 6.5, thanks a lot.

    Reply
  • Musta on August 28, 2014 1:05 am

    This work for Fedora 20?

    Reply
  • Ravikiran Patil on August 20, 2014 3:25 pm

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

    Reply
  • Leo on April 30, 2014 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.

    Reply
    • Jay on January 7, 2015 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.

      Reply
      • Rahul on April 9, 2015 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.

        Reply
        • Sumit Sahay on September 14, 2018 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

          Reply
  • Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.