Error: EACCES: permission denied

while running command npm install lodash you may face Error: EACCES: permission denied error. There are multiple reason of this error however primary reason is permission issue.

Here you will get to know the reason of Error: EACCES: permission denied and the possible solution to fix this error.

Why “EACCES: permission denied” error occur?

The reason of occurring Error: EACCES: permission denied is running npm command in unsafe mode and the owner of the folder is not a root owner and does not have permission to run this command.

Below is the error snap shot:

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.

At the end of the error , as stated that running this command is require root or administrator permission. lets check out the possible solution to fix this error.

How to run npm as administrator?

Use below command to resolve the error.

Method 1 :

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

Method 2 :

To give all permission to your project folder with below command

See also  Workers Compensation Insurance in Texas

sudo chmod -R 777 /yourProjectDirectoryName

Run Command

sudo npm install lodash

Method 3 :

Webpack server installation on globally. 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