Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to install the latest java version in Raspbian (Stretch)

Introduction

The default version of java provided in the latest raspbian images are outdated, so we are going to install from the ppa:webupd8team/java repository instead. Please note that add-apt-repository ppa:webupd8team/java will not work, so we will need to add the repository manually.

Installation

  1. Create the gpg key file and paste the following lines of text below
nano key.txt
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SKS 1.1.5
Comment: Hostname: keyserver.ubuntu.com

mI0ES9/P3AEEAPbI+9BwCbJucuC78iUeOPKl/HjAXGV49FGat0PcwfDd69MVp6zUtIMbLgkU
OxIlhiEkDmlYkwWVS8qy276hNg9YKZP37ut5+GPObuS6ZWLpwwNus5PhLvqeGawVJ/obu7d7
gM8mBWTgvk0ErnZDaqaU2OZtHataxbdeW8qH/9FJABEBAAG0DUxhdW5jaHBhZCBWTEOImwQQ
AQIABgUCVsN4HQAKCRAEC6TrO3+B2tJkA/jM3b7OysTwptY7P75sOnIu+nXLPlzvja7qH7Wn
A23itdSker6JmyJrlQeQZu7b9x2nFeskNYlnhCp9mUGu/kbAKOx246pBtlaipkZdGmL4qXBi
+bi6+5Rw2AGgKndhXdEjMxx6aDPq3dftFXS68HyBM3HFSJlf7SmMeJCkhNRwiLYEEwECACAF
Akvfz9wCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRDCUYJI7qFIhucGBADQnY4V1xKT
1Gz+3ERly+nBb61BSqRx6KUgvTSEPasSVZVCtjY5MwghYU8T0h1PCx2qSir4nt3vpZL1luW2
xTdyLkFCrbbIAZEHtmjXRgQu3VUcSkgHMdn46j/7N9qtZUcXQ0TOsZUJRANY/eHsBvUg1cBm
3RnCeN4C8QZrir1CeA==
=CziK
-----END PGP PUBLIC KEY BLOCK-----
  1. Add the gpg key
sudo apt-key add key.txt
  1. Add the repository to /etc/apt/sources.list.d/ and perform an update
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-get update
  1. Install Java 8 SDK
sudo apt-get install oracle-java8-installer 
  1. Verify that we have successfully installed java
pi@raspberrypi:~# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) Client VM (build 25.161-b12, mixed mode)

Switching between versions

If you have multiple jvms installed and you want to switch back to a specific version of java you can do the following:

Option 1

  1. List the available versions in your system
update-java-alternatives -l
  1. Copy the key of the first column of the result of your target version
java-8-oracle                  1081       /usr/lib/jvm/java-8-oracle
  1. Execute the set command using the previously copied key
update-java-alternatives -s java-8-oracle

Option 2

sudo apt-get install oracle-java8-set-default

More details here

@eugene-taylashev

This comment has been minimized.

Copy link

eugene-taylashev commented May 24, 2018

Thanks a lot. Worked for me

@BurovAlexProgrammer

This comment has been minimized.

Copy link

BurovAlexProgrammer commented Jun 21, 2018

echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list

Doesn't work for me. PI answered

permission denied

Enter this before
sudo -i

@chris-hunter

This comment has been minimized.

Copy link

chris-hunter commented Aug 26, 2018

I also had problems with permissions for:
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list

So had to do this but manually with text editor and sudo

@thomas-wroblewski

This comment has been minimized.

Copy link

thomas-wroblewski commented Sep 6, 2018

I did it with the following - added sudo to the tee command

echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
@ruulio31

This comment has been minimized.

Copy link

ruulio31 commented Sep 23, 2018

Thank you :), it worked for me on my Raspeberry with OSMC

@Khaosan

This comment has been minimized.

Copy link

Khaosan commented Jan 2, 2019

Merci beaucoup, ça fonction parfaitement chez moi.
NZBHydra2 fonctionne maintenant sur mon RPi 3B+...

@dbloud50

This comment has been minimized.

Copy link

dbloud50 commented Jan 8, 2019

I am unable to create gpg key. I receive: gpg: no valid OpenPGP data found. when I attempt to add key. I copied everything from -----BEGIN PGP PUBLIC KEY BLOCK----- to -----END PGP PUBLIC KEY BLOCK----- in key.txt. Do I need to create a directory for key.txt. I simply followed the steps listed.

@SpiritWolfNJ

This comment has been minimized.

Copy link

SpiritWolfNJ commented Jan 16, 2019

I'm a relative newbie but no stranger to the CLI but...

Following the instructions, step two gave me this error:
pi@raspi1:/tmp $ sudo apt-key add key.txt
key C2518248EEA14886:
1 signature not checked due to a missing key

Couldn't find a place to MANUALLY place key signature (where did Instruction Two send the data? (that's the newbie part)

After that, things went totally south...
"Add the repository to /etc/apt/sources.list.d/ and perform an update"
text group commands; they failed

Command instruction 3 failed..
Multiple errors for
deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi

Uncomment line below then 'apt-get update' to enable 'apt-get source'

#deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main
deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main

Finally, this:
pi@raspi1:~ $ sudo apt-get update
Hit:1 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease
Hit:2 http://archive.raspberrypi.org/debian stretch InRelease
Reading package lists... Done
W: Target Packages (main/binary-armhf/Packages) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (main/i18n/Translation-en_US.UTF-8) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Packages (ui/binary-armhf/Packages) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Packages (ui/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (ui/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (ui/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (ui/i18n/Translation-en_US.UTF-8) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Packages (main/binary-armhf/Packages) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (main/i18n/Translation-en_US.UTF-8) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Packages (ui/binary-armhf/Packages) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Packages (ui/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (ui/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (ui/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1
W: Target Translations (ui/i18n/Translation-en_US.UTF-8) is configured multiple times in /etc/apt/sources.list:1 and /etc/apt/sources.list.d/raspi.list:1

...and then:
pi@raspi1:~ $ java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

Mongo doesn't work, Nor does the display for PiHole; they both need Java (apparently)

I'm totally knackered and defeated...so I'm coming to get wisdom; all the online things I've tried have failed; and I can't go back to where I was.

@cybercussion

This comment has been minimized.

Copy link

cybercussion commented Apr 30, 2019

I just ended up in the same place installing Unifi Controller and it installed 1.8 65 too and won't work.
Downloading directly thru Oracle has a user/pass and I'm folding. I can just manually update each of the Ubiquity AC Pros vs spending hours trying to bring this up.

@dmdamen

This comment has been minimized.

Copy link

dmdamen commented May 11, 2019

No luck for me:

`pi@raspberrypi:~ $ sudo apt-get install oracle-java8-installer
Reading package lists... Done
Building dependency tree
Reading state information... Done
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`

@ConorMulhern

This comment has been minimized.

Copy link

ConorMulhern commented May 12, 2019

E: Package 'oracle-java8-installer' has no installation candidate

I've hit the same issue trying to upgrade Java on a Raspberry Pi.

Sounds like Oracle made changes to their licensing terms which means the package archive we've all been using to install the Java installer ( ppa.launchpad.net ) can no longer offer the installer. Which means the most popular method of installing Java on Pis (the one documented everywhere) no longer works.

I believe you need to create an account with Oracle, download the installed archive .tar file, and then install it.

@dmdamen

This comment has been minimized.

Copy link

dmdamen commented May 12, 2019

Yeah.. I figured that out as well. I don't want to jump through the Oracle hoops because:

  1. I don't want to register an account with them
  2. I want repository based installs only so I can easily keep my system up to date.

However, I tried installing openjdk-8-jdk and it works just fine.

@ConorMulhern

This comment has been minimized.

Copy link

ConorMulhern commented May 12, 2019

I went through the hoops of installing the Oracle JRE, but the Unifi controller kept using the 'wrong' version of Java, so I too installed the OpenJDK version;

sudo apt-get install openjdk-8-jre-headless -y

and the controller restarted without any issues.

@zachjacobs

This comment has been minimized.

Copy link

zachjacobs commented May 17, 2019

I went through the hoops of installing the Oracle JRE, but the Unifi controller kept using the 'wrong' version of Java, so I too installed the OpenJDK version;

sudo apt-get install openjdk-8-jre-headless -y

and the controller restarted without any issues.

This worked for me. Thanks @ConorMulhern!

@vicival

This comment has been minimized.

Copy link

vicival commented Jul 2, 2019

Didn't work (for me.. ; Raspberry Pi 3B & Raspbian stretch)
Did all the bits and at the end, I got this:

pi@pi:~ $ sudo apt-get install oracle-java8-installer
Reading package lists... Done
Building dependency tree
Reading state information... Done
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

How about a more direct approach?
I have Oracle's Java SE Development Kit 8 ( jdk-8u212-linux-arm64-vfp-hflt.tar.gz )
made exactly for Broadcom BCM2837 ( meaning arm & hardware floating-point ) .
How do I "install" it ? ( aka put it in the right places )

I already have openjdk-8-jdk-8u212 but I suspect it has a ?? problem because Netbeans IDE 8.1 (which is using this openjdk)
can't download the List of Plugins (nor any other update) from its Netbeans Distribution repository
( it errors Unable to connect to the NetBeans Distribution because of Zero sized file reported at )
http://updates.netbeans.org/netbeans/updates/8.1/uc/final/distribution/catalog.xml.gz
while it can download fine another similar list from the Plugin Portal which is on a different repository
http://plugins.netbeans.org/nbpluginportal/updates/8.1/catalog.xml.gz
That's why I want to try "a different" JDK .
P.S. - I found this
P.S. - For what it's worth, I discovered why my brand new Netbeans IDE 8.1 could not update from updates.netbeans.org
The link for that distribution/catalog file should be https , not http .
So edit that hyperlink ( Plugins/Settings/Edit/'Update Center Customizer'_form/URL/ ) and make it https
https://updates.netbeans.org/netbeans/updates/8.1/uc/final/distribution/catalog.xml.gz

@ormanya

This comment has been minimized.

Copy link

ormanya commented Sep 14, 2019

I went through the hoops of installing the Oracle JRE, but the Unifi controller kept using the 'wrong' version of Java, so I too installed the OpenJDK version;

sudo apt-get install openjdk-8-jre-headless -y

and the controller restarted without any issues.

Worked for me. Thanks a lot!

@herlon214

This comment has been minimized.

Copy link

herlon214 commented Sep 17, 2019

I went through the hoops of installing the Oracle JRE, but the Unifi controller kept using the 'wrong' version of Java, so I too installed the OpenJDK version;

sudo apt-get install openjdk-8-jre-headless -y

and the controller restarted without any issues.

Worked for me. Thanks!

@DubbyHarry

This comment has been minimized.

Copy link

DubbyHarry commented Sep 25, 2019

pi@pi:~ $ sudo apt-get install oracle-java8-installer
Reading package lists... Done
Building dependency tree
Reading state information... Done
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

I'm getting the same error on a Raspberry Pi 2B running Raspbian GNU/Linux 10 \n \l

Any ideas?

@ribasco

This comment has been minimized.

Copy link
Owner Author

ribasco commented Sep 25, 2019

The PPA for oracle jdk 8 has been discontinued. I suggest you install the openjdk version instead.

@DubbyHarry

This comment has been minimized.

Copy link

DubbyHarry commented Sep 25, 2019

The PPA for oracle jdk 8 has been discontinued. I suggest you install the openjdk version instead.

root@pi-hole:/home/pi# java -version
Error occurred during initialization of VM
Server VM is only supported on ARMv7+ VFP

Looks like I will re-install my Pi with Raspbian 9 instead of 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.