Asim K T Asim K T - 4 months ago 20
Node.js Question

Globally installed npm package not accessible in terminal

I installed

protractor
through
npm install -g protractor
which run successfully.

Running
npm -g ls --depth=0
shows
protractor
installed correctly.

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. I think after that the
PATH
variables messed up. 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

Answer

The environment variable $NODE_PATH is used by node to look for modules only.

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.


Example of where my protractor is installed:

root@codeblog:~# which protractor
/usr/bin/protractor

root@codeblog:~# env | grep PATH
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

If you got protractor installed at another place then you might want to tweak your ~/.bashrc to append that directory into the $PATH variable.

Like:

PATH=$PATH:/usr/my_protractor_dir/bin
Comments