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

Mac环境下AWS Amplify CLI安装后无法运行及npm全局包路径异常求助

Fixing "bash: amplify: command not found" on Mac with AWS Amplify CLI

Hey there, let's work through this issue step by step. The root cause here is definitely wonky npm global package configuration—your npm is installing global packages into a nested node_modules directory that's not in your system's PATH, which is why the amplify command isn't being found.

Let's break down the fixes:

  1. Check your current npm prefix setting
    First, confirm what's causing the nested directory issue by running:

    npm config get prefix
    

    This will likely return something like /usr/local/lib/node_modules/node—that's the problem. npm uses this prefix to determine where to install global packages and their executable links.

  2. Reset the npm prefix to the Mac default
    We need to set the prefix back to the standard global npm directory for Mac:

    npm config set prefix /usr/local
    

    This tells npm to install global packages into /usr/local/lib/node_modules and place executable commands (like amplify) into /usr/local/bin—which should already be in your system PATH.

  3. Verify your PATH includes /usr/local/bin
    Double-check that your system can find the executable commands by running:

    echo $PATH
    

    If you don't see /usr/local/bin listed, you'll need to add it to your shell configuration file:

    • For Bash: Open ~/.bash_profile in a text editor and add this line:
      export PATH="/usr/local/bin:$PATH"
      
      Then apply the change with:
      source ~/.bash_profile
      
    • For Zsh (default on newer Macs): Open ~/.zshrc and add the same export PATH line, then run:
      source ~/.zshrc
      
  4. Reinstall AWS Amplify CLI (cleanly)
    To make sure the CLI gets installed to the correct location, first uninstall the existing version:

    npm uninstall -g @aws-amplify/cli
    

    Then reinstall it:

    npm install -g @aws-amplify/cli
    
  5. Validate the fix
    Run these commands to confirm everything is working:

    • amplify --version should display the installed CLI version without errors
    • npm -g root should now return /usr/local/lib/node_modules (no more nested directories!)

Why this happened:

This usually occurs if there was a misstep during Node.js installation, or if someone manually modified the npm prefix setting in the past. By resetting the prefix to the default, we get npm back to installing global packages in a location that your system can easily find.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 04:48:38