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.
If you ran
npm install moneda(without the-gflag), the package is installed locally in your project’snode_modules/.bindirectory. This directory isn’t in your$PATHby default, so typingmonedadirectly won’t work. You have two quick fixes here:- Use
npxto run the local package:npx moneda(npx automatically looks for executables in your project’snode_modules/.bin) - Call the executable directly via its local path:
./node_modules/.bin/moneda
- Use
If you used
npm install -g moneda(with the global-gflag), the problem almost always boils down to npm’s global bin directory not being included in your$PATH.
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"
Depending on which shell you’re using (bash or zsh), edit the corresponding configuration file:
- For bash: Open
~/.bash_profileor~/.bashrcin a text editor, then add this line:export PATH="$(npm get prefix)/bin:$PATH" - For zsh: Open
~/.zshrcand 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!
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.
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




