安装express-generator@4.15.5后执行express命令提示command not found求助
Hey there! I see you’ve successfully installed express-generator globally, but the express command is still throwing a "not found" error—let’s fix that. This issue almost always happens because your system doesn’t know where to look for the globally installed npm commands.
Let’s walk through the solution step by step:
Confirm the missing path
From your installation output, we can see theexpresscommand was installed to/Users/myname/.npm-global/bin/. First, check if this path is in your system’sPATHvariable by running:echo $PATHIf
/Users/myname/.npm-global/bin/isn’t listed in the output, that’s exactly why the command can’t be found.Add the path to your shell config
Depending on which shell you’re using (Bash or Zsh are common on El Capitan):- For Bash: Open your
~/.bash_profilefile in a text editor (like nano or TextEdit) and add this line at the end:export PATH="/Users/myname/.npm-global/bin:$PATH" - For Zsh: Edit
~/.zshrcinstead and add the same line above.
- For Bash: Open your
Apply the changes right away
Run the corresponding command to make the PATH update take effect without restarting your terminal:# For Bash users source ~/.bash_profile # For Zsh users source ~/.zshrcTest the
expresscommand
Now try runningexpress newprojectagain—it should work as expected!
If the above doesn’t work (just in case):
If you’re unsure about the exact npm global path, run this command to get it:
npm config get prefix
Take the output (it should be /Users/myname/.npm-global for your case), append /bin to it, and add that full path to your PATH variable using the same steps above.
Original problem:
这是我首次在此发帖求助,此前已查阅大量资料解决了诸多问题。我使用MacBook OS X El Captain系统,已安装Node v8.9.4。执行命令sudo npm install -g express-generator后得到反馈:myname-MacBook-Air:todo myname$ sudo npm install -g express-generator /Users/myname/.npm-global/bin/express -> /Users/myname/.npm-global/lib/node_modules/express-generator/bin/express-cli.js + express-generator@4.15.5 updated 1 package in 1.052s但尝试执行
express newproject命令时,却提示express: command not found。
内容的提问来源于stack exchange,提问作者Christoffer Endresen

