RPi Java JDK Installation
Back to RPi Guides.
Installing OpenJDK on a Raspberry Pi (Debian Wheezy or Rasbian Wheezy)
OpenJDK based on IcedTea is packaged for both soft and hardfloat systems. Installation of OpenJDK is easy:
sudo apt-get update
sudo apt-get install openjdk-7-jdk
Installing IcedTea-web browser plugin and javaws 'jnlp' webstart
OpenJDK support the IcedTea-web browser plugin for using java applets inside the midori browser.
sudo apt-get update
sudo apt-get install icedtea-7-plugin
Installing The Oracle Java SE7 JDK on a Raspberry Pi (Debian Wheezy)
What does it do?
This page shows how to install the Oracle Java SE JDK7 on the Raspberry Pi Debian Wheezy image.
If you want to use Oracle JDK 7 or 8 on a hardflaot "Rasbian" Wheezy image then you need to get the early access version from java.net
- http://www.raspberrypi.org/phpBB3/viewtopic.php?f=81&t=49588 - Oracle JDK 7u40 EA hardfloat available
- http://www.raspberrypi.org/phpBB3/viewtopic.php?f=81&t=49497 - JDK 8 for ARM Early Access Releases (with JavaFX)
- http://www.raspberrypi.org/phpBB3/viewtopic.php?f=81&t=27805 - status of java on Raspbian
- A booted Raspberry Pi with keyboard, mouse, monitor
- A network connection (Ethernet or WiFi).
- Authorization to use root privileges.
Installing the software
Login to the computer, activate a web browser, and navigate to the [|Oracle Java SE Downloads] download page. [The Midori browser has had trouble interfacing to this page. This page has been successfully handled using the Iceweasel browser.] Click on the JDK Download link. Read and accept the Oracle Binary Code License Agreement for Java SE. Download the current file for "Linux ARM v6/v7 Soft Float ABI" and save in a location where you have write access. Your home directory will be assumed for the following instructions.
The following directions assume that you are installing version 7u10 of the JDK. Adjust the filenames appropriately if you downloaded and are installing a different version.
Activate a terminal window by either double click on either of the "LXTerminal" or "Root Terminal" icons or menu "Accessories -> LXTerminal" or "Accessories -> Root Terminal". Type the following commands in the terminal to create an installation directory and unpack the downloaded file:
sudo mkdir -p /opt/java sudo chown root:root /opt/java cd /opt/java sudo tar xvzf ~/jdk-7u10-linux-arm-sfp.tar.gz
This should create directory /opt/java/jdk1.7.0_10 (or similar, depending on the version you downloaded). If the tar command completes correctly, the downloaded file in your home directory can be deleted:
The system needs to know that a JVM has been installed, where it can be found on the system, and which is the default version (if there is more than one choice available). Type the following in the command window:
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.7.0_10/bin/java" 1 sudo update-alternatives --set java /opt/java/jdk1.7.0_10/bin/java
Java should now be successfully installed. To test this, request the java version with:
You should get a response showing the version that you just installed.
java version "1.7.0_10" Java(TM) SE Runtime Environment (build 1.7.0_10-b18) Java HotSpot(TM) Client VM (build 23.6-b04, mixed mode)
To use all java programs, you need to define a JAVA_HOME environment variable and add the associated bin directory to the system PATH. Edit the file /etc/environment with an editor of your choice (eg. nano):
sudo nano "/etc/environment"
Similarly, add the following line in an appropriate place in your ~/.bashrc file:
export JAVA_HOME="/opt/java/jdk1.7.0_10" export PATH=$PATH:$JAVA_HOME/bin
This will need to be done for each username on the system.
Create a new command window to see the environment changes you have made in the above files. Type the following:
You should see the above definitions in JAVA_HOME and PATH environment variables. If desired, do the same after a reboot.