Instructions on how to install Apache Maven on macOS.
First step should be to unsinstall any previous Apache Maven installation. This step can be skipped if no Apache Maven version was previously installed.
This will completelly remove any Apache Maven version previously installed. If you which to keep the user packages installed with
mvnyou should skip the last set of commands.
To uninstall any previous Apache Maven installations use the following command:
sudo rm -rf /usr/local/apache-maven(these are your maven settings and installed java packages, don't delete this if you plan on re-installing Apache Maven)
rm -rf ~/{.m2,.mavenrc}Apache Maven can be obtained here. Copy the link for the version that you want to install from there.
Get the Apache Maven binary archive and extract it with the following commands:
sudo mkdir -p /usr/local/apache-maven
curl --silent --location --retry 3 "https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz" | sudo tar xz --no-same-owner --strip-components=1 -C /usr/local/apache-maven/Add the following line to the .bash_profile file:
export MAVEN_HOME='/usr/local/apache-maven'
export PATH="${MAVEN_HOME}/bin:${PATH}"
Open a new terminal window and check if maven is installed:
mvn -vAlso check if the MAVEN_HOME environment variable was defined using the following command:
echo $MAVEN_HOME