Raspberry Pi - Installing Oracle Java Development Kit (JDK 1.7.0u6)
The Oracle JDK for ARM 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 Debian "Wheezy" (2012-08-08 soft-float) image.
(The Oracle JDK is not currently compatible with the Raspian "Wheezy" image) - Enable the Raspberry Pi for SSH remote network connections.
Update: The Debian "Wheezy" image comes with SSH access enabled in the default image.
(Here is an article on how to enable SSH in the Debian Squeeze distribution) - Get the Raspberry Pi's IP address.
Tools & Downloads:
All:
- Raspberry Pi Debian "Wheezy" image (2012-08-08)
- Oracle Java SE Development Kit (Select JDK Download, then Linux ARM - jdk-7u6-linux-arm-sfp.tar.gz)
Windows:
Mac-OSX:
Download the Oracle JDK for the Raspberry Pi
You can download the Oracle Java SE Development Kit 7u6 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 LinuxARM JDK7 SE distribution (jdk-7u6-linux-arm-sfp.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 Debian Squeeze 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
tar xvzf ~/jdk-7u6-linux-arm-sfp.gz
The unpacking process will take a few seconds to complete. It unpacks all the contents of the Oracle JDK tz file to a new directory named "jdk1.7.0_06" located in the user's home directory.
With the unpack complete its now time to move the new unpacked directory to the Java install location that we created earlier under "opt/java".
sudo mv -v ~/jdk1.7.0_06 /opt/java
We can also delete the original .tz file as it is no longer needed
rm ~/jdk-7u6-linux-arm-sfp.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_06/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_06/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_06"
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_06"
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.
Reader Comments (36)
some adjustments to the previous post
write error typing - I wanted to write 512 MB
in the jAVAdOC
http://pi4j.com/apidocs/index.html
can be found
I2C Communication very beautiful great job!
I hope to find other types of buses in the future
hardware part you should use a 3.3 version Max3485
I apologize for that
Luca
Man, you're the one.
This post was very useful and this really rocks.
Congrats!
@Thiago,
Thank You!
I am glad that you found the information helpful.
Also check this page for other useful Raspberry Pi articles:
http://www.savagehomeautomation.com/pi-slices/
Regards, Robert
Great stuff!
Your command above
tar xvzf ~/jdk-7u6-linux-arm-sfp.gz
should actually be:
tar xvzf jdk-7u6-linux-arm-sfp.tar.gz
...and it is up to 7u10 now:
tar xvzf /home/pi/Downloads/jdk-7u10-linux-arm-sfp.tar.gz
I had some difficulty with use of Midori browser, but I installed Mozilla IceWeasel and was able to do all the download stuff directly on my RPi without having to involve my PC (maybe it works with Midori; didn't try). Instead of doing the tar to my home directory and moving the extracted files, I did an extract in place with:
sudo -i
cd /opt/java
tar xvzf /home/pi/Downloads/jdk-7u10-linux-arm-sfp.tar.gz
and then ownership is correct and I don't need to move files around. If you do this, you can drop the stuff on this page about WinSCP and copying between Windows/Apple machines..
@Harvey,
Thanks for the comments and corrections. FYI, there is newer article posted here for JDK 7u10 and JSK 8 SE (ea)
http://www.savagehomeautomation.com/raspi-jdk7
http://www.savagehomeautomation.com/raspi-jdk8
I went back to check on the file names and it looks like if you download via Windows the file name does not include ".tar.gz", just ".gz". The link on the web page definitely says ".tar.gz", but the actual download file did not include it. Perhaps Oracle is detecting the operating system a users is downloading with and giving a different file name?
I'll try it next time using the browser via the user interface on the Raspberry Pi.
Thanks, Robert
Hi
very good guide,
i followed it and java environnement is working well. However I can't use the javac compiler and i'm not sure of how i can use it.
I wanted to use it with the pi4j library, but i did not find any mentioned trick on the website.
@Jérôme,
Try the commands listed on this page to make sure that your default Java configuration in Debian is pointing to the correct/desired JVM.
http://www.savagehomeautomation.com/projects/raspberry-pi-change-default-java-virtual-machine-jvm.html
Also, there is a newer version of Java available for the Pi:
http://www.savagehomeautomation.com/raspi-jdk7
Thanks, Robert
Hi,
Thanks for the fast answer, i did try with the 2 version of jdk (7.6 &7.10) just to be sure but i have the same problem. Moreover Debian is pointing to the good version as there is only one.
And i really can't find why I miss the compiler
Hi again, sorry for multiple posting.
It's just to signal that played the fool and forgot to signal the javac thing to the system as it's specified for java :
sudo update-alternatives --install "/usr/bin/java" "javac" "/opt/java/jdk1.7.0_06/bin/javac" 1
sudo update-alternatives --set java /opt/java/jdk1.7.0_06/bin/javac
Now it's working as I hoped..
Thanks
Hi,
I want to use Java SE embedded on the Pi. I downloaded it on my Windows PC from the Oracle website. With a USB-Stick I copyed it on the Pi.
While typing " java -version" i get the following message: bash: java: command not found (I am using Raspbian as OS)
Can you maybe tell me what is the problem?
Thanks,
Wiss
Thank you for the great guide! One quick question - when I do the sudo update-alternatives --install command, after I enter it I do not get the feedback that you do above that states, "update-alternatives: using (etc..)", I simply get nothing, and then when I go to check the version it does not work. Any ideas?
Hello, thanks but I am a bit confused: what's wrong with the package shipped with the debian weezy distribution?? The one that you can install by simply executing:
sudo apt-get install openjdk-7-jre
I've heard that some versions of Java doesn't use the floating point processor of the raspberry pi and that is a problem. Anyone has an idea of how to detect that??
Hallo,
can sameone help me?
Link "Raspberry Pi Debian "Wheezy" image" is dead.
Where can I get the Image, please help me
One comment on using the RXTX lib on the Raspberry PI:
I have installed it and it works just fine for USB-Serial adapters - however, RXTX does not seem to detect the internal serial interface on the GPIO expansion port - although I can use it with minicom and also with pi4j (after having disabled the serial console).
Very good tutorial for beginners that uses Raspberry Pi minicomputer. I add this tutorial in a series of tutorials from where the users can learn how to start working with this device.
Your tutorial about installing raspberry pi help me and others to get started with Pi. Thank you!