This section refers to the
MAVEN_HOME environment variable.
This variable contains the path to the Apache Maven binary distribution (where Maven is installed).
The environment variable is optional but it's recommended,
to simplify integration with applications that use it to locate the default Maven installation.
You can add the "
${MAVEN_HOME}/bin" directory
to your
PATH environment variable.
You can also configure the
M2_REPO environment variable
to specify an alternative path to the
repository folder
(default is
"${user.home}/.m2/repository").
This path can also be configured in the user or global "
settings.xml" file
by setting the value of the "
localRepository" element.
The
MAVEN_OPTS environment variable
allows you to set options (e.g., initial heap size:
-Xms, maximum heap size:
-Xmx)
used to start the JVM running Maven
and can be used to provide additional parameters.
See
http://docs.oracle.com/en/java/javase/23/docs/specs/man/java.html
Environment variables (Linux):
$ vi .bash_profile
export MAVEN_HOME="/opt/apache-maven"
export M2_REPO="$HOME/.m2/repository"
export MAVEN_OPTS="-Xms512m -Xmx1024m"
export PATH="${MAVEN_HOME}/bin:$PATH"
Note: Depending on your system, you may need to edit
.bashrc
or
.profile instead of
.bash_profile.
Run "
mvn -v" to verify that Maven is correctly installed:
$ mvn -v
Apache Maven 3.9.9
Maven home: /opt/apache-maven
Java version: 23.0.2, vendor: Oracle Corporation, runtime: /opt/jdk-23.0.2
...
Note:
To add an environment variable on Windows:
-
Right-click on "This PC".
-
Click on "Properties".
-
Click the "Advanced" tab.
-
Click the "Environment Variables" button.
-
Add the MAVEN_HOME environment variable
with the path where Maven is installed.
-
Select the "Path" system variable and click "Edit".
-
Add the path: ${MAVEN_HOME}/bin