# NPM Default package manger for Node.js # About NPM > npm is a [package manager](https://en.wikipedia.org/wiki/Package_manager "Package manager") for the [JavaScript](https://en.wikipedia.org/wiki/JavaScript "JavaScript") programming language maintained by [npm, Inc](https://en.wikipedia.org/wiki/Npm,_Inc. "Npm, Inc."). > > \-- [Wikipedia](https://en.wikipedia.org/wiki/Npm_(software)) # Avoid Global Installation of Packages ## Quick Instructions Inside a `npm` managed directory add the local installation directory to the path: ```shell PATH=`pwd`/node_modules/.bin:$PATH ``` Strip the first path from PATH: ```shell PATH=${PATH#*:} ``` ## Shell Functions `nact` saves PATH, then prepends it with the local installation directory, if inside an `npm` managed directory. It prevents multiple invocations. `ndeact` restores the PATH previously saved by `nact`. ```shell nact () { if [ -n "$NPM_MODULES_PATH" ]; then echo already activated: $NPM_MODULES_PATH return fi if [ ! -d ./node_modules/.bin ]; then echo not in a npm package directory return fi export NPM_MODULES_PATH NPM_MODULES_PATH=`pwd`/node_modules/.bin export NPM_ACTIVATE_PATH NPM_ACTIVATE_PATH=$PATH PATH="$NPM_MODULES_PATH:$PATH" export NPM_ACTIVATE_PS1 NPM_ACTIVATE_PS1=$PS1 PS1="(npm)$PS1" } ndeact () { if [ -z "$NPM_MODULES_PATH" ]; then echo nothing to deactivate return fi unset NPM_MODULES_PATH PATH=$NPM_ACTIVATE_PATH unset NPM_ACTIVATE_PATH PS1=$NPM_ACTIVATE_PS1 unset NPM_ACTIVATE_PS1 } ``` ## Rationale It is common to install commandline utilities like [Gulp](https://en.wikipedia.org/wiki/Gulp.js) or [Vue CLI](https://cli.vuejs.org/) with -g (global) commandline switch, so they are available via the standard search PATH. Global installation has several drawbacks, e.g.: - Versioning: different projects with different Node.js versions might require different versions of the tool - Privilege elevation is often required to install software globally ## Alternatives Other, probably more sofisticated techniques exist to acchive the same or similar functionality, see: [https://npm.github.io/installation-setup-docs/installing/using-a-node-version-manager.html](https://npm.github.io/installation-setup-docs/installing/using-a-node-version-manager.html) # References - Homepage: - Wikipedia: