Difference between revisions of "RPi Java JDK Installation"

From eLinux.org
Jump to: navigation, search
(How To Install the Java JDK on the Raspberry Pi/Debian Wheezy image)
 
(Tweak incorrect URLs)
Line 22: Line 22:
  
 
=Installing the software=
 
=Installing the software=
Login to the computer, activate a web browser, and navigate to the [[http://www.oracle.com/technetwork/java/javase/downloads/index.html| Oracle Java SE Downloads]] download page.
+
Login to the computer, activate a web browser, and navigate to the [[http://www.oracle.com/technetwork/java/javase/downloads/index.html | Oracle Java SE Downloads]] download page.
[The Midori browser has had trouble interfacing to this page.  This download page has been successfully downloaded using the [[RPi_IceWeasel| Iceweasel]] browser.]
+
[The Midori browser has had trouble interfacing to this page.  This page has been successfully handled using the [[RPi_IceWeasel| Iceweasel]] browser.]
 
Click on the JDK Download link.
 
Click on the JDK Download link.
 
Read and accept the Oracle Binary Code License Agreement for Java SE.
 
Read and accept the Oracle Binary Code License Agreement for Java SE.
Line 57: Line 57:
 
  Java HotSpot(TM) Client VM (build 23.6-b04, mixed mode)
 
  Java HotSpot(TM) Client VM (build 23.6-b04, mixed mode)
  
Some java programs require that a JAVA_HOME environment variable be defined and the java executable added to the system PATH.  Edit the file /etc/environment with an editor of your choice (eg. nano):
+
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"
 
  sudo nano "/etc/environment"
Line 69: Line 69:
 
  export JAVA_HOME="/opt/java/jdk1.7.0_10"
 
  export JAVA_HOME="/opt/java/jdk1.7.0_10"
 
  export PATH=$PATH:$JAVA_HOME/bin  
 
  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:
 
Create a new command window to see the environment changes you have made in the above files.  Type the following:
Line 76: Line 78:
 
You should see the above definitions in JAVA_HOME and PATH environment variables.  If desired, do the same after a reboot.
 
You should see the above definitions in JAVA_HOME and PATH environment variables.  If desired, do the same after a reboot.
  
A variation of this information with images can be found at [[http://www.savagehomeautomation.com/pi-jdk| Savage Home Automation]]
+
A variation of this information with images can be found at [[http://www.savagehomeautomation.com/pi-jdk | Savage Home Automation ]]

Revision as of 23:27, 23 February 2013

Back to RPi Guides.

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.

Note that the Java JDK can only be installed on soft-float images (such as Debian Wheezy). This information is NOT usable on the Raspian Wheezy image.

Prerequisites

  • 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:

rm ~/jdk-7u10-linux-arm-sfp.tar.gz

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:

java -version

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"

and add:

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

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:

export

You should see the above definitions in JAVA_HOME and PATH environment variables. If desired, do the same after a reboot.

A variation of this information with images can be found at [| Savage Home Automation ]