全局安装Lerna后执行命令提示“bash: lerna: command not found”求助
Hey there, let's troubleshoot why your globally installed Lerna isn't showing up in Git Bash. The issue is almost certainly related to your system's PATH environment variable not including npm's global bin directory, or a minor quirk with your older Node/npm setup. Here's how to fix it step by step:
1. Verify the npm Global Path is in Git Bash's PATH
First, let's check if Git Bash knows where to find the Lerna executable:
- Run this command in Git Bash:
echo $PATH - Look for a path that matches
/c/Users/<user-name>/AppData/Roaming/npm(note the forward slashes instead of backslashes for Git Bash).
If you don't see this path, add it temporarily first to test:
export PATH="$PATH:/c/Users/<user-name>/AppData/Roaming/npm"
Now try running lerna init again. If it works, make this change permanent by adding the same export line to your ~/.bashrc or ~/.bash_profile file (create the file if it doesn't exist).
2. Test with the Full Executable Path
To confirm it's a PATH issue, run Lerna directly using its full path in Git Bash:
/c/Users/<user-name>/AppData/Roaming/npm/lerna init
If this command works, you can be sure the problem is that Git Bash isn't looking in the right directory for global npm commands.
3. Check Your npm Prefix Configuration
Sometimes npm's global install path gets misconfigured. Verify it's set correctly:
npm config get prefix
The output should be C:\Users\<user-name>\AppData\Roaming\npm (Windows-style path here, since we're using npm's command). If it's different, set it back with:
npm config set prefix "C:\Users\<user-name>\AppData\Roaming\npm"
Then reinstall Lerna globally to ensure the links are created correctly:
npm install --global lerna
4. Consider Updating Node/npm (Optional but Recommended)
Your Node.js v8.10.0 and npm 3.10.9 are quite outdated. While Lerna 2.11.0 should work with them, newer versions of npm handle global path management more reliably. If you can, update npm to the latest version compatible with Node 8:
npm install --global npm@6
(Node 8.x is compatible with npm up to version 6.x)
内容的提问来源于stack exchange,提问作者Vaibhav Agrawal

