Error: EACCES: permission denied
Solution 1
Creating package.json using npm init solved my issue.
Solution 2
This command fix the issue. It worked for me:
sudo npm install -g --unsafe-perm=true --allow-root
Solution 3
I have same issue with webpack server installation on globally, Use steps from this Url Solved my issue, my be work for you.
Steps mention above There: Back-up your computer before you start.
Make a directory for global installations:
1.
mkdir ~/.npm-global
Configure npm to use the new directory path:
2.
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
3.
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
4.
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
Solution 4
I had problem on Linux. I wrote
chown -R myUserName /home/myusername/myfolder
in my project folder.
WARNING: this is NOT the right way to fix it; DO NOT RUN IT, if you aren't sure of what could be the consequences.
Solution 5
Try to give all permission to your project folder with below command
sudo chmod -R 777 /yourProjectDirectoryName
run with
sudo npm install lodash
Related videos on Youtube
xruptronics
I am from Electronics and Communication background.I have been developing hardware and software solutions for different projects.Currently,I am working as Software Developer using technologies like NodeJs, Postgres, Django and developing and testing hardware products using hardware platforms like Raspberry Pi, Arduino, AVR Microcontrollers, etc.Visit my blog here Find me on: Github Linked In Twitter
Updated on January 26, 2022Comments
-
xruptronics about 2 years
I run npm install lodash but it throws Error: EACCES: permission denied error. I know it is permission issue but as far as I know, sudo permission is not required for installing node module locally. If I run it with sudo, it gets installed inside ~/node_modules folder. drwxrwxr-x is the file permission of existing folder. I can't figure out what might have gone wrong.
Below is the error message.
npm ERR! tar.unpack untar error /home/rupesh/.npm/lodash/4.13.1/package.tgz npm ERR! Linux 3.13.0-88-generic npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "lodash" npm ERR! node v4.3.1 npm ERR! npm v2.14.12 npm ERR! path /home/rupesh/node_modules/lodash npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall mkdir npm ERR! Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash' npm ERR! at Error (native) npm ERR! { [Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash'] npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/home/rupesh/node_modules/lodash', npm ERR! fstream_type: 'Directory', npm ERR! fstream_path: '/home/rupesh/node_modules/lodash', npm ERR! fstream_class: 'DirWriter', npm ERR! fstream_stack: npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25', npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53', npm ERR! 'FSReqWrap.oncomplete (fs.js:82:15)' ] } npm ERR! npm ERR! Please try running this command again as root/Administrator. npm ERR! Please include the following file with any support request: npm ERR! /home/rupesh/Desktop/es6/npm-debug.log
-
AJS almost 8 yearsis the owner of the folder
node_modules
root? -
xruptronics almost 8 yearsnode_module folder is not created yet inside folder in which i intend to install lodash.
-
AJS almost 8 yearsdid you run npm install in your /home/rupesh/ directory or some other directory?
-
xruptronics almost 8 yearspath of folder in which I run npm install is ~/Desktop/es6
-
AJS almost 8 yearswhats the output of
ls -l ~/Desktop | grep es6
make sure you are the owner of es6 directory -
xruptronics almost 8 yearsdrwxrwxrwx 3 rupesh rupesh 4096 Jul 12 14:48 es6
-
-
DrakaSAN almost 8 yearsDoesn't
chown
have a-r
option to prevent having to use it on each and every folder innode_modules
? -
xruptronics almost 8 years@Juanjo Salvador It didn't work.It throws same error.
-
xruptronics almost 8 yearsDoing chown -R rupesh:rupesh /home/rupesh/node_modules/ and running npm install lodash again installed lodash inside ~/node_module folder.But this time it does not throw error.But it is not where I intend to install.
-
AJS almost 8 yearsyes i know you should create the project in your home directory rather than Desktop. npm for some reason is installing your modules in
/home/rupesh/node_modules
for some reason. Any way working in your home directory should be ideal anyway -
xruptronics almost 8 yearsI think ~/Projects/es6 is equivalent to ~/Desktop/es6 structure wise.What I am having trouble figuring out is why node_modules is not created inside es6 folder and why lodash(or whatever) module is not installed inside that. I had not faced this issue earlier but what went wrong today,that is what i want to figure out.
-
Juanjo Salvador almost 8 years@DrakaSAN yeah, chown have a recursive option.
-
AJS almost 8 yearsyup i read my previous two comment and realized the stupidity :), well i looked around and couldn't find anyone else having the same problem. Is your code able to find
loadash
module?. -
xruptronics almost 8 yearsBut I am not sure why package.json file is required while installing node module as package.json file is not updated or used in my case because I have not used --save or --save-dev or similar command.
-
AJS almost 8 yearsthis is weird. i think some thing was messed up in your npm conf and doing init reset it, anyways it should be a mystery forever as i couldn't find a single reference to a similar problem elsewhere.
-
Wayne Smallman over 5 yearsFor anyone like myself, while this command appears to have worked at the time of writing, for Node
v10.10.0
I got the following error: "npm ERR! Can't install /var/www/project: Missing package name" -
Peter Edwards over 5 yearsThe flags --unsafe-perm=true --allow-root worked for us using node v10.15.0 to install as user root an existing application where node-sass would not install. Exact command we used to get node-sass installed to local directory node_modules folder was # npm install --save-dev --unsafe-perm=true --allow-root node-sass@latest
-
Josh about 5 yearsWorked!! On Mac moved my code folder to my root folder: HardDrive/ , and "npm install" ran flawlessly. Then I moved my code folder back to where I wanted it inside HardDrive/users/myUserName/Projects/code , ran "npm install" again, and this time, it worked.
-
Johnny almost 5 yearsworked on Mojave. Many thanks after 4-5hrs of troubleshooting, this did the trick!
-
Chris Marotta almost 5 yearsHad a similar issue with npm 6.9.0 and this worked for me too.
-
Chris Marotta almost 5 yearsYou can use root to solve the problem (though this is not recommended).
-
Patrick Da Silva almost 5 yearsVery unrecommended. That touches all your directories and removes root rights on any of them. If some things need to be set as root, this destroys your current configuration.
-
Mooncake over 4 yearsWhy would you allow the entire world to access this particular folder?
-
Pablo Papalardo about 4 yearsIt is a jr solution
-
Andrew almost 4 yearsYou may not even need 777. For me the problem was just the #'s were too low. (775 fixed it.)
-
Frank H over 3 yearsI was able to get it to work by using those flags so really the answer is :sudo npm install -g --unsafe-perm=true --allow-root <package-name>@<version-name>
-
MillerC over 3 years"Setting 777 permissions to a file or directory means that it will be readable, writable and executable by all users and may pose a huge security risk." -linuxize.com/post/what-does-chmod-777-mean
-
Simon Degn over 3 yearsI agree @PatrickDaSilva. This messed up my entire server..
-
Radoslaw over 3 years4. on Catalina
source ~/.zshrc
-
raphael75 over 3 yearsIt would be safer to use an absolute path, such as chown -R myusername /home/myusername/myfolder instead of ./*. If you run the command in the answer from the root folder it will screw everything up!
-
Shams Nahid about 3 yearsWorked on 20.04 also.
-
William about 3 yearsthis worked for me: sudo npm install --save -g solgraph --unsafe-perm=true --allow-root
-
csharpbd about 3 yearsThanks @Manohar Reddy Poreddy, after trying many solutions this worked for me.
-
ThaJay almost 3 yearsAnyway in my case it was the right solution. for some reason the Webpack output folder was owned by
root
so now it's owned by me again and it works. I agree you do not do this randomly, but if you look through your folders and are like WTH is this root? Then do this on that folder. -
JackHacks almost 3 yearsThis answer seems like a better practive
-
devaent almost 3 yearsthis works for me on Ubuntu 18.04. Thanks for the help
-
ekerner over 2 years@PatrickDaSilva there is no harm in changing the ownership of a users own files in their home dir to their user. In fact usually thats what you want: chown -R $USER ~/
-
Entropy over 2 yearsWorked on Mac M1 Big Sur. Thank you!
-
tripleee about 2 yearsWhatever you are hoping to accomplish,
chmod 777
is wrong and dangerous. You absolutely do not want to grant write access to executable or system files to all users under any circumstances. You will want to revert to sane permissions ASAP (for your use case, probablychmod 755
) and learn about the Unix permissions model before you try to use it again. If this happened on a system with Internet access, check whether an intruder could have exploited this to escalate their privileges. -
zzzgoo about 2 yearsthis will cause a git issue. All the files will be notified as modified.
-
Anurag Shukla about 2 yearsWorked like a charm!
-
Hack06 almost 2 yearsFor those who arrive here trying to install with 'yarn' instead of 'npm', just replace it respectively.