Typically when installing a new npm packages globally in your system, you will encounter an error something like
Error: EACCESS permission denied something.
Don't worry, it's natural I'm here to help you to fix this kind of error.
Normally I'm using node version manager (nvm) to handle my node versions, so I can easily switch to any version I prefer but we will not discuss it here. I'll create a separate blog post for that on how to set up a multiple node version using NVM (node version manager).
So let's take a look the error that most probably something like this below:
- Open up your favorite terminal and run this code
So what does it do?
chown is a unix command which means "change owner". From that definition based on our code above we are going to change the owner of our folder
~/.npm which for sure the "root" user is applied.
We're going to assign this folder recursively to our own username using this command
whoami so that it will be easy to read and write anything we want.
NOTE: Somehow, even when we change the owner of
~/.npm folder, we still encounter an EACCES error. To Fix that, we should change the owner of our node_modules folder.
Now you can finally install npm packages without sudo.
Explore our new Tips and Tricks tutorial. Explore our Tips and Tricks
I hope you enjoy our tutorial, Let me know incase you encounter any error I would love to answer that. Don't forget to subscribe to my Youtube Channel at Let's Code Pare - Youtube Channel