简体   繁体   English

设置全局安装后找不到Express命令

[英]Express command not found after setting installing globally

When I run sudo npm install -g express-generator : 当我运行sudo npm install -g express-generator

/Users/myname/npm/bin/express -> /Users/myname/npm/lib/node_modules/express-generator/bin/express-cli.js
/Users/myname/npm/lib
   └── express-generator@4.15.5

And when I run express : 当我运行express

express not found

Also, I thought it was interesting that when I run which npm : 另外,我认为有趣的是,当我运行which npm

/usr/local/bin/npm

That is the path. 那是路。

It seems that whenever I try to install something like yeoman or this express generator globally, it never works. 似乎每当我尝试在全球范围内安装诸如yeoman或此express generator的东西时,它就永远无法工作。

It should also be noted that I am on an Mac running zsh. 还应注意,我在运行zsh的Mac上。

Most likely your npm bin directory is not in the path. 您的npm bin目录很可能不在路径中。 Try to list the files in that directory by ls -l /usr/local/share/npm/bin/ . 尝试通过ls -l /usr/local/share/npm/bin/列出该目录中的文件。

If you find the express file, you can add that directory to the path by export PATH=/usr/local/share/npm/bin:$PATH . 如果找到快速文件,则可以通过export PATH=/usr/local/share/npm/bin:$PATH将该目录添加到export PATH=/usr/local/share/npm/bin:$PATH If not, most likely something went wrong with your installation and you can try installing the module again. 如果不是,很可能是您的安装出现问题,您可以尝试再次安装该模块。

Running this in the command line: 在命令行中运行此命令:

export PATH=/usr/local/bin/npm:$PATH

Fixed the issue...for now. 解决了该问题...目前。 I'm not totally sure why that worked. 我不太确定为什么行得通。

This affects Homebrew users using Node.js & npm 这会影响使用Node.jsnpm Homebrew用户

When you install Node.js using Homebrew it does not put npm on the PATH for you, however it suggests that you should do so. 当您安装Node.js使用Homebrew不会把npmPATH给你,但它表明,你应该这样做。

Homebrew doesn't modify the user's environment or dotfiles. Homebrew不会修改用户的环境或点文件。 However, brew install node does print a message suggesting the user add that path to their PATH. 但是,brew install节点会打印一条消息,建议用户将该路径添加到其PATH中。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM