The following installation instructions are provided to install, upgrade, and uninstall the Pi4J libraries, examples, utility scripts, etc. directly on your Rasbperry Pi. These instructions are not intended to install Pi4J on your development workstation or other computer. For development conducted on a computer other than the Raspberry Pi, please access the Pi4J JAR dependencies via the Maven repository or download them directly and reference them in your project.
If you are using a recent build of Raspbian, then an Oracle Java runtime environment is pre-installed. Nothing more to do.
If you are using an older Raspbian build that does not already include a Java runtime environment, please see the following article for a complete set of installation instructions for installing the Oracle JDK.
Pi4J depends on the WiringPi native library by Gordon Henderson. Please see the following page for more information on WiringPi.
No installation is required for Wiring Pi. Wiring Pi is embedded in the Pi4J native library.
(NOTE: This installation method requires that your RaspberryPi is connected to the Internet.)
The simplest method to install Pi4J on your RaspberryPi is to execute the following command directly on your RaspberryPi.
curl -s get.pi4j.com | sudo bash
This method will download and launch an installation script that perform the following steps:
If you prefer/need to install Pi4J on a RaspberryPi device without an Internet connection, the following instructions provide the steps necessary to install Pi4J without requiring an Internet connection.
First, download a copy of the latest Pi4J Debian/Raspian installer package (.deb) file to your local computer. You can download the Pi4J Debian/Raspian installer package (.deb) using your web browser at the following URL:
Next, you will need to transfer the download installer package over to your RaspberryPi. You can use any method you prefer to transfer the file (USB, SCP, FTP, etc.)
(NOTE: If you have a previous version of Pi4J installed, you will need to uninstall it first.)
Once the installer package is available on your RaspberryPi, use the following command on the Pi to perform the installation:
sudo dpkg -i pi4j-1.1.deb
If you originally installed Pi4J using the 'easy' method, then Pi4J upgrades will be available anytime you perform a system update using 'sudo apt-get update' and 'sudo update-get upgrade'.
If you wish to force an upgrade of the Pi4J package only, you can do so by executing the following command:
sudo apt-get install pi4j or pi4j --update
If you originally installed Pi4J using the 'easy' method, then you can uninstall Pi4J simply by executing the following command on your RaspberryPi.
sudo apt-get remove pi4j or pi4j --uninstall
If you originally installed Pi4J using the 'easy' method and you want to remove all traces of Pi4J, including the Pi4J repository in the APT repositories list and the Pi4J GPG signature, then simply execute the following command on your RaspberryPi.
curl -s get.pi4j.com/uninstall | sudo bash
This will install the Pi4J libraries and example source files to:
When attempting to compile a Java program using the Pi4J libraries, make sure to include the Pi4J lib folder in the classpath:
javac -classpath .:classes:/opt/pi4j/lib/'*' ...
When attempting to start a Java program using the Pi4J libraries, make sure to include the Pi4J lib folder in the classpath:
sudo java -classpath .:classes:/opt/pi4j/lib/'*' ...
If you would like to explore the examples, you can compile all the examples with the following commands: