Install JAVA (Oracle JAVA & openJDK) via JAVA Alternatives Method

JAVA is necessary to run certain applications in Linux and windows environment. I already installed OpenJDK 7 in my system and I’m going to install oracle java 8 using java alternatives method which is very simple and handy. Just dig our article.

List of method to install JAVA on Linux

1) Check current java version

Use the below command to check installed java version on your system.

$ java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.15.10.1)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)

The output clearly shows that, i have already installed OpenJDK 7 in my system.

2) Download oracle java archive file

Use the below command to download the oracle java 8 archive file. Make sure oracle uses cookies, so use according to that.

[Downloading Oracle Java 8 archive file]
$ 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/8u66-b17/jdk-8u66-linux-x64.tar.gz"

3) Extract the archive file

Use the below tar command to extract the tar.gz archive file.

[Extract Oracle Java Archive file]
$ sudo tar -zxvf jdk-8u66-linux-x64.tar.gz

4) Install oracle java 8 using Alternatives Method

Use the below command to Install oracle java 8 on your system using JAVA alternatives method. Make sure you need to mention your java path (Newly downloaded)

[Install Oracle Java using Java Alternatives Method]
$ sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_66/bin/java 2

5) Choose alternative java version

Use the below command to list installed java version on your system. Here i’m going to choose oracle java 8 which is installed newely on my system. just enter the number which is showing under Selection area to switch to alternative version of java.

[Setup Newly installed java version as a default]
$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /opt/jdk1.8.0_66/bin/java                        2         manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode

Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /opt/jdk1.8.0_66/bin/java to provide /usr/bin/java (java) in manual mode

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...

  • Lucas

    en el cuarto paso, no me encuentra la ruta alternativa opt/jdk1.8….dice que no existe.

  • Dickson Kemboi

    Much thanks, quite elaborative, just enabled me put it on Chapeau Linux. I am happy, thanks

  • Un servicio de posicionamiento web te garantiza más visitas y altamente cualificadas
    y también interesadas en tus servicios.

  • Dinika

    This is an amazing guide. It really did help a lot. Thanks so much!
    I was stuck at step 4, but then I used the following command to uncompress my tar files in /opt/ (of course I googled it!):
    sudo tar -zxvf jdk-8u20-linux-x64.tar.gz -C /opt/

  • Follow the steps and you will be Celebrating!!!

  • @CV ,
    Glad to hear.

  • CV

    Great post, thanks! though, for 32bit systems you have to use the 32 bit package, obviously

  • @Francisco,

    Its a file path. Also read the below article for further clarification.
    https://www.2daygeek.com/how-to-setup-java-environment-variable-in-linux/

  • Francisco

    Excelent work!

    But I have a dude:

    the JAVA_HOME and JRE_HOME variables, are there paths to a directory?
    export JAVA_HOME=/opt/jdk1.8.0_20/bin
    export JRE_HOME=/opt/jdk1.8.0_20/bin

    or are there paths to a file?
    export JAVA_HOME=/opt/jdk1.8.0_20/bin/java
    export JRE_HOME=/opt/jdk1.8.0_20/bin/jar

    regards

  • @Alex,
    Welcome

  • Alex

    Great tutorial, very easy to follow and just the right amount of explanation. Thank you.

  • @Dana Tontea,

    Welcome.

  • Dana Tontea

    great tutorial! thanks

  • @tiomte ,

    For manual software installing, i advise you to download and extract the software package to /opt or /usr/local/src
    directory.

    In step-4 first part is java global location so you need to put the same like below.
    sudo update-alternatives –install /usr/bin/java java (second part – you need mention your new java directory where you extracted the java on your system)

  • tiomte

    how can i find my path in step 4?

  • 2daygeek

    @Lawrence (MrLordLaw),

    You are most welcome.

  • Lawrence (MrLordLaw)

    It takes time for me because i downloaded it at /home/lordlaw
    I’ve been stuck at step 4 or the installing process -_- HAHA but it’s okay I googled it and copy the files to /opt but it’s not that easy because i need to log in in terminal as the root 🙂 and that’s why I’m very thankful to google!!! ^_^
    And ofcourse for this Guide Thank you so much!! muwah!!! love you! xD
    I’m just very happy! thank you for the easy guideliness!

    God Bless you! :))

  • 2daygeek

    @DC Mishra,

    I have slightly modified the command and its start downloading now, pls use below command and let me know.

    # 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/8u20-b26/jdk-8u20-linux-i586.tar.gz”

    • D C Mishra

      Your modified command is not working too-
      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/8u20-b26/jdk-8u20-linux-i586.tar.gz”–2014-08-28 21:26:58– http://xn--no-cookies-nu6e/
      Resolving –no-cookies (xn--no-cookies-nu6e)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--no-cookies-nu6e’
      –2014-08-28 21:27:03– http://xn--no-cookies-nu6e/
      Resolving –no-cookies (xn--no-cookies-nu6e)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--no-cookies-nu6e’
      –2014-08-28 21:27:03– http://xn--no-check-certificate-2t2l/
      Resolving –no-check-certificate (xn--no-check-certificate-2t2l)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--no-check-certificate-2t2l’
      –2014-08-28 21:27:03– http://xn--no-check-certificate-2t2l/
      Resolving –no-check-certificate (xn--no-check-certificate-2t2l)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--no-check-certificate-2t2l’
      –2014-08-28 21:27:03– http://xn--header-vg0c/
      Resolving –header (xn--header-vg0c)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--header-vg0c’
      –2014-08-28 21:27:03– http://xn--header-vg0c/
      Resolving –header (xn--header-vg0c)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--header-vg0c’
      –2014-08-28 21:27:03– ftp://xn--cookie-oi0c/
      => ‘.listing’
      Resolving “cookie (xn--cookie-oi0c)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--cookie-oi0c’
      –2014-08-28 21:27:04– ftp://xn--cookie-oi0c/
      => ‘.listing’
      Resolving “cookie (xn--cookie-oi0c)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--cookie-oi0c’
      –2014-08-28 21:27:04– http://[gpw_e24=http://www.oracle.com/%5D/
      Resolving gpw_e24=http://www.oracle.com/ (gpw_e24=http://www.oracle.com/)… failed: Name or service not known.
      wget: unable to resolve host address ‘gpw_e24=http://www.oracle.com/’
      bash: “http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-linux-i586.tar.gz”: No such file or directory
      Please, look into again.

      • 2daygeek

        It’s working for me. Then better visit oracle website and download the 32-bit package and follow the same steps to do that

  • 2daygeek

    @D C Mishra,

    Use the below command to download the 32-bit package and Follow the same steps.

    # 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/8u20-b26/jdk-8u20-linux-i586.tar.gz”

    If you face any trouble let me know to check further.

    • D C Mishra

      I got the following after your suggested command

      -2014-08-27 21:07:54– http://xn--no-cookies-nu6e/
      Resolving –no-cookies (xn--no-cookies-nu6e)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--no-cookies-nu6e’
      –2014-08-27 21:07:54– http://xn--no-cookies-nu6e/
      Resolving –no-cookies (xn--no-cookies-nu6e)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--no-cookies-nu6e’
      –2014-08-27 21:07:54– http://xn--no-check-certificate-2t2l/
      Resolving –no-check-certificate (xn--no-check-certificate-2t2l)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--no-check-certificate-2t2l’
      –2014-08-27 21:07:54– http://xn--no-check-certificate-2t2l/
      Resolving –no-check-certificate (xn--no-check-certificate-2t2l)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--no-check-certificate-2t2l’
      –2014-08-27 21:07:54– http://xn--header-vg0c/
      Resolving –header (xn--header-vg0c)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--header-vg0c’
      –2014-08-27 21:07:54– http://xn--header-vg0c/
      Resolving –header (xn--header-vg0c)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--header-vg0c’
      –2014-08-27 21:07:55– ftp://xn--cookie-oi0c/
      => ‘.listing’
      Resolving “cookie (xn--cookie-oi0c)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--cookie-oi0c’
      –2014-08-27 21:07:55– ftp://xn--cookie-oi0c/
      => ‘.listing’
      Resolving “cookie (xn--cookie-oi0c)… failed: Name or service not known.
      wget: unable to resolve host address ‘xn--cookie-oi0c’
      –2014-08-27 21:07:55– http://[gpw_e24=http://www.oracle.com/%5D/
      Resolving gpw_e24=http://www.oracle.com/ (gpw_e24=http://www.oracle.com/)… failed: Name or service not known.
      wget: unable to resolve host address ‘gpw_e24=http://www.oracle.com/’
      bash: “http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-linux-i586.tar.gz”: No such file or directory

      Please look into this

  • 2daygeek

    @Rick Disheroon,

    Nice to here.

    • D C Mishra

      Please, explain how to install oracle java 8 on Ubuntu 14.04. on a 32 bit system

  • Rick Disheroon

    Thank you! I am a Noob. Win? No prob, Linux? Noob. I almost didn’t catch that you chdir to . . / opt $
    I was d/l’ing away at about 85% complete when I noticed it. Haha, I thought OMG! 😉
    That was perfect. Worked perfect, even for me. Thank you so much. I owe you!!

  • 2daygeek

    @ arcaos,

    You are most welcome.

  • arcaos

    Excelent tutuorial, worked perfectly and now I can run Android Studio just fine.

    Thx a lot.

Shares
Close
Please support the site
By clicking any of these buttons you help our site to get better