Error: EACCES: permission denied

417,210

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
Share:
417,210

Related videos on Youtube

xruptronics
Author by

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, 2022

Comments

  • xruptronics
    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
      AJS almost 8 years
      is the owner of the folder node_modules root?
    • xruptronics
      xruptronics almost 8 years
      node_module folder is not created yet inside folder in which i intend to install lodash.
    • AJS
      AJS almost 8 years
      did you run npm install in your /home/rupesh/ directory or some other directory?
    • xruptronics
      xruptronics almost 8 years
      path of folder in which I run npm install is ~/Desktop/es6
    • AJS
      AJS almost 8 years
      whats the output of ls -l ~/Desktop | grep es6 make sure you are the owner of es6 directory
    • xruptronics
      xruptronics almost 8 years
      drwxrwxrwx 3 rupesh rupesh 4096 Jul 12 14:48 es6
  • DrakaSAN
    DrakaSAN almost 8 years
    Doesn't chown have a -r option to prevent having to use it on each and every folder in node_modules?
  • xruptronics
    xruptronics almost 8 years
    @Juanjo Salvador It didn't work.It throws same error.
  • xruptronics
    xruptronics almost 8 years
    Doing 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
    AJS almost 8 years
    yes 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
    xruptronics almost 8 years
    I 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
    Juanjo Salvador almost 8 years
    @DrakaSAN yeah, chown have a recursive option.
  • AJS
    AJS almost 8 years
    yup 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
    xruptronics almost 8 years
    But 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
    AJS almost 8 years
    this 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
    Wayne Smallman over 5 years
    For 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
    Peter Edwards over 5 years
    The 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
    Josh about 5 years
    Worked!! 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
    Johnny almost 5 years
    worked on Mojave. Many thanks after 4-5hrs of troubleshooting, this did the trick!
  • Chris Marotta
    Chris Marotta almost 5 years
    Had a similar issue with npm 6.9.0 and this worked for me too.
  • Chris Marotta
    Chris Marotta almost 5 years
    You can use root to solve the problem (though this is not recommended).
  • Patrick Da Silva
    Patrick Da Silva almost 5 years
    Very 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
    Mooncake over 4 years
    Why would you allow the entire world to access this particular folder?
  • Pablo Papalardo
    Pablo Papalardo about 4 years
    It is a jr solution
  • Andrew
    Andrew almost 4 years
    You may not even need 777. For me the problem was just the #'s were too low. (775 fixed it.)
  • Frank H
    Frank H over 3 years
    I 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
    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
    Simon Degn over 3 years
    I agree @PatrickDaSilva. This messed up my entire server..
  • Radoslaw
    Radoslaw over 3 years
    4. on Catalina source ~/.zshrc
  • raphael75
    raphael75 over 3 years
    It 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
    Shams Nahid about 3 years
    Worked on 20.04 also.
  • William
    William about 3 years
    this worked for me: sudo npm install --save -g solgraph --unsafe-perm=true --allow-root
  • csharpbd
    csharpbd about 3 years
    Thanks @Manohar Reddy Poreddy, after trying many solutions this worked for me.
  • ThaJay
    ThaJay almost 3 years
    Anyway 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
    JackHacks almost 3 years
    This answer seems like a better practive
  • devaent
    devaent almost 3 years
    this works for me on Ubuntu 18.04. Thanks for the help
  • ekerner
    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
    Entropy over 2 years
    Worked on Mac M1 Big Sur. Thank you!
  • tripleee
    tripleee about 2 years
    Whatever 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, probably chmod 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
    zzzgoo about 2 years
    this will cause a git issue. All the files will be notified as modified.
  • Anurag Shukla
    Anurag Shukla about 2 years
    Worked like a charm!
  • Hack06
    Hack06 almost 2 years
    For those who arrive here trying to install with 'yarn' instead of 'npm', just replace it respectively.