1. Download from maven official website : http://maven.apache.org/download.cgi
2. Decompression (Mac)
zip package decompression unzip apache-maven-3.8.6-src.zip
tar package decompressiontar -xvf apache-maven-3.8.6-src.tar.gz
3. Configure environment variables
Open terminal
vim ~/.bash_profile Open the .bash_profile file and add commands to set environment variables in the file
The environment variable command is as follows:
export M2_HOME=/Users/xxx/Documents/maven/apache-maven-3.5.0
export PATH=$PATH:$M2_HOME/bin
Execute after adding: wq save and exit
orvim ~/.zshrc 打开.zshrc文件,在文件中添加设置环境变量的命令
export M2_HOME=/Users/xxx/Documents/maven/apache-maven-3.5.0
export PATH=$PATH:$M2_HOME/bin
Execute after adding: wq save and exit
4. Test
terminal input: mvn -v
if the following information appears, the installation is successful
Maven home: /opt/apache-maven-3.8.4
Java version: 1.8.0_312, vendor: Azul Systems, Inc., runtime: /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "aarch64", family: "mac"
Add a small knowledge point
. The above source ~/.bash_profile command will take effect after the current window is executed, mvn -v
but it will not take effect when opened in a new terminal mvn -v
. Promptzsh: command not found: mvn
what? black face. . . .
In mac, the source command must be executed every time to make the environment variable take effect, has it been executed once, does it take effect globally? The answer is yes (Baidu)
can be configured as follows: Add source ~/.bash_profile to ./zshrc
vi ~./zshrc
Add wq to the last line source ~/.bash_profile
to save and source ~/.zshrc
make it take effect
mvn -v
At this time , it will take effect directly when opened in a new window