Installing maven on the Raspberry Pi

The Raspberry Pi‘s raspbian image comes with oracle-java8-jdk already installed and I wanted to use this with maven. However if you install maven using apt-get it will install all kinds of other JDKs and things you don’t need. The solution to this is to install maven from it’s binary distribution. This is quite easy as everything it needs is already installed.

Tell you shell where to find maven. We’ll do this in the system profile settings so it is available to all users.sudoedit /etc/profile.d/maven.sh
and enterexport M2_HOME=/opt/apache-maven-3.2.5export "PATH=$PATH:$M2_HOME/bin"
Quit and save from the editor.

Log out and back into the Raspberry Pi so the profile script takes effect and there it is. You can test that it is working withmvn -version
and you should see something likeApache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)Maven home: /opt/apache-maven-3.2.5Java version: 1.8.0, vendor: Oracle CorporationJava home: /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jreDefault locale: en_GB, platform encoding: UTF-8OS name: "linux", version: "3.12.26-rt40+", arch: "arm", family: "unix"

Run `echo $PATH` and check that the output contains /opt/apache-maven-3.2.5/bin and make sure you have logged out and back in again. If not then /etc/profile.d/maven.sh not have been created correctly.
You can also check that `ls -l /opt/apache-maven-3.2.5/bin/mvn` shows you an executable file.