44

I am an experienced Java programmer who received the Raspberry Pi for Christmas. Unfortunately, it appears that only Python is installed in it. What command do I type at the start command line where I would usually type startx to install the JDK and JRE?

Peter Mortensen
2,0042 gold badges15 silver badges18 bronze badges
asked Jan 26, 2013 at 12:10
2
  • 1
    GCC is also installed in the default distribution so C and C++ are also options. Commented Sep 11, 2013 at 21:47
  • 1
    A stable release of Oracle's JDK 7 is finally available (see my answer below). Unlike JDK 8, it's not a beta and it's still fast. Commented Sep 14, 2013 at 20:01

7 Answers 7

24
+50

[Note: Later in 2013 the Pi Foundation announced Raspbian now ships with Oracle hard-float.]

The oracle 8 preview works for me, thus far. Compiling is slow on the pi, surprise, but the jre seems to run quite fast once it loads. I think bearbin's answer is pretty definitive but if you want a simple way to try oracle:

  1. Download. You get a .tar.gz file, which is a gzipped tarball.
  2. Put the .tar.gz in /usr/local and unpack it: tar -xzf oracle8-blah-blah.tar.gz. This will create a directory with everything in it. You can rename the directory, mv oracle-jdk-whatever jdk1.8.0. Everything in there is self-contained.
  3. Put the bin/ directory at the beginning of your executable search $PATH. If there are any other javas installed, that will make this one take precedence: PATH=/usr/local/jdk1.8.0/bin:$PATH.

That will only work for your current shell. To make it the default from now on, add this to ~/.profile:

export PATH=/usr/local/jdk1.8.0/bin:$PATH

Note you must log in again to make .profile effective. However, if you are using lightdm, the default GUI login won't do this, see here for a solution.

answered Feb 10, 2013 at 19:01
1
  • This helped me carry out a solution to an issue which someone else (and myself) was experiencing. +1 Commented Dec 8, 2019 at 19:40
43

To install the Java Runtime Environment (JRE) run the following command:

sudo apt-get install openjdk-7-jre

This installs the Java JRE (Java Runtime Environment) which will allow you to run applications written in Java.

To install the JDK run the command:

sudo apt-get install openjdk-7-jdk

This allows you to compile Java applications to bytecode.

If you want the Oracle Java VM, which is a lot faster (optimized for embedded arm CPUs) and is also a developer preview (applications maybe buggy or crash) until some time into the future. Instead of the above instructions you need to download the file called Oracle JDK 8 (with JavaFX) for ARM Early Access on the Oracle Java 8 download page.

Remember to download the Oracle Java system on your Pi, or you won't be able to install it.

To install the Oracle Java System:

sudo tar zxvf jdk-8-ea-b36e-linux-arm-hflt-*.tar.gz -C /opt
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk1.8.0/bin/java" 1 
sudo update-alternatives for other commands if needed (e.g. javac).
java -version

Then it is all installed.

Another thing, if you have more then one Java runtime installed you have to check which version you use with the command java -version. If the output is:

java version 1.5.0 gij (GNU libgij)

Then you are using another java runtime. You can resolve the issue by running

sudo update-alternatives --config java

and choosing the OpenJDK or Oracle option.

answered Feb 5, 2013 at 18:19
8
  • when running tar zxvf jdk... command, two errors (second is repeated): tar (child): jdk...tar.gz: no such file or directory tar (child): fatal error received. exiting now Commented Feb 6, 2013 at 18:06
  • @imulsion The file may have a slightly different name - type the ls command and use the file with a similar name instead. Commented Feb 6, 2013 at 18:15
  • what to type after ls? Commented Feb 6, 2013 at 18:30
  • tar zxvf [] where [] is the file with a similar name. Commented Feb 6, 2013 at 18:47
  • 1
    Only because you are copying to /opt. You wouldn't normally need it. Commented Jun 21, 2013 at 4:35
8

Installing Oracle Java 7 JDK (but not JRE) hard-float for RPi is now as stunningly easy as:

sudo apt-get update && sudo apt-get install oracle-java7-jdk

(source)

I used to go through the old processes that were linked above, but since they easyfied it, now I just do this.

answered Oct 20, 2013 at 20:32
1
  • 1
    Better yet, if your Wheezy comes from 2013年09月25日-wheezy-raspbian or later (here), Oracle Java 7 JDK appears to be pre-installed. Commented Oct 21, 2013 at 22:45
4

sudo apt-get install java-runtime

This is OpenJDK 6.

Oracle JDK is not available in armhf flavor, so you have to use a soft-float image to use it.

answered Jan 26, 2013 at 15:31
2
  • 3
    Oracle JDK 8 is available in a developer preview. For my case it is working without any problem. raspberrypi.org/phpBB3/viewtopic.php?f=81&t=26110 Commented Jan 26, 2013 at 18:36
  • @M Noit it says there are loads of packages that i can install and i need to specify one. what to type in? Commented Feb 5, 2013 at 17:26
2

Oracle have provided a step by step guide of how to setup Java SE Embedded on a Raspberry Pi device. They include information on the essential linux setup and some details of optional tweaking/optimisations

http://www.oracle.com/technetwork/articles/java/raspberrypi-1704896.html

answered Aug 15, 2013 at 8:09
0

Detailed instructions for Java SE Embedded from Oracle are provided here.

answered Sep 11, 2013 at 21:50
0

Nowadays, instead of the Early Access JDK 8, you can install the hardfloat version of Oracle JDK 7, which has full support from Oracle (unlike the JDK 8).

Oracle's current download page (the same as other Java releases): http://www.oracle.com/technetwork/java/javase/downloads/index.html

(No JRE is available, you need to download the full JDK).

Announcement: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=81&t=49588

For installation, you can refer to bearbin's answer.

answered Sep 14, 2013 at 20:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.