简体   繁体   English

终端无法访问全球安装的npm包

[英]Globally installed npm package not accessible in terminal

I installed protractor through npm install -g protractor which run successfully. 我安装protractor通过npm install -g protractor其成功运行。

Running npm -g ls --depth=0 shows protractor installed correctly. 运行npm -g ls --depth=0表示正确安装了protractor

azim@azim-desktop:~$ npm -g ls --depth=0
/home/azim/npm-global/lib
├── express-generator@4.13.1
├── generator-angular@0.12.1
├── generator-chrome-extension@0.3.1
├── generator-gulp-angular@1.0.2
├── generator-gulp-angular-subtask@0.9.1
├── generator-karma@1.0.0
├── generator-mocha@0.1.8
├── generator-react-webpack@3.2.2
├── git-remote-mango@0.0.2
├── jshint@2.7.0
├── jsx@0.9.89
├── mango-admin@0.1.1
├── n@2.1.0
├── npm@3.7.2
├── protractor@4.0.0
└── yo@1.6.0

but protractor isn't accessible in terminal. 但终端无法访问量角器。

azim@azim-desktop:~$ protractor
protractor: command not found

It was working fine a while ago, I've updated my npm and node to latest versions. 它刚刚工作正常,我已经将我的npmnode更新到最新版本。 I think after that the PATH variables messed up. 我认为之后PATH变量搞砸了。 Googled for a solution but didn't work anything. 谷歌搜索解决方案,但没有任何工作。 I don't want to mess up the current situation. 我不想搞砸目前的情况。

Current path is: 目前的路径是:

azim@azim-desktop:~$ echo $NODE_PATH
/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/azim/npm-global/lib/node_modules

Versions: 版本:

azim@azim-desktop:~$ npm --version
2.14.12
azim@azim-desktop:~$ node --version
v4.3.1

The environment variable $NODE_PATH is used by node to look for modules only. 节点使用环境变量$NODE_PATH来仅查找模块。

Essentially you'll want to make sure that the directory path, where the protractor binary is located, is accessible through the environment variable $PATH instead. 基本上,您需要确保可以通过环境变量$PATH访问protractor二进制文件所在的目录路径。


Example of where my protractor is installed: 我的量角器的安装位置示例:

root@codeblog:~# which protractor root @ codeblog:〜#哪个量角器
/usr/bin/protractor 在/ usr / bin中/量角器

root@codeblog:~# env | root @ codeblog:〜#env | grep PATH grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin: /usr/bin :/sbin:/bin:/usr/games:/usr/local/games PATH = / usr / local / sbin:/ usr / local / bin:/ usr / sbin: / usr / bin :/ sbin:/ bin:/ usr / games:/ usr / local / games
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript NODE_PATH = / usr / lib中/的NodeJS:/ usr / lib中/ node_modules:在/ usr /共享/ JavaScript的

If you got protractor installed at another place then you might want to tweak your ~/.bashrc to append that directory into the $PATH variable. 如果您在另一个地方安装了protractor ,那么您可能需要调整~/.bashrc以将该目录附加到$PATH变量中。

Like: 喜欢:

PATH=$PATH:/usr/my_protractor_dir/bin

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

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