npm does not add alias automatically when installi

2019-09-09 01:31发布

问题:

When I try to run a command to call a package already installed using npm.

e.g: cordova

cordova -v

It does not work, it works only when I run the full path:

/Users/James/.npm-packages/bin/cordova -v

For that I need to create an alias for each package in order to avoid calling using the full paths, which causes many issues in many levels.

My npm version is:

3.7.3

My O.S

Mac OSx El Capitan

回答1:

Add /Users/James/.npm-packages/bin/ to your $PATH:

export PATH="$PATH:$HOME/.npm-packages/bin/"

Add the above to your ~/.bash_profile and source it:

source ~/.bash_profile

AFAIK OSX runs bash as a login shell when a terminal is opened, so .bash_profile should be used in favor of .bashrc.

For more info see: What is PATH?



标签: linux bash npm