Page 1 of 1

How to install Java 8 on Raspbian?

Posted: Tue Feb 24, 2015 5:31 am
by rpi25
How would I go about doing this? I don't see a good package when I do apt-cache search jre, they are all java 6 and 7.

I am wanting to install filebot, but to do so I apparently need to install Java 8.

Can anyone point me in the right direction? A search of the forum disregarded install and 8, and just searched for java, which returned over 6000 posts and the first few pages of results were not helpful, lol

Re: How to install Java 8 on Raspbian?

Posted: Tue Feb 24, 2015 9:25 am
by DougieLawson
sudo apt-get install oracle-java8-jdk

Although on a stock Raspbian (or NOOBS) 2015-02-16 install it's already there.

Re: How to install Java 8 on Raspbian?

Posted: Tue Feb 24, 2015 8:12 pm
by rpi25
Very cool, I see you are correct it was already installed, as when I tried to add it via apt-get it said it was already the most up to date version.

However, something seems to be not right.

When I try to execute the filebot.sh script from the most recent filebot portable (http://sourceforge.net/projects/filebot/), I get the following errors

Code: Select all

Exception in thread "main" java.lang.UnsupportedClassVersionError: net/filebot/Main : Unsupported major.minor version 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:643)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
	at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Could not find the main class: net.filebot.Main. Program will exit.
Which is confusing, as the java 8 package you mention is clearly installed. Any idea what is wrong here?

Re: How to install Java 8 on Raspbian?

Posted: Tue Feb 24, 2015 8:14 pm
by DougieLawson
Your code has thrown an exception. You'll need to read the source code to understand why it has done that.

Re: How to install Java 8 on Raspbian?

Posted: Tue Feb 24, 2015 9:25 pm
by rpi25
OK, here's what I did to fix this, total linux noob but essentially I had to just change the default auto choice of java and javac for the raspberry pi (one of them was still set to the jdk6).

I did so following this guide http://www.rpiblog.com/2014/03/installi ... ry-pi.html

With these commands
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java

Re: How to install Java 8 on Raspbian?

Posted: Tue Feb 24, 2015 9:46 pm
by asandford
rpi25 wrote:OK, here's what I did to fix this, total linux noob but essentially I had to just change the default auto choice of java and javac for the raspberry pi (one of them was still set to the jdk6).

I did so following this guide http://www.rpiblog.com/2014/03/installi ... ry-pi.html

With these commands
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java
A more 'portable' way is to set the JAVA_HOME env variable to point to the appropiate version for your project.

Re: How to install Java 8 on Raspbian?

Posted: Tue Feb 24, 2015 11:05 pm
by rpi25
So in this instance, where would I find the home variable to redirect? Is that in the filebot.sh script, or elsewhere?

Re: How to install Java 8 on Raspbian?

Posted: Tue Feb 24, 2015 11:36 pm
by asandford
rpi25 wrote:So in this instance, where would I find the home variable to redirect? Is that in the filebot.sh script, or elsewhere?
You can set it from the CLI: export JAVA_HOME=/path/to/java/version/you/want

Re: How to install Java 8 on Raspbian?

Posted: Sat Oct 22, 2016 7:26 pm
by simonx314
rpi25 wrote:OK, here's what I did to fix this, total linux noob but essentially I had to just change the default auto choice of java and javac for the raspberry pi (one of them was still set to the jdk6).

I did so following this guide http://www.rpiblog.com/2014/03/installi ... ry-pi.html

With these commands
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java
Thanks rpi25, running these two commands was what I needed to do to fix my javac java version mismatch.

Re: How to install Java 8 on Raspbian?

Posted: Thu Feb 16, 2017 1:12 am
by henryburkhard
After downloading the latest version from oracle you can run a script to set the alternatives.
JAVA_DIR=/usr/lib/jvm/jdk1.8.0_121
JAVA_BIN_DIR=$JAVA_DIR/bin
JAVA_JRE_LIB_DIR=$JAVA_DIR/jre/lib
JAVA_JRE_BIN_DIR=$JAVA_DIR/jre/bin

DEST_DIR=/usr/bin
ALT_LEVEL=100

for x in $JAVA_JRE_BIN_DIR $JAVA_JRE_LIB_DIR $JAVA_BIN_DIR
do
for f in `find $x -maxdepth 1 -type f -executable`
do
NAME=`basename $f`
update-alternatives --install $DEST_DIR/$NAME $NAME $x/$NAME $ALT_LEVEL
done
done

Re: How to install Java 8 on Raspbian?

Posted: Tue Aug 22, 2017 2:52 pm
by palswim
DougieLawson wrote:
Tue Feb 24, 2015 9:25 am
sudo apt-get install oracle-java8-jdk
My Raspbian repository does not appear to contain this package. Am I missing a source or did Raspbian remove this package from the repository?

Re: How to install Java 8 on Raspbian?

Posted: Tue Aug 22, 2017 4:18 pm
by DirkS
palswim wrote:
Tue Aug 22, 2017 2:52 pm
DougieLawson wrote:
Tue Feb 24, 2015 9:25 am
sudo apt-get install oracle-java8-jdk
My Raspbian repository does not appear to contain this package. Am I missing a source or did Raspbian remove this package from the repository?
It's in the RPF repo, not Raspbian

Code: Select all

[email protected]:~$ apt-cache policy oracle-java8-jdk
oracle-java8-jdk:
  Installed: (none)
  Candidate: 8u65
  Version table:
     8u65 0
        500 http://archive.raspberrypi.org/debian/ jessie/main armhf Packages

Re: How to install Java 8 on Raspbian?

Posted: Mon Oct 09, 2017 3:29 pm
by HawaiianPi
Yea, it's in the RPF Stretch repo as well.

[email protected]:~ $ apt-cache policy oracle-java8-jdk
oracle-java8-jdk:
Note that it is quite an old version. The current version from Oracle is 8u144. If you want to update to the latest version you can install it manually, but an easier way is to use the webupd8team PPA, which will install and update Java like other packages. Also, if the above shows you have the old version installed, you'll want to remove it after we get you updated to the latest version (but don't try to remove it now).

Open a terminal and do the following:

Code: Select all

sudo su
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
The current version of Stretch will generate an errort about no dirmngr when trying to get the key. To fix that just install it (apt-get install dirmngr) then repeat the key command and continue.

Code: Select all

apt-get update
apt-get install oracle-java8-installer
This will take a little while, and you'll have to agree to the Oracle terms, so pay attention.

When that is finished you'll want to remove the old Java version. If you had the default oracle-java8-jdk installed, remove it with apt-get remove oracle-java8-jdk, then you can exit the root terminal with exit[enter].

Enter java -version to check your installed version (it should be the latest).

[email protected]:~ $ java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) Client VM (build 25.144-b01, mixed mode)


Congrats, you now have the latest Java.

Re: How to install Java 8 on Raspbian?

Posted: Fri Mar 23, 2018 1:58 am
by bhamail
@HawaiianPi Thanks. Your post worked great for me.

Re: How to install Java 8 on Raspbian?

Posted: Sat Apr 07, 2018 9:58 am
by dazz100
Hi
I have just done a fresh install of the latest version of Raspian Stretch and Java wasn't installed.
I had to install it manually.

Re: How to install Java 8 on Raspbian?

Posted: Sun Apr 08, 2018 7:57 pm
by HawaiianPi
dazz100 wrote:
Sat Apr 07, 2018 9:58 am
Hi
I have just done a fresh install of the latest version of Raspian Stretch and Java wasn't installed.
I had to install it manually.
Only the Desktop version has it pre-installed. The Lite version would need you to install it. And the version in the repos is still super old.

Code: Select all

~ $ 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)
Latest Java 8 from Oracle is now 8u161

Code: Select all

~ $ 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)

Re: How to install Java 8 on Raspbian?

Posted: Mon Apr 09, 2018 2:39 pm
by Teapot
You can also give a try to OpenJDK 10 or 9.

E.g. certified Liberica one https://www.bell-sw.com/java-for-raspberry-pi.html

There are .tar.gz and .deb download options.

Re: How to install Java 8 on Raspbian?

Posted: Fri May 04, 2018 10:46 am
by danieldixon
Hi,

Installation

First install dirmngr:
sudo apt-get install dirmngr

Second add deb repositories and key:

Code: Select all

echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
Warning! If you add xentail repositories (as many RPi forums and other pages state) you’ll end up with old 1.8.0_65 version, you must be using trusty repositories in order to install latest Java version.

Update repositories:

sudo apt-get update

Install Java installer:
1

Code: Select all

sudo apt-get install oracle-java8-jdk
Verify Java version

To be 100% sure I have proper version of Java I use basic command:


java -version

Remove old Java

In case you have old Java 8 JDK

Code: Select all

sudo apt-get remove --purge oracle-java8-jdk


Hope that Helps! 8-)
Regards,
Techtiq Solutions,

Re: How to install Java 8 on Raspbian?

Posted: Sun May 06, 2018 9:02 am
by HawaiianPi
danieldixon wrote:
Fri May 04, 2018 10:46 am
Hi,

Installation
...
You just posted what I posted last year, only with incorrect information.
danieldixon wrote:
Fri May 04, 2018 10:46 am
Warning! If you add xentail repositories (as many RPi forums and other pages state) you’ll end up with old 1.8.0_65 version, you must be using trusty repositories in order to install latest Java version.
Nope, that is completely false. 8u65 is what's in the Raspbian repositories. Installed the way I outlined above you get the latest version.

Code: Select all

~ $ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) Client VM (build 25.171-b11, mixed mode)