Regardless the system you are using, it’s important to have a common location to save development tools. So you won’t have trouble to find them whenever necessary.
I will assume that you have already installed Java. But if you need to download it, here is the link to Java 8. For older versions, you will need to check Java archive. It’s important to know that these archived versions are not updated with the latest security patches.
According to your project setup, Maven 3 needs Java 5 version. But to apply newer versions you will need Java 6 to Maven 3.2+ or Java 7 to Maven 3.3+. At the moment of this writing, we are on version 3.5.0. For more details check Maven history documentation.
Linux and OSX
Unix systems have similar settings. In this case, we can apply the same installing configuration only changing the way to download the file.
On Linux, use
wget -O <output_file> <url> command and on OSX, use
curl -o <output_file> <url>. An important thing is always favoring the download of
.tar files instead of
.zip. It’s because Unix retains all file permissions like execution to scripts, for example.
You can check Maven Archives to select the best version for your project (only for 3.0.4+).
Open the terminal and enter the home directory (
cd ~/) to avoid permission problems. Download the desired version with the following command:
wget -O apache-maven-3.5.0-bin.tar.gzhttps://archive.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz.
Extract the downloaded file with
tar xf apache-maven-3.5.0-bin.tar.gz
A common local to install user’s tools is
/usr/local. So move the extracted folder to this location. At this point, you will need to write privileges. That’s why
sudo is needed.
sudo mv apache-maven-3.5.0 /usr/local/
Almost ready to use. Now you are already able to check the version using the full path.
There are some differences between
.bash_profilefiles. But it’s not the focus entering on Unix details. Let’s use
.bash_profile file for this configuration. This allows saving the configuration for any new terminals.
Ensure that you are in the home directory by
cd ~/. You can check hidden files using the command
The simplest way is to add the PATH at the end of the file. This command bellow will work even if the file doesn’t exist. But note that
>> will append the content to the file. So if you execute multiple times, it will append several times.
echo 'PATH=/usr/local/apache-maven-3.5.0/bin:$PATH' >> .bash_profile
Refresh the configuration using
source .bash_profile. Now it’s possible to use maven anywhere in the system.
Check the complete process below using an Ubuntu with Vagrant.
The main difference of Windows configuration is the environment variable. I’m not a Windows user but I’ll try to show in simple steps how to get started on a right way.
Download and Install
.zip version file at the same place, Maven Archives.
To keep all software development tools centralized on a single place, let’s unzip the downloaded file to
C:\dev\tools. You should install your JDK or other tools here to avoid searching for them later.
Now there are some manual steps to reach the right configuration.
Open the Control Panel and use the search field typing
environment variablesto find the option Edit the system environment variables.
A dialog of System Properties will be presented. Click the button
Environment Variables…. We almost there. Now we need to create the
MAVEN_HOME variable to configure the
On the System variables fieldset (not User variables), click on
New… button. Set the variable name as
MAVEN_HOME and the variable value to
Now you have to scroll and find variable
Path at the same place you added Maven home and click the
Edit… button. To avoid conflict with other installations, it’s important to add the value on the top of the list. So, add
%MAVEN_HOME%\bin. For older Windows versions, maybe you need set the value to the front of Path value and make sure you don’t forget the
; at the end. Now click
OK buttons from all dialogs to finish this process.
You can apply the same process to a JDK installation and configuration of
JAVA_HOME variable if you didn’t do it yet.
Now you can open the Command Prompt (CMD) to check Maven installed version.