3

I am trying to avoid installing common Node packages redundantly for each user. I would like to install certain common Node packages globally. However, on Arch Linux, I encounter permissions issues.

npm install [package] -g 

fails with message:

Missing write access to /usr/lib/node_modules

This succeeds:

sudo npm install [package] -g 

However, then we get errors like this when a regular user tries to use the package:

Error: EACCES: permission denied, open '/usr/lib/node_modules/[package]/lib/[file].js'

What is the right way to do this, assuming we are required to install some packages globally. EDIT: see the reason for the requirements here.

2
  • My recommendation: Don't. I tried, and it breaks horribly over time when dependency hell rears its ugly head. After that experience, I always install packages per repository. Even if it means wasting disk space, and having to cleanup node_modules from time to time. Commented Dec 25, 2019 at 9:46
  • I now realize I did not ask the question I needed to ask. Therefore, I created a new (hopefully better) question here: stackoverflow.com/questions/59481432/… Commented Dec 25, 2019 at 19:55

1 Answer 1

1

In general all packages should be installed locally. This ensures you can have multiple applications running on different versions (like needed) of the same package. A global package-update might unleash hell in terms of broken dependencies and compatibility.

Do a global install when a package provides an executable command you want to run from the shell.

BUT if there is an already globally installed package you want to use in development: use npm link <global-package>. This will create a local link to that package (working only with npm >= 1.0 and with an OS supporting symlinks).

For further information read:

  1. npm-1-0-global-vs-local-installation
  2. npm-1-0-link
1
  • Good answer, but it doesn't answer my intended question. I now realize I did not ask the question well. Therefore, I created a new (hopefully better) question here: stackoverflow.com/questions/59481432/… Commented Dec 25, 2019 at 19:54

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.