Node/Gatsby EACESS issues

Hello there!

I’ve been working in development for some time, and I think is my time to face Linux and overcome my fear to it.

I’ve been struggling to install Node; I’ve tried with Snap, wit Asdf, and now I did it with Pacman (sudo pacman -Syu nodejs npm); yes, I’ve tried all that because I was getting errors and tought that probably a clean install from other places could solve it, buuuut, it didn’t.

I’m currently trying to install Gatsby; whenever I run the command npm install -g gatsby-cli, I get the following error:

3165 error Error: EACCES: permission denied, access '/usr/lib/node_modules'
3165 error   errno: -13,
3165 error   code: 'EACCES',
3165 error   syscall: 'access',
3165 error   path: '/usr/lib/node_modules'
3165 error }

I’ve tried to solve it running the following:

sudo chown -R $USER /usr/local/lib/node_modules
sudo chown -R $(whoami) ~/.npm

But, it didn’t work (even if the owner of the folder was correctly changed).

Can anyone help me a little bit with this, please?

Thank you!

Hello and welcome!

Packages, even node modules, which are installed by pacman need root access for writing. Modifying the permissions in /usr/local/ is a really bad idea. :-1:

If you need to install it globally, then run sudo npm install -g gatsby-cli. That gives you by typing your user password root privileges for this command.

But better install it as user: npm install -u gatsby-cli

There is also another method to change the dir for npm when installing. Put his into your ~/.bashrc and even with -g option it will be installed in ~/.npm:



source ~/.bashrc

to activate it.

Keep sure you have that in your ~/.bash_profile:

if [ -r ~/.bashrc ]; then
   source ~/.bashrc
1 Like

Thanks for the welcome!

Ok, this is great, problem solved! I wasn’t able to do it on my own… and it’s good to know what you said about root access.

Probably this can be solved this way when installed with pacman, I don’t really know… fun thing here is that I read in one or two places that is better to change the permissions than using sudo :joy: I’ll believe in you.

Question here: why is it better to install it as user?

And thank you a lot for helping me with this!

1 Like
  1. It is a basic security concept of linux.
  2. When something is installed globally, than it is meant to installed as root or “admin”.
  3. If you need to modify the node modules, then it is easier to do this as user.
  4. node_modules is not a big case, but think of changing permissions sensible system data. It could break everything or is a nice way to present your system as a nice goal for some black hackers.

How ever, node modules needs just read access. For installation use sudo. In that way, you can’t damage you computer accidentally. Just a nice advice.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.