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. First we need to register the GPG key (required for authentication). So lets create a temporary file and paste the public key there.
    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-----
    

    You can get this key directly from the launchpad page (refer to the Signing Key link under “Technical details about this PPA”).

  2. Now use apt-key to register the key
    sudo apt-key add key.txt
  3. 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
  4. Install Java 8 SDK
    sudo apt-get install oracle-java8-installer
  5. 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: Using update-java-alternatives (Recommended)

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

Option 2: Using oracle-java8-set-default package

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

4 thoughts on “How to install the latest java version in Raspbian (Stretch)

Add yours

  1. sudo apt-get update produced a response that ended with:
    N: Ignoring file ‘webupd8team-java-list’ in directory ‘/etc/apt/sources.list.d/’ as it has no filename extension

    I wasn’t able to get any farther. What did I do wrong?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: