简体   繁体   English

Node.js 错误:全局模块:'找不到命令'

[英]Node.js error: global module: ' command not found '

Solution:解决方案:

  1. Permissions error - fixed with confidence from comment by Kadir权限错误 - 从Kadir 的评论中自信地修复
  2. Bower Sourcing of bin - fixed with with clarity from Josiah's comment Bower Sourcing of bin - 从Josiah 的评论中明确修复
  3. sudo chown -R $(whoami):admin /usr/local须藤 chown -R $(whoami):admin /usr/local

.bower-profile .bower-profile

if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac

.profile 。轮廓

PATH=~/npm-global/bin:$PATH

Original Error Trail原始错误轨迹

Mac OS X El Captain | Mac OS X El 船长 | Node v5.0 |节点 v5.0 | NPM 3.4.0新产品管理 3.4.0

npm works, global commands like git work. npm 工作,像 git 这样的全局命令工作。

bower -g in projects does not work.项目中的bower -g不起作用。

Aarons-MacBook-Air:test2 Akorn$ ionic start todo blank
-bash: ionic: command not found
Aarons-MacBook-Air:test2 Akorn$ ionic --version
-bash: ionic: command not found
Aarons-MacBook-Air:test2 Akorn$ npm ionic -l -v
3.4.0

Permission Error权限错误

Aarons-MacBook-Air:test2 Akorn$ brew update && brew upgrade node
Error: The /usr/local directory is not writable.
Even if this directory was writable when you installed Homebrew, other
software may change permissions on this directory. Some versions of the
"InstantOn" component of Airfoil are known to do this.

You should probably change the ownership and permissions of /usr/local
back to your user account.
  sudo chown -R $(whoami):admin /usr/local
Aarons-MacBook-Air:test2 Akorn$ brew --version
Homebrew 0.9.5 (git revision fb84; last commit 2015-12-22)

Questions Can I trust sudo fixes?问题我可以信任 sudo 修复吗?

Is there a better fix?有没有更好的解决办法?

Are there methods for further diagnostics?有没有进一步诊断的方法?

How did I break this?我是怎么破解这个的?

  1. Incorrectly updating npm or node - so however npm calls global functions from wrong folder.错误地更新 npm 或节点 - 但是 npm 从错误的文件夹调用全局函数。

  2. Incorrectly using brew.错误地使用 brew。

  3. Ugly code in .profile / .profile_bash . .profile / .profile_bash丑陋代码。

    ~/.bash_profile : ~/.bash_profile :

     source ~/.profile

    ~/.profile : ~/.profile :

     export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

Generally when you see -bash: mycommand: command not found it means that the command you're trying to use isn't located where bash is looking for it.通常,当您看到-bash: mycommand: command not found这意味着您尝试使用的命令不在 bash 正在查找的位置。 Bash usually looks in the present working directory and in any location that's listed in the $PATH environment variable. Bash 通常在当前工作目录和$PATH环境变量中列出的任何位置中查找。

You can see what the current value of $PATH is by running echo $PATH .您可以通过运行echo $PATH来查看$PATH的当前值。 Judging based on the ~/.profile contents you posted, the location you have ionic installed in is not part of your path.根据您发布的~/.profile内容判断,您安装ionic的位置不是您路径的一部分。 You'll have to verify where that file is installed;您必须验证该文件的安装位置; maybe /Users/Akorn/npm-global/lib or maybe there was a shortcut installed in /usr/local/bin or /usr/bin , so you'll want to check those too and make sure that those are added to your $PATH .也许/Users/Akorn/npm-global/lib或者在/usr/local/bin/usr/bin安装了快捷方式,因此您也需要检查它们并确保将它们添加到您的$PATH As an example, my $PATH looks like this;例如,我的$PATH看起来像这样; /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Josiah/docker/bin

To learn how to add a new location to your $PATH , read up on the first answer to this question .要了解如何向$PATH添加新位置,请阅读此问题的第一个答案

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

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