You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacBook Air配置Apache Maven 3.6.3后执行mvn -version提示命令不存在

Fixing "zsh: command not found: mvn" on MacBook Air

Hey there, let's get your Maven setup working properly. The core issue here is that modern macOS uses zsh as the default shell, and it doesn't automatically load the .bash_profile file you configured—so your Maven environment variables aren't being applied when you open the terminal.

Here's what to do:

Step 1: Confirm your default shell

First, double-check that you're using zsh (which you likely are). Run this command:

echo $SHELL

You should see output like /bin/zsh—that confirms zsh is your default shell.

Step 2: Add Maven config to zsh's profile file

Zsh uses ~/.zshrc as its primary configuration file, not .bash_profile. Let's edit it:

  • Open the file in a text editor (I prefer using TextEdit for simplicity):
    open -e ~/.zshrc
    
  • Add these two lines to the end of the file (same as you put in .bash_profile):
    export M2_HOME=/Users/ak/Applications/apache-maven-3.6.3
    export PATH=$PATH:$M2_HOME/bin
    
  • Save the file and close TextEdit.

Step 3: Apply the changes immediately

Instead of closing and reopening your terminal, run this command to load the updated config right away:

source ~/.zshrc

Step 4: Verify Maven works

Now test if Maven is recognized:

mvn -version

You should see output showing your Maven version, Java version, and system info—success!

Alternative: Make zsh load your .bash_profile

If you want to keep using .bash_profile for shared config between bash and zsh, you can add this line to ~/.zshrc:

source ~/.bash_profile

Then run source ~/.zshrc to apply, and mvn -version should work too.

Quick sanity check

If you still run into issues, confirm the Maven path exists:

ls /Users/ak/Applications/apache-maven-3.6.3/bin

You should see the mvn executable listed here—if not, double-check that you moved the Maven folder to the correct location.

内容的提问来源于stack exchange,提问作者Kriss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 22:02:51