4

The node.js package manager, npm, has an option to install packages globally. Since distributions typically have their own package manager, is it safe to use the global option? Could npm packages conflict with distribution packages and cause errors down the road that are hard to trace back?

drs
  • 5,363
  • 9
  • 40
  • 69
  • To be picky, that's the *node.js* package manager. Have a look here: https://www.npmjs.org/doc/files/npm-folders.html for the relevance of global vs. local. I would guess if `npm` is from a distro package, its prefix will be `/usr` whereas if you built from source it's `/usr/local/` -- if you have both, that's then two separate places for modules installed *globally* to end up. Calling `node` on the command line will most likely default to the `/usr/local` one, and it will not have access to any modules installed globally by the distro one... – goldilocks Oct 30 '14 at 14:57
  • ...That doesn't deal with the issue of using `npm` globally vs. installing node packages from the distro. I would guess for the distro version of `npm` they would conflict, or rather, install overtop. Probably using `npm` gets you the more recent version. – goldilocks Oct 30 '14 at 14:59
  • @goldilocks I only have `npm` installed from my distribution's package manager so we don't have to worry about there being two `npm` binaries behaving differently. – drs Oct 30 '14 at 15:25

1 Answers1

6

It depends on how npm was configured when it was installed.

If npm was installed on Debian from the package that is included in the distribution, then, yes, it is safe. npm with the global option installs to /usr/local, which is explicitly set aside for local software installation and should not conflict with the operating system distribution's own installations.

npm -g installs to /usr/local (/usr/local/lib/node_modules, /usr/local/bin, etc...) even if npm itself is located in /usr/bin as it would be if it were itself installed from, say, a Debian package that's part of the OS distribution.

Most likely there are other operating system distributions to which the above applies.

On Fedora on the other hand, npm installs packages to /usr/lib/node_modules (not in /usr/local). I don't know whether or not this is safe. It depends if any Fedora-packaged nodejs modules also go to /usr/lib/node_modules or whether they go somewhere else. If they go somewhere else, then it would be safe.

drs
  • 5,363
  • 9
  • 40
  • 69
Celada
  • 43,173
  • 5
  • 96
  • 105
  • Hmm.. This doesn't seem to be the case for my system (Fedora 19). `which npm` gives `/usr/bin/npm`, but checking in `/usr/local`, I don't see any directories corresponding to `npm` modules I've installed. – drs Oct 30 '14 at 15:28
  • My answer is based on my experience with Debian jessie (the earliest Debian distribution which contains `npm`). I'm surprised to hear it's different on Fedora. Are you able to find where your packages that were installed using `npm -g` did go? – Celada Oct 30 '14 at 15:34
  • 1
    @Caleda It looks like the ones I've installed are under `/usr/lib/node_modules/` – drs Oct 30 '14 at 15:38
  • I see. Looks like I have to edit my answer. – Celada Oct 30 '14 at 15:41