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
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-globalConfigure 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:$PATHBack 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
This command fix the issue. It worked for me:
sudo npm install -g --unsafe-perm=true --allow-root
Creating package.json using npm init solved my issue.
I had problem on Linux. I wrote
chown -R myUserName ./*
in my project folder.
From what i can see in your logs you posted:
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',
directory /home/rupesh/node_modules/ doesn't have necessary permissions to create directory so run chown -r rupesh:rupesh /home/rupesh/node_modules/ this should solve it.
FWIW I had the same symptoms, but with a different package. Creating package.json and running npm init did NOT solve my issue.
On this system, apparently new folders in this location were being created with root permissions. During npm install, new folders are created. This caused npm install to fail partway, even with sudo.
The solution was to run npm install app in a different location with no root umask.
It doesn't have write permissions for others (r-x). Try with
chmod a+w <folder>
and repeat.
First install without -g (global) on root. After try using -g (global) It worked for me.
I solved this issue by changing the permission of my npm directory. I went to the npm global directory for me it was at
/home/<user-name>
I went to this directory by entering this command
cd /home/<user-name>
and then changed the permission of .npm folder by entering this command.
sudo chmod -R 777 ".npm"
It worked like a charm to me. But there is a security flaw with this i.e your global packages directory is accessible to all the levels.
Remove dist folder and this solve my problem!!
Execute these commands and issue will be solved!
sudo chmod -R 777 /usr/local/bin
sudo chmod -R 777 /usr/local/lib/node_modules
来源:https://stackoverflow.com/questions/38323880/error-eacces-permission-denied