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.
- Download the Binary tar.gz version the maven website. Pick the latest version.
wget http://www.mirrorservice.org/sites/ftp.apache.org/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz
- Extract the archive to /opt.
cd /opt && sudo tar -xzvf /path/to/apache-maven-3.2.5-bin.tar.gz
- 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 enter
export M2_HOME=/opt/apache-maven-3.2.5
export "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 with
mvn -version
and you should see something like
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)
Maven home: /opt/apache-maven-3.2.5
Java version: 1.8.0, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.12.26-rt40+", arch: "arm", family: "unix"
Very helpful! Thanks
LikeLike
in the last step where we are writing mvn -version it is showing mvn command not found
LikeLiked by 1 person
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.
LikeLike
I’m having a similar issue as Jay
When I run `echo $PATH` I get:
‘/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/apache-maven-3.2.5/bin’
So that looks good. But when I try `ls -l /opt/apache-maven-3.2.5/bin/mvn` I get:
‘ls: cannot access ‘/opt/apache-maven-3.2.5/bin/mvn’: No such file or directory’
I have tried both copy/pasting the content from step 3 as well as manually entering it and I’m sure each character is correct.
What do you suggest?
LikeLike
[SOLVED]
Looks like I solved my own problem right after I asked for help; turns out I had extracted the archive to /etc/opt instead of /opt (I still have a lot to learn with using a CLI)
Thanks for posting this article!
LikeLike
having similar issue
echo $PATH output
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
LikeLike
There is now a much easier way to install maven on a raspbery pi:
sudo apt update && sudo apt install maven
This works on the latest release of Raspbian. The article was written at a time when it was not that easy.
LikeLike
Hey! I just tried it and it worked. Thanks for the article.
LikeLike