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

安装express-generator@4.15.5后执行express命令提示command not found求助

Fixing "express: command not found" After Installing express-generator on Mac OS X El Capitan

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:

  1. Confirm the missing path
    From your installation output, we can see the express command was installed to /Users/myname/.npm-global/bin/. First, check if this path is in your system’s PATH variable by running:

    echo $PATH
    

    If /Users/myname/.npm-global/bin/ isn’t listed in the output, that’s exactly why the command can’t be found.

  2. 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_profile file 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 ~/.zshrc instead and add the same line above.
  3. 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 ~/.zshrc
    
  4. Test the express command
    Now try running express newproject again—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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:44:36