npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
Solution 1
An inadvisable way to fix the issue would be to use sudo:
sudo npm install -g monaca
However it would be better to find a way around this without using sudo.
npm install -g less does not work
Solution 2
add following lines to ~/.bashrc after installing npm:
npm set prefix ~/.npm
PATH="$HOME/.npm/bin:$PATH"
PATH="./node_modules/.bin:$PATH"
Execute following line after changes:
source ~/.bashrc
and as mentioned by @contemplator avoid using sudo
Solution 3
Note: It is highly recommended to avoid using sudo
with npm!
Using sudo is not recommended. It may give you permission issue later. While the above works, use these instructions to fix your issue permanently.
Solution 4
To all the warnings telling not to use sudo
above, I'd add the following solution that worked pretty well for me while installing n, node version manager
sudo chown -R $USER /usr/local/lib/node_modules
This was taken from here: https://poopcode.com/missing-write-access-to-usr-local-lib-node-modules/
PS: for my specific use-case I also needed to run this one afterwards
sudo chown -R $USER /usr/local/bin/
Solution 5
This command will change the owner (chown) recursively (-R) for the current user in the specified directory
sudo chown -R $USER /usr/local/lib/node_modules
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
Note: Due to security concerns, please don't use the marked solution but instead the highest voted one!
original question:
I am trying to install monaca with this command.
npm install -g monaca
But right after getting these errors:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules npm ERR! path /usr/local/lib/node_modules npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules' npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules' npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'', npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/usr/local/lib/node_modules' }
Any idea how to solve this problem? Thank you