How to install Apache Maven on Amazon EC2 instance
Simple article to show you how you can install latest version of Apache Maven on an Amazon EC2 instance in few quick and easy steps. Things like directory structure is purely a personal preference.
Requirements
- java 1.7 (assumed installed)
- amazon ec2 instance (assumed available)
- apache maven
As you log-in to your EC2 instance using ‘ec2-user’, you are now in your home directory.
1 2 3 | /home/ec2-user |
Get the latest version of Apache Maven from the mirror service
1 2 3 | $ wget http://www.mirrorservice.org/sites/ftp.apache.org/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz |
This will download the latest Apache Maven (3.2.1 as of this writing) tar file into your home directory. Untar the file using
1 2 3 | $ sudo tar -xzvf apache-maven-3.2.1-bin.tar.gz |
This will create a folder apache-maven-3.2.1 in your home directory. You can now move this directory to your desired location. My personal preference is to move it to /usr/local/maven or /usr/share/maven
1 2 3 | $ sudo mv /home/ec2-user/apache-maven-3.2.1 /usr/local/maven |
Another personal preference is to create a version agnostic symlink to the latest version of the maven installation. This allows you to change/upgrade versions without having to change exported paths etc.
1 2 3 | $ sudo ln -s /usr/local/maven/apache-maven-3.2.1 /usr/local/maven/current |
Now we add the path of the current maven installation to ec2-user bash profile, so that it is available to us whenever we login
1 2 3 | $ sudo vim ~/.bashrc |
And add the following paths to the ec2-user bash profile
1 2 3 4 5 6 | export MAVEN_HOME=/usr/local/maven/current export M2_HOME=/usr/local/maven/current export M2=/usr/local/maven/current/bin export PATH=/usr/local/maven/current/bin:$PATH |
Reload your bash profile using
1 2 3 | $ source ~/.bashrc |
You can check your maven installation using
1 2 3 4 5 6 7 8 | $ mvn -version Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9;2014-02-14T17:37:52+00:00) Maven home: /usr/local/maven/current Java version: 1.7.0_55, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.55.x86_64/jre .... |