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?
Running the following command solved the issue for me while installing my packages.json :
To install only the package which caused the issue:
Try this commandsudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules}
this will change the ownership of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Update
Follow this link as suggested by other users.
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
Option 2: Use a package manager that takes care of this for you
Use
--unsafe-perm=true
and--allow-root
flags withnpm
install like below:-it worked like charm for me.
Use sudo before tns and it is work for me
Example:
if I have used sudo then not found error like to create postinstall.js
is sufficient.