Optimize your Java development and runtime environment with this comprehensive guide on installing Java Development Kit (JDK) and Java Runtime Environment (JRE) on Linux systems. Java developers need both JDK and JRE to craft and run Java applications and applets efficiently. JDK offers the essential tools for developing Java applications, including the Java compiler, while JRE provides a runtime environment necessary for Java applications.

Advertisement

How to Install Java on Ubuntu and Linux Mint

This guide simplifies the process of installing OpenJDK Java on popular Linux distributions such as Ubuntu and Linux Mint. OpenJDK, an open-source implementation of the Java Platform, Standard Edition, ensures your Java applications run securely and efficiently.

Installation Steps

  1. Update Your Package Index

    Begin by updating your package index to ensure you have access to the latest software versions. Execute the following command in your terminal:

    sudo apt update
    
  2. Install Java OpenJDK

    Install OpenJDK 8 by running the following command. This command installs both the JDK and JRE, setting up your system for Java development and execution.

    sudo apt install openjdk-8-jdk openjdk-8-jre
    
  3. Verifying the Java Installation

    After installing Java, verify the installation to ensure Java is correctly installed on your system. Run the following command to check the installed Java version:

    java -version
    

    This command will display the installed OpenJDK version, confirming the successful installation.

  4. Setting Up JAVA_HOME and JRE_HOME Environment Variables

    To ensure Java applications can locate the Java libraries, it’s crucial to set the JAVA_HOME and JRE_HOME environment variables. These variables point to the installation directories of JDK and JRE, respectively. You can set these environment variables in the /etc/environment file with the following commands:

    cat >> /etc/environment <<EOL
    JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
    JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
    EOL
    

Conclusion

Successfully installing and configuring Java on your Linux system is a foundational step for any Java developer. By following the steps outlined in this guide, developers can efficiently prepare their Linux systems for Java development and application execution. This setup not only facilitates the creation of Java applications but also supports running Java-based software. Whether you’re developing new Java applications or running existing ones, having both JDK and JRE properly installed and configured ensures a robust development and execution environment for your Java projects.

Share.

189 Comments

  1. cat >> /etc/environment <<EOL
    JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
    JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
    EOL

    USING THESE STEPS PERMISSION DENIED

  2. Costin C-tin on

    As Benjamin Hecht (and others) pointed out “Permission denied” is raised when trying “cat >> /etc/environment <<EOL ” . Even with “sudo cat >> ” the same applies. To be able to write to /etc/environment this needs to be used:
    cat | sudo tee -a /etc/environment <<EOL
    JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
    JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
    EOL

    • How to upgrade or how to remove java-8 version and install java7 how to set environment variable, can anyone help me with my question?

  3. Benjamin Hecht on

    Hi, I’m getting ‘permission denied’ as an error:

    (base) benjamin@benjamin-desktop:~$ java -version
    openjdk version “1.8.0_252”
    OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
    OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
    (base) benjamin@benjamin-desktop:~$ cat >> /etc/environment < JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
    > JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
    > EOL
    bash: /etc/environment: Permission denied
    (base) benjamin@benjamin-desktop:~$ cat >> /etc/environment < JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
    > JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
    > EOL
    bash: /etc/environment: Permission denied

    Any help would be greatly appreciated! Thanks! Trying to use java for loading a jnlp file so using Java 8 on 18.04.4 appears to be the only way.

    • Try: sudo nano /etc/environment (or use any other text editor)
      Then add the lines:
      JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
      JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre

  4. Levent GUREN on

    There is a space after equal sign at this line:
    JAVA_HOME= /usr/lib/jvm/java-8-openjdk-amd64
    This must not be there. 🙂

  5. Marcus Siqueira on

    Interesting stuff! Keep the site up you have a lot of good content! You just helped me and I believe you helped a lot more people

    • I have corrected the title. Earlier this tutorial was for the Oracle Java installation, But as of now, Oracle Java 8 is not available directly, So we change it to OpenJDK.

  6. Hi, I’m using Ubuntu 18.04 and I’m getting below error :

    Package oracle-java8-installer is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘oracle-java8-installer’ has no installation candidate

  7. Edwin Smith Velandia Salazar on

    work for me,

    sudo apt-get install default-jdk
    sudo apt autoremove
    sudo apt-get install default-jre
    java –version
    sudo apt install openjdk-8-jdk

    sudo update-alternatives –config java
    Existen 2 opciones para la alternativa java (que provee /usr/bin/java).

    Selección Ruta Prioridad Estado
    ————————————————————
    0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 modo automático
    1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 modo manual
    * 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 modo manual

    Pulse para mantener el valor por omisión [*] o pulse un número de selección:

    *** in my case, i used java-8, press 2

    and my app work.

  8. It’s not working and it won’t work. You need to update your article. Oracle has made it mandatory to create an account and download the required version. The PPA method is deprecated and it won’t work.

    TIP: Make sure you download the binary version or the Oracle 8 JDK.

  9. Actually it is possible to install Java 8 u 131 to Mint 19+ or Ubuntu 18+.

    Search for these files on the Internet:

    oracle-java8-installer_8u131-1_webupd8_2_all.deb
    oracle-java8-set-default_8u131-1_webupd8_2_all.deb
    oracle-java8-unlimited-jce-policy_8u131-1_webupd8_2_all.deb

    Then:

    sudo oracle-java8-installer_8u131-1_webupd8_2_all.deb
    sudo oracle-java8-set-default_8u131-1_webupd8_2_all.deb
    (and you can install the unlimited one, but not necessary by defalut)

    In contrary to the abandoned PPA, you can install these without problems and the ‘Oracle Java 8 Plugin Control Panel’ will work too.

    If the .jnlp files don’t open in Firefox, then select “open with” and enter “javaws” .

    There is virtually no info of Java 8 for the latest Mint/Ubutu installation over the internet and I had to figure it out too.

    I hope it helps!

    • Hi,

      Java 8 is no more available to download from Oracle site. But if you have any existing installation on another system, can be used to install to your system.

  10. This is not working. It is showing this error E: Package ‘oracle-java8-installer’ has no installation candidate

  11. Hi
    when i try to intall the java8. By these commands
    sudo add-apt-repository ppa:webupd8team/java
    sudo apt update; sudo apt install oracle-java8-installer
    after the second command i am getting error like this
    “Package oracle-java8-installer is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source”
    what to do ? and i have tried everything to come out of this i can’t able to do this
    plzz help me out.

  12. Unfortunately don’t work anymore 🙁
    >
    >~/Downloads/jdk1.8.0_202$ sudo apt-get install oracle-java8-set-default
    >[sudo] password for i1:
    >Reading package lists… Done
    >Building dependency tree
    >Reading state information… Done
    >E: Unable to locate package oracle-java8-set-default

  13. Chuanpeng Hu on

    Hi, there,

    Thanks so much for your post. It’s helpful.
    But I failed to install java,

    > sudo apt install oracle-java11-installer

    I got this error message:

    Resolving login.oracle.com (login.oracle.com)… 209.17.4.8
    Connecting to login.oracle.com (login.oracle.com)|209.17.4.8|:443… connected.
    HTTP request sent, awaiting response… 401 Authorization Required

    Username/Password Authentication Failed.
    download failed
    Oracle JDK 8 is NOT installed.
    dpkg: error processing package oracle-java8-installer (–configure):
    installed oracle-java8-installer package post-installation script subprocess returned error exit status 1
    Processing triggers for shared-mime-info (1.9-2) …
    Setting up oracle-java11-set-default (11.0.2-2~linuxuprising1) …
    Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) …
    Processing triggers for hicolor-icon-theme (0.17-2) …
    Processing triggers for fontconfig (2.12.6-0ubuntu2) …
    Errors were encountered while processing:
    oracle-java8-installer
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    One possibility is that “401 is because 8u211 is the first version that is paid only. The previous 8u201 was the last freely available version.” as suggested by one comment here: https://stackoverflow.com/questions/46815897/jdk-8-is-not-installed-error-404-not-found

  14. I need jdk version to be like this

    Java version “1.8.0_40”
    Java™ SE Runtime Environment (build 1.8.0_40-b25)
    Java HotSpot™ 64-Bit Server VM (build 25.40-b25, mixed mode)

    How do I do it for Ubuntu 18.10

  15. Alexandre Pedro on

    Linux Mint 19.1, couldn’t do the last step as the guide says. Ended up doing:
    sudo nano /etc/environment

    Paste in:
    JAVA_HOME=/usr/lib/jvm/java-8-oracle
    JRE_HOME=/usr/lib/jvm/java-8-oracle/jre

    Save and exit.

    Thank you for the guide!

  16. But live-streaming of the game can affect their job and makes these enjoy theirs favored game on laptop or pc.

  17. If they bests the seller he gets twice the total amount
    of money inside the payout than he’d have if he had gained without doubling.

  18. sudo apt-get install oracle-java8-installer
    sudo: não foi possível resolver máquina leni
    Lendo listas de pacotes… Pronto
    Construindo árvore de dependências
    Lendo informação de estado… Pronto
    Alguns pacotes não puderam ser instalados. Isto pode significar que
    você solicitou uma situação impossível ou, se você está usando a
    distribuição instável, que alguns pacotes requeridos não foram
    criados ainda ou foram retirados da “Incoming”.
    A informação a seguir pode ajudar a resolver a situação:

    Os pacotes a seguir têm dependências desencontradas:
    oracle-java8-installer : Depende: java-common (>= 0.24) mas não é instalável
    Recomenda: gsfonts-x11 mas não é instalável
    Recomenda: oracle-java8-set-default mas não será instalado
    E: Impossível corrigir problemas, você manteve (hold) pacotes quebrados.

  19. Hello

    Connecting to download.oracle.com (download.oracle.com)|104.122.105.69|:80… connected.
    HTTP request sent, awaiting response… 404 Not Found
    2018-01-22 13:59:51 ERROR 404: Not Found.

    download failed
    Oracle JDK 8 is NOT installed.
    dpkg: error processing package oracle-java8-installer (–configure):
    subprocess installed post-installation script returned error exit status 1
    Errors were encountered while processing:
    oracle-java8-installer
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    I am getting this error while running install command on terminal on linux mint 17.2.

  20. when i do this all i get is

    download failed
    Oracle JDK 8 is NOT installed.
    dpkg: error processing package oracle-java8-installer (–configure):
    subprocess installed post-installation script returned error exit status 1
    Errors were encountered while processing:
    oracle-java8-installer
    E: Sub-process /usr/bin/dpkg returned an error code (1)

  21. Great information. Appreciate the time you took to share this feedback for us computer nerds. Love your blog too. Java is still one of the best options out there.

  22. step 1 Can do add-apt-repository ppa:webupd8team/java && apt-get update && apt-get install oracle-java8-installer allso little bit easy 🙂

  23. hi,
    there is an error with python-samba while installing oracle-java8-installer.
    [/var/cache/apt/archives/python-samba_2%3a4.3.11+dfsg-0ubuntu0.16.04.9_i386.deb
    E: Sub-process /usr/bin/dpkg returned an error code (1)]
    how can i solve this problem?

    • Hello:

      You you either open ‘Files’ or ‘nautilus’ with root privileges, you will be able to open the etc/environment file, edit it and save afterward.

    • the easiest way is to do it through the terminal using sudo for root access (which enables you to edit sensitive files)
      $ sudo gedit /etc/environment
      add the lines
      then save.
      done.

  24. This seems to install JRE _not_ JDK as the title of the article states.
    Several people have pointed this out in the comments yet these queries remain unanswered.
    Perhaps the title of the article is incorrect…

    • Hi Tim,

      This installs JDK and JRE both. After installation you can check install java compiler.

      $ javac -version

      javac 1.8.0_111

  25. Thank you! This works Great! I was also able to integrate Apache Solr on my website

    I am thinking about keeping this up and going on my vps server

  26. Hello, i f i understand this will install JDK too. But i cant find my JDK directory.
    any help or explanation ? thank you in advance

  27. If you get “Cannot add PPA ‘ppa:cooperjona/lightread’ . Please check that the PPA name or format is correct.” error

    sudo -E add-apt-repository ppa:ppaname/ppa
    instead of

    sudo add-apt-repository ppa:ppaname/ppa

    • Encountered the same issue – i had to modify the timeout settings in /var/lib/dpkg/info/oracle-java8-installer.postinst to make it run. Sadly, the installer script doesn’t use the system-wide /etc/wgetrc but creates its own wgetrc each time it runs. So, you’ll have to search for the line “echo “timeout = 15″ >> wgetrc” in the postinst file i’ve mentioned above. Now, just set a longer timeout or remove the line completely.

  28. I’m getting an error when running the command:

    sudo add-apt-repository ppa:webupd8team/java

    The error is:
    Cannot add PPA: ‘ppa:~webupd8team/ubuntu/java’.
    ERROR: ‘~webupd8team’ user or team does not exist.

  29. Thanks but it’s not working for me, this is the message i got:

    ~ $ sudo apt-get update
    E: Type ‘sudo’ is not known on line 1 in source list /etc/apt/sources.list.d/mono-xamarin.list
    E: The list of sources could not be read.

  30. Sure wish this wasn’t the first item coming up in a google search of “installing java 8 jdk on ubuntu” because this isn’t the jdk!

  31. Webupd8 Java PPA DOWN!!!!! When will it be updated?

    W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://ppa.launchpad.net trusty Release: The following signatures were invalid: BADSIG C2518248EEA14886 Launchpad VLC

    W: Failed to fetch http://ppa.launchpad.net/webupd8team/java/ubuntu/dists/trusty/Release

    W: Some index files failed to download. They have been ignored, or old ones used instead.

  32. Hi Rahul,
    I am new to Ubuntu. I tried the setps to install jdk 1.8.
    While setting environment, I found the error
    Error: Could not open input file: /usr/java/jre1.8.0_45/lib/rt.pack
    jsse.jar…
    Error: Could not open input file: /usr/java/jre1.8.0_45/lib/jsse.pack
    charsets.jar…
    Error: Could not open input file: /usr/java/jre1.8.0_45/lib/charsets.pack
    localedata.jar…
    Error: Could not open input file: /usr/java/jre1.8.0_45/lib/ext/localedata.pack
    jfxrt.jar…
    Error: Could not open input file: /usr/java/jre1.8.0_45/lib/ext/jfxrt.pack
    plugin.jar…
    Error: Could not open input file: /usr/java/jre1.8.0_45/lib/plugin.pack
    javaws.jar…
    Error: Could not open input file: /usr/java/jre1.8.0_45/lib/javaws.pack
    deploy.jar…
    Error: Could not open input file: /usr/java/jre1.8.0_45/lib/deploy.pack
    /var/lib/dpkg/info/jre1.8.0-45.postinst: line 641: /usr/sbin/alternatives: No such file or directory
    dpkg: error processing package jre1.8.0-45 (–configure):
    subprocess installed post-installation script returned error exit status 127
    Setting up oracle-java8-set-default (8u45+8u33arm-1~webupd8~1) …
    Errors were encountered while processing:
    jre1.8.0-45
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    What should I do to set environment ?

    • Same here, HARSHITA.

      Worse: I can’t install any package since I’ve tried to install this using this tutorial. Can someone help please?

      Zoli

      • EDIT: Maybe a helpful hint, I did a…

        java -version

        …this shows me…

        java version “1.9.0-ea”
        Java(TM) SE Runtime Environment (build 1.9.0-ea-b70)
        Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b70, mixed mode)

        So the error messages seem to come from an older installation, that I have to remove. But how?

        Zoli

  33. Hi,

    I would like to thank you for helping the non techs like myself first. Could you help me with a problem I get? I am using LM 17.1 and trying to do the installation I get the Binary Code License Agreement display at mt terminal window. There is no way to click ok or accept those terms, failing which the installation aborts. Can you tell me a way around, or what am I doing wrong?

    Thanks
    Amit

  34. Hi,
    I could install java 8 as you wrote, but I still can not set java 8 as a default JRE. And when I would like to add it to the installed JREs I cant find it. Where should it be?
    Thank you!

  35. Divine Martins Jr. on

    Wonderful and helpful.
    A written tutorial on how to install using the already downloaded tar.gz file will be helpful too. Thanks

    • Packages can be removed with
      >sudo apt-get –purge remove packageName

      apt-get remove may some times leave behind some files.
      –purge will remove all files.

  36. Hi,

    I am getting an error stating the following. Please help.

    Cannot add PPA: ‘ppa:webupd8team/java’.
    Please check that the PPA name or format is correct.

Exit mobile version