Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install: Error: EACCES: permission denied, mkdir

I attempted to do a sudo npm install -g appium on Mac OS 10.12.5.

I get this error:

info Chromedriver Install Installing Chromedriver version '2.30' for platform 'mac' and architecture '64'

info Chromedriver Install Opening temp file to write chromedriver_mac64 to...

Error: EACCES: permission denied, mkdir

'/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/2017820-44752-12jfqpb.z2hd'

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! [email protected] install: node install-npm.js npm ERR! Exit status 1 npm ERR!

this is not a dup question, as this install attempt was with sudo, as the other one was not.

like image 516
Steve W Avatar asked Sep 20 '17 17:09

Steve W


2 Answers

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

Worked for me

like image 138
Long Nguyen Avatar answered Oct 21 '22 15:10

Long Nguyen


The -g option means install globally. When packages are installed globally, EACCES permission errors can occur.

Consider setting up npm to operate globally without elevated permissions. See Resolving Permission Errors for more information.

Option 1

The best way to avoid permission issues is to reinstall NodeJS and npm using a node version manager.

1. Install nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

You can close and reopen the terminal ou just open another terminal and check if nvm is installed properly with this command: command -v nvm.

2. To download and install the latest LTS release of NodeJS, run:

nvm install --lts

3. Set the newly installed NodeJS as the default environment:

nvm alias default lts/*

Option 2 (Does not apply for windows)

Change the owner of npm's directories to the current user:

sudo chown -R $(your_user) /usr/local/{lib/node_modules,bin,share}
sudo chown -R $(your_user) ~/.npm ~/.npmrc
like image 21
AzafoCossa Avatar answered Oct 21 '22 13:10

AzafoCossa