80

I'm trying to install ESLint with npm by going:

npm install -g eslint

However I get the following error:

Deans-Air:~ deangibson$ npm install -g eslint
npm ERR! tar.unpack untar error /Users/deangibson/.npm/eslint/2.4.0/package.tgz
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "eslint"
npm ERR! node v4.2.3
npm ERR! npm  v2.14.7
npm ERR! path /usr/local/lib/node_modules/eslint
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/eslint'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/eslint']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/eslint',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/eslint',
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!     /Users/deangibson/npm-debug.log

And to be honest I get this every single time I try and install something with npm. Sometimes using 'sudo' works, sometimes it doesn't... How can I fix this once and for all?

11 Answers11

145

Use --unsafe-perm=true and --allow-root flags with npm install like below:-

sudo npm install -g eslint --unsafe-perm=true --allow-root

it worked like charm for me.

DHRUV GUPTA
  • 2,000
  • 1
  • 15
  • 24
52

This problem is well documented in the npm docs: Fixing npm permissions.

You have 2 solutions available:

Option 1: Change npm's default directory to a hidden directory in your home folder

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile

Option 2: Use a package manager that takes care of this for you

brew install node
Eray Erdin
  • 2,633
  • 1
  • 32
  • 66
Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
11

Running the following command solved the issue for me while installing my packages.json :

 sudo npm install --unsafe-perm=true --allow-root

To install only the package which caused the issue:

  sudo npm install -g --unsafe-perm=true --allow-root eslint
mahmoud mehdi
  • 1,493
  • 1
  • 19
  • 28
5

guys, I have fixed it simplely by

sudo npm install

I have tried the toppest answer, it works well too.

gyoko_chen
  • 69
  • 1
  • 2
3
sudo npm install -g --unsafe-perm=true eslint

is sufficient.

Floern
  • 33,559
  • 24
  • 104
  • 119
Rahul
  • 181
  • 1
  • 8
3

Use sudo before tns and it is work for me

Example:

sudo tns create Tekmo --template tns-template-hello-world

if I have used sudo then not found error like to create postinstall.js

Error: EACCES: permission denied

Partho63
  • 3,117
  • 2
  • 21
  • 39
Abhijeet Jadhav
  • 188
  • 1
  • 4
2

for MacOS users having this issue!

while starting the react server, write sudo npm start not npm start.

That solved the issue for me.

Slmn
  • 33
  • 5
1

you can login as root using sudo su. First run the command sudo su on your terminal, then give your login password. Finally execute your expected command npm install -g eslint. It works for me.

Ziaur Rahman
  • 1,148
  • 11
  • 24
0

For MAC user provide the access permission to project directory folder

  1. Right click on project directory folder
  2. Select get info
  3. Provide the access permission - Apply to inclosed items
Nandu Hulsure
  • 123
  • 1
  • 7
0

This is a simple permissions error and one of the ways to resolve it is to simply delete the node_modules folder and run npm install again, making sure you are not the root user.

-1

Just had the same error while running

npm install -g @ionic/cli native-run cordova-res

To fix, run the following

sudo apt update
sudo apt upgrade -y

I had read the already present solutions but thought there was something else, UNSAFE isn't a safe keyword, lol. While running the command with the --unsafe-perm=true, I noticed it downloading what seemed to be update binaries. So, I updated and tried again.

igmrrf
  • 459
  • 4
  • 11