Contributions

Contributions are appreciated and used to host this site. Thank You for your support.

Feature Products
  • Raspberry Pi with Java: Programming the Internet of Things (IoT)
    Raspberry Pi with Java: Programming the Internet of Things (IoT)
  • Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
    Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
  • Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
    Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
  • Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
    Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
  • Getting Started with Raspberry Pi
    Getting Started with Raspberry Pi
  • Raspberry Pi User Guide
    Raspberry Pi User Guide
  • PiBrella LED Add On Board
    PiBrella LED Add On Board
  • Diversitech® WS-1 - Wet Switch Flood Detector
    Diversitech® WS-1 - Wet Switch Flood Detector
  • Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
    Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
  • Floodstop Washing Machine Valve Shutoff Kit
    Floodstop Washing Machine Valve Shutoff Kit
  • Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
    Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
  • Floodstop Individual Water Appliance Additional Water Sensor XS-01
    Floodstop Individual Water Appliance Additional Water Sensor XS-01
  • Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
    Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
  • Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
    Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
  • Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
    Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
  • Metra 70-2002 Radio Wiring Harness for Saturn 00-05
    Metra 70-2002 Radio Wiring Harness for Saturn 00-05
  • Metra Reverse Wiring Harness 71-2002 for Select 2000-2005 Saturn Vehicles OEM Radio
    Metra Reverse Wiring Harness 71-2002 for Select 2000-2005 Saturn Vehicles OEM Radio
Friday
Sep132013

Raspberry Pi - Installing Oracle Java Development Kit (JDK 7u40)

UPDATE!

The Oracle Java SE 7 JDK/JRE now comes pre-installed in Raspbian images!
See this post for more details:  Oracle JDK/JVM Now Pre-Installed on Raspbian

The Oracle JDK7 for ARM v6/7 (hard-float ABI) is now available!  This article will provide the necessary instructions on how to install the Oracle Java Development Kit (JDK) on your Raspberry Pi.  

Prerequisites

  • Install and boot the Raspberry Pi using the Rasbian "Wheezy" (2013-07-26 or newer) image.  
  • Enable the Raspberry Pi for SSH remote network connections.  
    Update:  The Debian "Wheezy" image comes with SSH access enabled in the default image.
  • Get the Raspberry Pi's IP address.

Tools & Downloads:

All:

Windows:

Mac-OSX:

Download the Oracle JDK for the Raspberry Pi

You can download the Oracle Java SE Development Kit 7u40 on this page:
http://www.oracle.com/technetwork/java/javase/downloads/index.html

First, select JDK Download button under JDK SE 7, then select the Linux ARM v6/v7 VFP Hard Float AB distribution (jdk-7u40-linux-arm-vfp-hflt.tar.gz). 

Transfer the Oracle JDK to the Raspberry Pi

After downloading the Oracle JDK to you desktop computer, we need to transfer it over to the Raspberry Pi.  We will use SCP to transfer the file over the network.  If you are running on a Windows desktop, then download and install WinSCP.

 If you are using Mac OSX, you can download and install Cyberduck.  The screens will look different but the goals are the same.

Create a new session in WinSCP using the IP address of you Raspberry Pi.  The default authentication credentials for the Raspbian Wheezy image is username "pi" and password "raspberry".  Save the session and then login.  You may be prompted to accept the SSH fingerprint, choose "Yes" to accept and continue.

After successfully establishing a connection, select the drive and folder location in the left pane where you download the Oracle JDK file to on your local desktop system.  In the right pane is the file system on the Raspberry Pi, we will leave it in it's default location in the "pi" user's home directory.  Drag and drop the Oracle JDK file from the left pane to the right pane and WinSCP will start the file transfer process.  You will be prompted with a transfer dialog, just click the "Copy" button to start the transfer.  


When the file transfer is complete, you can close WinSCP (or CyberDuck).

Installation Procedure on Raspberry Pi

The remaining steps should be performed directly on the console of the Raspberry Pi or using a SSH terminal connection with shell access.  In the last step, we transfered the Oracle JDK file to the "pi" user's home directory.  We should be logged in as the "pi" user and already in the user's home directory.

Lets create a new directory where we will install the JDK files to. 

sudo mkdir -p -v /opt/java

Next, lets unpack the Oracle JDK .gz file using this command:

sudo tar xvzf ~/jdk-7u40-linux-arm-vfp-hflt.gz -C /opt/java

The unpacking process will take a few seconds to complete.  It unpacks all the contents of the Oracle JDK gz file to a new directory named "jdk1.7.0_40" located in the "/opt/java" directory.

We can now delete the original .gz file as it is no longer needed 

rm ~/jdk-7u40-linux-arm-vfp-hflt.gz

To complete the JDK installation we need to let the system know there is a new JVM installed and where it is located.  Use the following command to perform this task.

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.7.0_40/bin/java" 1

And finally we also need to tell the system that we want this JDK to be the default Java runtime for the system. The following command will perform this action.

sudo update-alternatives --set java /opt/java/jdk1.7.0_40/bin/java

Now java is installed.  To test and verify we can execute the java command using the version argument.

java -version

You should get the following response:

That's it the Oracle JDK is installed and ready for use.

Add JAVA_HOME Environment Variable

Some Java programs require a JAVA_HOME environment variable to be configured on the system.  Add the following line to you "/etc/environment" using your favorite text editor.

JAVA_HOME="/opt/java/jdk1.7.0_40"


Also, edit your "~/.bashrc" file using this command

nano ~/.bashrc

and add the following two lines to the bottom of the file and save.

export JAVA_HOME="/opt/java/jdk1.7.0_40"
export PATH=$PATH:$JAVA_HOME/bin 


Reboot or re-login to apply the export to your environment.  

 

* Raspberry Pi is a trademark of the Raspberry Pi foundation.
* Oracle and Java are registered trademarks of Oracle.

 


If you prefer to install the JDK8 developer preview/early access version, please see this page:
Install Oracle Java SE8 (Milestone 8) Developer Preview (JDK)

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (3)

Hi, I tried this, but received an error when running java -version.

It said "/usr/bin/java" no such file or directory.

Any ideas?

September 27, 2013 | Unregistered CommenterAlun

Sorry, ignore me, did it on a clean install and it worked fine!

September 27, 2013 | Unregistered CommenterAlun

@Alun,

Glad you got it working. FYI .. Oracle and Raspberry Pi are now including the Oracle JDK7 in the Raspbian distribution.
See this post: http://www.raspberrypi.org/archives/4959

Thanks, Robert

September 29, 2013 | Registered CommenterRobert Savage

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« Raspberry Pi - Installing Oracle Java SE 8 (Milestone 8) Developer Preview | Main | Raspberry Pi - Pi4J Version 0.0.5 Released! »