Install and Configure Maven Tutorial
Table of Contents
This article discusses Maven, which is the latest released version: Apache Maven 3.9.8
.
System Requirements
The following are the system requirements for installing this version:
Java Development Kit (JDK): Maven 3.9+ requires JDK 8 or above to execute. It still allows you to build against 1.3 and other JDK versions by using toolchains.
Memory:No minimum requirement
Disk:Approximately 10MB is required for the Maven installation itself. In addition to that, disk space will be used for your local Maven repository. The size of your local repository will vary depending on usage but expect at least 500MB.
Operating System:No minimum requirement. Start up scripts are included as shell scripts (tested on many Unix flavors) and Windows batch files.
Official Maven Download Address: https://maven.apache.org/download.cgi.
Installing in Windows
Download Maven
For Windows systems, you need to download the “Binary zip archive” package, usually formatted as apache-maven-x.x.x-bin.zip
,The downloaded Maven package is: apache-maven-3.9.8-bin.zip.
Install Maven
Unzip the downloaded apache-maven-3.9.8-bin.zip
, and move the resulting folder apache-maven-3.9.8
to a suitable location. Normally, I place the unzipped folder under D:\dev-env\maven
.
Since the download is a binary compressed package, there is no need to install it after decompressing the package, just use it directly. Therefore, my Maven installation directory is D:\dev-env\maven\apache-maven-3.9.8
.
Configure Maven system environment variables
In order to use Maven at anywhere in Windows, we need to add the MAVEN_HOME
to the system environment variables and include the Maven bin
directory in the Path
system environment variable.
My Computer => Right-click => Properties => Advanced system settings => Environment Variables => System variables
- Create a new system variable, which name:
MAVEN_HOME
, Variable value:D:\dev-env\maven\apache-maven-3.9.8
; - Change the system variable, which name:
Path
, append to the original variable value:D:\dev-env\maven\apache-maven-3.9.8\bin
;
Verify the successful installation
Type Win + R
to open the command line prompt window (DOS interface), enter mvn --version
, and if the content shown in the following figure appears, the configuration is successful.
Configure maven local repository
In the Maven configuration (in the conf
folder), find the configuration file settings.xml
, edit the file, and specify the address of the Maven local repository using the <localRepository>
tag:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
D:\dev-env\maven\repos
Configure Maven aliyun mirror repository
By default, Maven accesses foreign repositories to download JAR packages. To prevent slow downloads of JAR packages when using Maven in China, it is necessary to change it to the Alibaba Cloud Maven mirror repository[1].
Edit the Maven configuration file settings.xml
, and within the <mirrors>
tag, add the configuration for the Alibaba Cloud mirror repository:
public-aliyun
public
Aliyun public
https://maven.aliyun.com/repository/public
Installing in Linux
First, connect to the Linux system via an SSH remote connection tool. I am using the system’s built-in terminal tool with the following command line: ssh user@ip
> ssh user@ipaddress
Where user
is the login username, and ipaddress
is the Linux access IP address
Download Maven
Download the Maven Linux installation package apache-maven-3.9.8-bin.tar.gz through the following command line:
> wget https://dlcdn.apache.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz
Install Maven
Place the downloaded installation package in the /usr/local/
directory on the disk, and unzip the installation package:
> tar -zxvf apache-maven-3.9.8-bin.tar.gz
Since the download is a binary compressed package, there is no need to install it after decompressing the package, just use it directly.
Configure Maven system environment variables
In order to use Maven properly, you need to add the MAVEN_HOME
system environment variable to the system environment variables, and also add the Maven bin
directory to the PATH
system environment variable.
Edit the /etc/profile
file, that is, vi /etc/profile
, and add the following content:
export MAVEN_HOME=/usr/local/apache-maven-3.9.8
export PATH=${PATH}:${MAVEN_HOME}/bin
Replace ${PATH}
with the original PATH
content. After saving the configuration, enter the following command to make the configuration take effect:
> source /etc/profile
We can verify if Maven is working properly by using the command mvn -v
.
Other configurations are the same as the Windows installation.
Refer to the Alibaba Cloud Maven User Guide: https://developer.aliyun.com/mvn/guide ↩