What is Maven?
Maven is essentially a build automation tool similar to apache ant but provides much more features that just building. It addresses two important aspects -
- how your software will be built and
- your software dependency resolution
Lets get started then.
How to install Maven?
You can search for the maven package using the following command
apt-cache search maven
You may see a lot of packages but what we are interested is -
maven - Java software project management and comprehension tool
So lets go ahead and install it. Use the following command to install the package
sudo apt-get install maven
I am using Ubuntu so I have apt-get. You can use yum if you have Fedora/CentOS.
To verify the installation you can simply execute the following command
mvn -v
v here stands for version. You can also type complete word i.e mvn -version.
You will see some details about the installed maven package.
This indicated maven is successfully installed.
Install latest versions
Using apt-get you may not get the latest version of maven. For latest version download the binary from maven site and install it.
Use the following commands -
- cd ~/Downloads
- wget http://apache.mirrors.timporter.net/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz
- sudo mkdir -p /usr/local/apache-maven
- sudo mv apache-maven-3.1.1-bin.tar.gz /usr/local/apache-maven
- cd /usr/local/apache-maven
- sudo tar -xzvf apache-maven-3.1.1-bin.tar.gz
- Edit ~/.profile with gedit ~/.profile and add these four lines:
- export M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
- export M2=$M2_HOME/bin
- export MAVEN_OPTS="-Xms256m -Xmx512m"
- export PATH=$M2:$PATH
Next immediate question that may come to anyone’s mind -
Where is maven installed?
Maven by default gets installed in the following directory
/usr/share/maven
and maven configuration files go to the following directory
/etc/maven
settings.xml has default configurations like path to local repository. yes maven downloads dependencies and stores it in a local repository so that there is no need to download same dependency twice.
Path to maven(mvn) executable is not added to $PATH variable then how is the command recognized?
If you print your path variable by using
echo $PATH
You will notice one of the paths in the variable is
/usr/bin
Now if you see the contents of /usr/bin you will notice that it has mvn executable. It is actually soft link to the actual executable. This approach is a common approach. We cannot keep adding all installed packages folder to $PATH. Instead create a soft link to executable and keep it in /usr/bin and add this to the $PATH.
This was just how do we install maven on ubuntu. In the next post we will see how to compile and run Java code using maven.
No comments:
Post a Comment