You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Mac下NPM从GitHub安装包后执行提示command not found问题求助

Hey there, let's work through this command-not-found issue together—it’s a pretty common snag when installing npm packages from GitHub, so we’ll get this sorted out for you.

First: Check if you installed the package globally or locally
  • If you ran npm install moneda (without the -g flag), the package is installed locally in your project’s node_modules/.bin directory. This directory isn’t in your $PATH by default, so typing moneda directly won’t work. You have two quick fixes here:

    1. Use npx to run the local package: npx moneda (npx automatically looks for executables in your project’s node_modules/.bin)
    2. Call the executable directly via its local path: ./node_modules/.bin/moneda
  • If you used npm install -g moneda (with the global -g flag), the problem almost always boils down to npm’s global bin directory not being included in your $PATH.

Find npm’s global bin directory

First, run this command to get npm’s global prefix path:

npm get prefix

This will output something like /usr/local or /Users/your-username/.npm-global. The corresponding bin directory you need is [prefix]/bin (e.g., /usr/local/bin or /Users/your-username/.npm-global/bin).

Next, check if this bin path is already in your $PATH:

echo $PATH | grep -q "$(npm get prefix)/bin" && echo "Path is in your PATH" || echo "Path is NOT in your PATH"
Add the npm bin path to your PATH if missing

Depending on which shell you’re using (bash or zsh), edit the corresponding configuration file:

  • For bash: Open ~/.bash_profile or ~/.bashrc in a text editor, then add this line:
    export PATH="$(npm get prefix)/bin:$PATH"
    
  • For zsh: Open ~/.zshrc and add the same line.

After saving the file, refresh your shell configuration to apply the change:

# For bash users
source ~/.bash_profile
# Or if you use .bashrc instead
source ~/.bashrc

# For zsh users
source ~/.zshrc

Now try running your package command again—it should work!

Bonus: Fix permission issues (if applicable)

If you ever saw permission errors when installing global packages, it might be because your npm global directory has incorrect ownership. Fix that with:

sudo chown -R $(whoami) $(npm get prefix)/{lib/node_modules,bin,share}

Then re-install your global package to ensure it’s placed correctly.

Final verification

Run echo $PATH again to confirm the npm bin directory is listed, then run which moneda—if it outputs the full path to the executable, you’re all set!

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

火山引擎 最新活动