Reputation: 7684
What might be causing the error Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
?
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log
Upvotes: 754
Views: 972317
Reputation: 643
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Upvotes: 5
Reputation: 146
In my case, just restarting the computer helped. I am running on Windows Subsystem For Linux
Upvotes: 0
Reputation: 1709
I tried the solution of the answer given by @okanda but it didn't work for me.
However it worked perfectly when I did it for several folders like mentioned in this thread: https://github.com/angular/angular-cli/issues/9676#issuecomment-464857493
sudo chown -R $USER /usr/local/lib/
sudo chown -R $USER /usr/local/bin/
sudo chown -R $USER /usr/local/share/
Upvotes: 156
Reputation: 145
I followed some of the answers on this question as I was getting the Error: EACCES: permission denied
error.
Nothing I did worked except from starting again fresh without node modules.
In the end for me to run the following successful I had to
npm update --save
successfullyHopefully this helps someone who was in the same boat as me!
Upvotes: 0
Reputation: 175
I was getting this error while starting the VITE frontend server. I resolved it by adding sudo (since it is some file level permission issue) sudo npm run dev
. This is not the best/safest solution but the easiest.
Upvotes: 1
Reputation: 5791
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use a hidden directory in your home directory.
Back up your computer. On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create the ~/.profile
file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
To test your new configuration, install a package globally without using sudo
.
Source: the NPM website.
Upvotes: 557
Reputation: 12254
Change your file permissions... Like this
First check who owns the directory
ls -la /usr/local/lib/node_modules
it is denying access because the node_module folder is owned by root
drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules
so this needs to be changed by changing root to your user but first run command below to check your current user How do I get the name of the active user via the command line in OS X?
id -un
OR whoami
Then change owner
sudo chown -R [owner]:[owner] /usr/local/lib/node_modules
OR
sudo chown -R ownerName: /usr/local/lib/node_modules
OR
sudo chown -R $USER /usr/local/lib/node_modules
Upvotes: 1156
Reputation: 1518
If you are experiencing this problem on your Mac, Take the following steps First, use the command below to determine who owns this file.
ls -la /usr/local/lib/node_modules
You will find some files below, one of which is listed below.
drwxr-xr-x 3 root wheel 768 May 29 02:21 node_modules
Have you noticed that the above file is owned by root? To make changes inside, you must change the path's ownership.
This command can be used to determine who the current user is.
id -un (in my case user is Yamsol)
and then you can change by calling this command (just replace your user name with ownerName)
sudo chown -R ownerName: /usr/local/lib/node_modules
in my case as you know the user is "yamsol" I will call this command this way
sudo chown -R yamsol: /usr/local/lib/node_modules
that's it.
Upvotes: 34
Reputation: 1190
All you need to do is to add USER to the owner of /local/lib
sudo chown -R $USER /usr/local/lib
EDIT :
To target precisely and only the node_modules folder, try using this command before using the previous one :
sudo chown -R $USER /usr/local/lib/node_modules
Upvotes: 92
Reputation: 1727
On my mac similar issue is coming while installing Ionic.
I run the command
sudo chown -R $USER /usr/local/
path you can update as given in error.
Upvotes: 6
Reputation: 28968
You can install npm through Node version manager or a Node installer. In the docs it states:
We do not recommend using a Node installer, since the Node installation process installs npm in a directory with local permissions and can cause permissions errors when you run npm packages globally.
NPM actually recommends using a Node Version Manager to avoid these errors.
Since you have the permission error, you probably installed npm through a Node installer and now you need to reinstalled it with a nvm (node version manager).
Luckily, this is very simple. You do not even need to remove your current version of npm or Node.js.
All you need to do is
Install nvm. For OSX or Linux Node use:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/<VERSION>/install.sh | bash
where <VERSION>
should be replaced with the latest version
This creates a nvm folder in your home directory.
Then
Install npm and node.js through nvm. To do so, just call
nvm install node
("node" is an alias for the latest version)
Now you can install your package globally without using sudo
or changing the owner of node_modules
in usr
folder.
Upvotes: 52
Reputation: 249
I got the same error and solve it using the command
sudo npm install -g expo-cli --unsafe-perm
Here in image after running the command
then run the following commandf to update npm
I easily solve the problem.
Upvotes: 0
Reputation: 53
If you are running Linux(ie: Arch)
# npm -g install packageName
By default this command installs the package under /usr/lib/node_modules/npm and requires root privileges to do so.
To allow global package installations for the current user, set the npm_config_prefix
environment variable. This is used by both npm and yarn.
mkdir ~/.node_modules
cat ~/.profile
PATH="$HOME/.node_modules/bin:$PATH"
export npm_config_prefix=~/.node_modules
Re-login or source to update changes.
You can also specify the --prefix
parameter for npm install
. However, this is not recommended, since you'll need to add it every time you install a global package.
$ npm -g install packageName --prefix ~/.node_modules
So you dont have to chown folder permision
Upvotes: 2
Reputation: 1144
Encountered in CentOS 8 stream
Solution
(1/4) Creating node_modules folder
$ sudo mkdir /usr/local/lib/node_modules
(2/4) Own with Current User
$ sudo chown -R $USER /usr/local/lib/node_modules/
(3/4) Own the bin
folder
$ sudo chown -R $USER /usr/local/bin/
(4/4) Own the share
folder
$ sudo chown -R $USER /usr/local/share/
Upvotes: 8
Reputation: 32
in case anyone want to make the user to have access like a root user check out this https://support.apple.com/en-us/HT204012
this supposed to be the best approach if the user account is the owner of the account
Upvotes: -1
Reputation: 4167
Be careful with all responses that change the owner of all directories under /usr/local Basically, don't mess the Linux system!!!
Using sudo
for your local stuff is a really bad recommendation as well.
The original link from www.competa.com is broken, so this is the original approach from there:
npm config set prefix ~/.npm
# open your .bashrc (Linux) or .bash_profile (Mac) file for editing:
nano ~/.bashrc # for Linux
# or...
nano ~/.bash_profile # for Mac if you haven't created a .bashrc file
# add these lines:
export PATH="$PATH:$HOME/npm/bin"
export NODE_PATH="$NODE_PATH:$HOME/npm/lib/node_modules"
# save the file and then enter this command or logout and login to make the changes take effect:
. ~/.bashrc
# or...
. ~/.bash_profile
Option B: Use a version manager like NVM
Upvotes: 24
Reputation: 681
Review this carefully:
https://ionicframework.com/docs/developing/tips#resolving-permission-errors
sudo chown -R $(whoami) /usr/local/{lib/node_modules,bin,share}
sudo chown -R $(whoami) ~/.npm ~/.npmrc
Upvotes: 9
Reputation: 681
The best way to solve this issue (as the solution may vary from one device to another) is to read carefully the error in order to figure out which folder needs write
access.
In my case, I had to give /usr/local/lib
and /usr/local/bin
permissions.
Upvotes: 1
Reputation: 793
brew uninstall node
brew install node
sudo npm install -g "your_package" --unsafe-perm=true --allow-root
Hopes this helps someone
Upvotes: 3
Reputation: 510
Simple solution for linux users, just add sudo in front of whatever command you're running for npm
Upvotes: -3
Reputation: 375
Below command worked for me:
sudo npm install -g appium --unsafe-perm=true --allow-root
Upvotes: 5
Reputation: 331
in my case it works i.e i want npm link so when I hit sudo npm link it works
sudo npm install
because sudo gives you permissions to superuser levels. superuser account is usually called 'Administrator.' In Linux/Unix the superuser account is generally named 'root'.
The root user has permission to access, modify or delete almost any file on your computer. Normal user accounts can access, modify or delete many fewer files. The restrictions on a normal account protect your computer from unauthorized or harmful programs or users.
Upvotes: -2
Reputation: 453
If it is still not working after giving permissions try running these commands:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
and finally test with this command
npm install -g jshint
This does not work for Windows.
Upvotes: 15
Reputation: 3899
For those of you still unable to fix the problem after using the above mentioned solutions. Try this
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
That should do the trick, cheers!
Upvotes: 5
Reputation: 1134
Similar to POsha's answer but this is what worked for me on ubuntu 19
sudo npm i -g ngrok --unsafe-perm=true --allow-root
From this link
https://github.com/inconshreveable/ngrok/issues/429
Upvotes: 3
Reputation: 1440
This occurred as a result of npm
not being able to access your global node_modules
directory locally, running
sudo chown -R Name: /usr/local/lib/node_modules
e.g.
sudo chown -R developerayo: /usr/local/lib/node_modules
fixes the issue, now you can run the command you ran again.
Upvotes: 5
Reputation: 12996
sudo chown -R $USER /home/bereket/.nvm/versions/node/v8.9.1/lib/node_modules
and
sudo chown -R $USER /usr/local/lib/node_modules/
replace v8.9.1
with your node version you are using.
Upvotes: 7