Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locally installed versus globally installed NPM modules

In my package.json file, I have bower listed as a dependency. After I run npm install, bower gets installed locally. When I try to run bower after installing it locally I get an error

"bower" is not recognized as an internal or external command

It seems the only way to resolve this is to install bower globally. Why should I have to do this? If my project contains a local copy of bower, why won't node use it?

like image 329
Rigil Avatar asked Dec 09 '14 22:12

Rigil


People also ask

What is the difference between a globally installed module and a locally installed module?

globally —- This drops modules in {prefix}/lib/node_modules , and puts executable files in {prefix}/bin , where {prefix} is usually something like /usr/local . It also installs man pages in {prefix}/share/man , if they're supplied. locally —- This installs your package in the current working directory.

What does it mean to install npm package globally?

Installing a package globally allows you to use the code in the package as a set of tools on your local computer. To download and install packages globally, on the command line, run the following command: npm install -g <package_name>

What is the difference between global installation and local installation of dependencies?

Installing the local dependencies means the module will be available only for a project you installed in the same directory. Global installing dependencies puts the module into your Node.

Are NPM packages installed globally?

npm packages can be installed globally using the -g or --global flag so that the package can be used from the console.


1 Answers

Installing locally makes bower available to the current project (where it stores all of the node modules in node_modules). This is usually only good for using a module like so var module = require('module'); It will not be available as a command that the shell can resolve until you install it globally npm install -g module where npm will install it in a place where your path variable will resolve this command.

Edit: This documentation explains it pretty thorougly.

like image 87
Jimi Avatar answered Sep 22 '22 08:09

Jimi