search
HomeJavajavaTutorialQuickly install Maven on Mac system, step-by-step guide

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to elegantly obtain entity class variable names to build database query conditions?How to elegantly obtain entity class variable names to build database query conditions?Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How to use the Redis cache solution to efficiently realize the requirements of product ranking list?How to use the Redis cache solution to efficiently realize the requirements of product ranking list?Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

How to safely convert Java objects to arrays?How to safely convert Java objects to arrays?Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

How do I convert names to numbers to implement sorting and maintain consistency in groups?How do I convert names to numbers to implement sorting and maintain consistency in groups?Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the default run configuration list of SpringBoot projects in Idea for team members to share?How to set the default run configuration list of SpringBoot projects in Idea for team members to share?Apr 19, 2025 pm 11:24 PM

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor