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.
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
- 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
- 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
- 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.
- 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.
189 Comments
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
thanks
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?
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
add permission with below commonad
sudo chmod -R ugo+rw /etc/environment
There is a space after equal sign at this line:
JAVA_HOME= /usr/lib/jvm/java-8-openjdk-amd64
This must not be there. ๐
Thanks Levent, Article has been updated.
thanks!
Thanks for the quick and clear guide.
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
Good write-up. I certainly love this website. Thanks!
Thanks it worked for me
Step 2 still says “Oracle Java 8”
Hi Hugo, Thanks for pointing it. I have updated the tutorial correctly.
This is not an Oracle JDK installation as the title suggest!
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.
This works perfectly as of 31-Oct-2019
Working perfectly
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
This article is out of date, and, as of September 2019, no longer works.
very easy steps. Thanks
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.
worked on LinuxMint. Thanks
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.
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.
This is not working. It is showing this error E: Package ‘oracle-java8-installer’ has no installation candidate
because oracle changed license for it’s jdk. this tutor is useless and, in fact, scam.
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.
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
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
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
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!
Same here.
This is simple and extremely easy explanation
But live-streaming of the game can affect their job and makes these enjoy theirs favored game on laptop or pc.
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.
Location: http://download.oracle.com/otn-pub/?AuthParam=1521892631_53f4fd9f2a836d690ba6d31c8b160b91 [following]
–2018-03-24 11:55:11– http://download.oracle.com/otn-pub/?AuthParam=1521892631_53f4fd9f2a836d690ba6d31c8b160b91
Connecting to download.oracle.com (download.oracle.com)|2.21.188.165|:80… connected.
HTTP request sent, awaiting response… 404 Not Found
2018-03-24 11:55:12 ERROR 404: Not Found.
Hi Scott,
I have checked commands and this is working for me. Which operating system version are you using?
W: Falhou ao buscar http://archive.ubuntu.com/ubuntu/dists/vivid-backports/universe/binary-i386/Packages 404 Not Found [IP: 91.189.88.149 80]
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.
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.
Hi Ankit, The webupd8 team has not updated the package yet to PPA. For the time, You can download packages to install Java 8.
https://drive.google.com/file/d/1l8NTWhZrwYjvjRMXvAgTNXbExJ08eIjU/view
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)
Hi Bill, The webupd8 team has not updated the package yet to PPA. For the time, You can download packages to install Java 8.
https://drive.google.com/file/d/1l8NTWhZrwYjvjRMXvAgTNXbExJ08eIjU/view
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.
step 1 Can do add-apt-repository ppa:webupd8team/java && apt-get update && apt-get install oracle-java8-installer allso little bit easy ๐
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?
i’m not being able to edit the etc/environment file!!!
please help?!
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.
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
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
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
I didn’t get a JDK downloaded either. Does anyone have a suggestion ?
I don’t like it.. It’s too easy.
Do you have a harder example?
This is simple and extremely easy explanation
I want know becouse we make donwload of archive on site of oracle and that file i dont can install
1-up!!! Thanks! you saved my day ๐
Thanks for your suggestions, this solution is fast and understandable. i owe you one ๐
that is the best guide of the INTERNET, thanks man.
Thank you maaaan!
I’ve installed java 1.8 on two devices thanks to this beautiful simple process
๐ you da man thanks!
Great guide.
Thanks!
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
thanks
Genio, muchas gracias. Saludos desde Argentina!
This saved my day! Thank you!
This saved me a whole day of manually doing it myself. Thanks so much!!
Great step-by-step process document!! Thanks.
thanks!
Thanks a lot! You all helped me a lot!
nice documentation
i already had java7. after installing java8, java- -version still gives jdk7… whats the solution?
have u got any solution? for this ….
Thanks for the great instructions!
Thank you !
Thank you very much !!
Thank You so much
Thank bro none of the site help out on google but u r site instruction was extremely perfect….
This article was extremely helpful. Please keep posting Linux and Java related articles.
Thanks for a simple and great HOWTO! ๐
hi guys i am getting this error)
(http://download.oracle.com/otn-pub/java/jdk/8u72-b15/jdk-8u72-linux-i586.tar.gz
Connecting to download.oracle.com (download.oracle.com)|180.149.61.152|:80… connected.
HTTP request sent, awaiting response… Read error (Connection reset by peer) in headers.
Retrying.)
upto try:5 after that download fail NOT inst error please help
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.
Thank you very much
It is not working for me.
Hi,
What issue are you facing ?
Thanks man. It works perfectly.
Muy รบtil, muchas gracias.
Very useful tutorial…
Thank you
hey!!! so usefull!!!! thank a lot!!!!! ๐
Thanks dude searched everywhere for guides but yours is the best and easiest.
Thank you ๐
Hey, i’am new with linux and its very usefull thanks for the tutorial.
Thank you very much for this. It helped a lot!
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.
Hi Ian,
Its still working for me. Please confirm what OS version are you using ?
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.
Very nice, simple and useful
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!
I agree with you comment !!! It’s not a JDK and only a Runtime then, no option to compile (no javac compiler)
Thanks a lot!
Nice article. So the reference in my blog yes
Thanks a lot
thanks
Thanks for that short advice, for now everything is working ๐ and let it stay in this way ๐
Thank you!
thank, ..thank you very much, very nice work
Very Nice, thanks!
you follow this post and enjoy java8. very nice work done by techadmin.
Thanks dude ยฐ this information was util.
Good job!
Does not work trows class not found exception
everything went in a breeze – cool
thanks
looking for manual procedure to do stepbystep as well
Thanks a lot.
Very helpful.
Thanks man!! Worked like a champ!
Muito obrigado amigo.
Thank you very useful
Thanks
While installing throw sha256sum mismatch jdk-8u60-linux-x64.tar.gz
please help me to out this problem
Thank you so much……Really really helped alot….. ๐
Is there a way to get it to move up from 51 to 60? The website says I am behind!
Thanks very thamkful!!
Really helpful information.
Good One!
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.
thankyou somuch
Thank you sharing a such helpful article
idk how to install this
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
Very helpful article.
Very helpful,
Thanks !!!
Very helpful article. Thanks.
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
use arrow keys to move, enter to accept
Thank you!! It works!.
Thanks for the info! very helpful…
Thank you so much, this helped a lot !!!!
Thanks from a spanish user!
Thanks! It helped a lot!
if i search, do i have java?, and enter site is says this plugin is not accepted,what i have to do?
Hi Habdul,
Do you mean java is working with browser ? If yes which browser are you using ?
Thank you for kind article to install java 1.8 in Ubuntu 14.04.
It works well. ๐
Will it work for Ubuntu 14.10?
This is very handy, thank you. And thank you to the Webupd8 Team!
thank you, greetings from Mรฉxico.
You made my day,, thanks allot
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!
thanks for post !! it was very helpful for me !
Thanks for the guide.. worked fine for me
Thank you very much. This is really helpful.
Awesome! very helpful!
Very useful. Thank you.
Very Easy for install Java in Ubuntu ๐
Nice Job
great! i always wonder why we haven’t something like a repo to install jdk!
great work
Thanks a lot. Quick, easy and it installs both JDK and JRE version 8!
Wonderful and helpful.
A written tutorial on how to install using the already downloaded tar.gz file will be helpful too. Thanks
This installs the JRE not the JDK/SDK. Is not the same ….
Nice tutorial!
But now, How do you uninstall it?
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.
Hi, whish all of costum installs have these very good install help,
saves lots of time , thx,
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.
no problem here with sudo, name (and all further instructions are correct)
Yeah.. same problem here
Thanks man, saved me some time ๐
thanks! ๐
Thank you very much, this helped a lot
Very good, help so much
Thank’s for this article!
Thanks! Very helpful.
you guys rock
Thank you so much!
Thank you!
thank you very very much
Missing the – in java -version
Woops! Retract that!
many thanks, this helped a lot!
Thanks!
I canยดt access my bank with open-jdk, only with oracle-java
Useful Information, Thanks
Nice tutorial
Greetings from Mexico Wey!! :3
Thanks!!!! God Thanks!!!!
Hi, these information is very useful. Thank you very much.