Home >Java >javaTutorial >Quickly install Maven on Mac system, step-by-step guide
How to install Maven on Mac, quickly master the steps, you need specific code examples
With the rapid development of software development, Maven has become one of the important tools for Java project management one. This article will introduce in detail how to install Maven on Mac, and provide specific steps and code examples to help readers quickly master the Maven installation process.
Step 1: Download Maven
First, open the browser, enter the Maven official website (https://maven.apache.org), and click the "Download" link to enter the download page. On the download page, find the latest version of Maven and click the corresponding link to download.
Step 2: Decompress the Maven compressed package
After the download is completed, find the downloaded Maven compressed package file. You can save it in any folder for subsequent operations. Then, open the Terminal application and go to the folder where the Maven archive is saved.
Use the following command to decompress the Maven compressed package:
tar -zxvf apache-maven-3.8.1-bin.tar.gz
This command will decompress the Maven compressed package and create a folder named "apache-maven-3.8.1" in the current directory .
Step 3: Configure environment variables
In order to be able to use Maven commands at any location, you need to add Maven's bin directory to the system's environment variables. Enter the following command in the terminal to edit the ~/.bash_profile
file:
vi ~/.bash_profile
Press i
to enter edit mode, then add the following at the end of the file:
export M2_HOME=/path/to/maven/apache-maven-3.8.1 export MAVEN_HOME=$M2_HOME export PATH=$PATH:$MAVEN_HOME/bin
Replace /path/to/maven/
here with the actual path after Maven decompression, which is the /apache-maven-3.8.1
created above. The path to the folder. When editing is complete, press the Esc
key and then enter :wq
to save and exit the file.
Restart the terminal or enter the following command to make the configuration file take effect immediately:
source ~/.bash_profile
Step 4: Verify the installation
Enter the following command in the terminal to check whether the Maven installation is successful :
mvn -v
If the Maven version number and other related information are displayed, it means that Maven has been installed successfully and has been configured.
At this point, the steps to install Maven are completed. Below we will use a simple example to verify the use of Maven.
Step 5: Use Maven to create the project
Enter the folder where the project is stored in the terminal, and then execute the following command to create the Maven project:
mvn archetype:generate -DgroupId=com.example -DartifactId=my-first-maven-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This command will use Maven's Default templates quickly create a project. After the creation is completed, enter the project folder you just created:
cd my-first-maven-project
Step 6: Build the project
Execute the following command in the terminal to build the project:
mvn package
This command will Compile and package the project to generate a JAR file. After the build is completed, the generated JAR file can be found in the target
directory of the project folder.
With this simple example, we learned how to use Maven to create and build a project.
This article details how to install Maven on Mac and provides specific steps and code examples. By following the above steps, readers can quickly master the installation process of Maven and give full play to the powerful functions of Maven in development. Hope this article is helpful to readers.
The above is the detailed content of Quickly install Maven on Mac system, step-by-step guide. For more information, please follow other related articles on the PHP Chinese website!