Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm package fails to install "npm ERR! Error: EACCES: permission denied" #14

Closed
pallatee opened this issue Apr 7, 2016 · 181 comments
Closed

Comments

@pallatee
Copy link

pallatee commented Apr 7, 2016

While trying to install a packge with npm (for example lodash) it fails with error message:

npm ERR! Linux 3.4.0+
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "lodash"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.3
npm ERR! path /root/test/node_modules/.staging/lodash-9a2aabe2
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename

npm ERR! Error: EACCES: permission denied, rename '/root/test/node_modules/.staging/lodash-9a2aabe2' -> '/root/test/node_modules/lodash'
npm ERR!     at destStatted (/usr/lib/node_modules/npm/lib/install/action/finalize.js:25:7)
npm ERR!     at FSReqWrap.oncomplete (fs.js:82:15)
npm ERR!
npm ERR! Error: EACCES: permission denied, rename '/root/test/node_modules/.staging/lodash-9a2aabe2' -> '/root/test/node_modules/lodash'
npm ERR!     at Error (native)
npm ERR!  [Error: EACCES: permission denied, rename '/root/test/node_modules/.staging/lodash-9a2aabe2' -> '/root/test/node_modules/lodash']
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!     /root/test/npm-debug.log

I have tried to install it both with and without starting bash in administrator mode.

@borovaka
Copy link

borovaka commented Apr 7, 2016

There is another wired thing about npm. When I try to install gulp globally I get:

Error: could not get uid/gid
net.js:135
    this._handle.open(options.fd);
                 ^

Error: EINVAL: invalid argument, uv_pipe_open
    at Error (native)
    at new Socket (net.js:135:18)
    at createWritableStdioStream (internal/process/stdio.js:142:16)
    at process.stdout (internal/process/stdio.js:10:14)
    at console.js:99:37
    at NativeModule.compile (node.js:395:5)
    at Function.NativeModule.require (node.js:340:18)
    at node.js:223:27
    at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/uid-number/get-uid-gid.js:16:1)
    at Module._compile (module.js:413:34)

    at /usr/lib/node_modules/npm/node_modules/uid-number/uid-number.js:37:16
    at ChildProcess.exithandler (child_process.js:209:5)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:850:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:90:13)
    at Socket.emit (events.js:182:7)
    at Pipe._onclose (net.js:475:12)

@jamesscholeyweb
Copy link

Same here. In fact if I try to update npm update -g npm@latest it attempts to copy lodash to the staging directory then throws the errror. Following this subsequent attempts to use npm are broken because it can no longer find lodash.

IMPORTANT

This really should be of utmost importance to the team. I for one was very excited and love how everything else works, but as you are adding this feature to windows with the intention of bringing web developers back to windows this needs fixing ASAP. This alone will stop me switching back to windows for web development and I'm sure it will be the same for many. It defeats the purpose of switching for me. Please please please fix.

@jgchristopher
Copy link

@borovaka you can fix that error by allowing unsafe perms

npm config set unsafe-perm=true

@jamesscholeyweb
Copy link

Already tried. It bypasses the error but it still doesn't work. You will
get a permissions access error still or at least I did.

On Friday, April 8, 2016, John Christopher notifications@github.com wrote:

@borovaka https://github.com/borovaka you can fix that error by
allowing unsafe perms

npm config set unsafe-perm=true


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#14 (comment)

@jgchristopher
Copy link

@jamesscholeyweb right, I was able to get to your error after setting those perms. Otherwise I wasn't able to do anything.

@jgchristopher
Copy link

This seems to be the underlying issue.

root@localhost:/usr/lib/node_modules/.staging# rename /usr/lib/node_modules/.staging/lodash-24c8c2f4 /usr/lib/node_modules/ember-cli/node_modules/babel-core/node_modules/lodash Bareword found where operator expected at (eval 1) line 1, near "24c8c2f4" (Missing operator before c8c2f4?) Unknown regexp modifier "/b" at (eval 1) line 1, at end of line syntax error at (eval 1) line 1, near "/."

@Sparticuz
Copy link

Related: MicrosoftDocs/WSL#26

It seems to be an issue with symlinks

@jbaribeault
Copy link

Confirmed - this is totally related to the symlink issue.

@jamespacileo
Copy link

Same here with

npm install typescript

Here's the output

npm WARN enoent ENOENT: no such file or directory, open '/root/package.json'
npm WARN root No description
npm WARN root No repository field.
npm WARN root No README data
npm WARN root No license field.
npm ERR! Linux 3.4.0+
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "typescript" "gulp" "tsd"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.3
npm ERR! path /root/node_modules/.staging/ansi-regex-0de81b15
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename

npm ERR! Error: EACCES: permission denied, rename '/root/node_modules/.staging/ansi-regex-0de81b15' -> '/root/node_modules/ansi-regex'
npm ERR!     at destStatted (/usr/lib/node_modules/npm/lib/install/action/finalize.js:25:7)
npm ERR!     at FSReqWrap.oncomplete (fs.js:82:15)
npm ERR!
npm ERR! Error: EACCES: permission denied, rename '/root/node_modules/.staging/ansi-regex-0de81b15' -> '/root/node_modules/ansi-regex'
npm ERR!     at Error (native)
npm ERR!  [Error: EACCES: permission denied, rename '/root/node_modules/.staging/ansi-regex-0de81b15' -> '/root/node_modules/ansi-regex']
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!     /root/npm-debug.log

@russalex
Copy link
Contributor

This looks a lot like #3. We can keep the conversation going on there.

What I can say right now is that things are getting better (at least in non-mnt directories.). On my dev box I see:

russ@RUSSALEX-DESK:~/tmp$ npm list
/home/russ/tmp
├── acorn@3.0.4
├─┬ gulp@3.9.1
│ ├── archy@1.0.0
│ ├─┬ chalk@1.1.3
│ │ ├── ansi-styles@2.2.1
│ │ ├── escape-string-regexp@1.0.5
│ │ ├─┬ has-ansi@2.0.0
│ │ │ └── ansi-regex@2.0.0
│ │ ├─┬ strip-ansi@3.0.1
│ │ │ └── ansi-regex@2.0.0
│ │ └── supports-color@2.0.0
│ ├── deprecated@0.0.1
│ ├─┬ gulp-util@3.0.7
│ │ ├── array-differ@1.0.0

It goes on from there. I should point out that I have not tried to actually use any of these, I have only installed them.

The team is hard at work getting stuff up and running. Npm is one of those things we're looking at now.

@russalex
Copy link
Contributor

Full disclosure here. Doing a little more testing on our internal build and finding that doing an "npm -g install " still throws the uv_pipe_open error, even when in ~/tmp.

We have someone looking into it.

@mablae
Copy link

mablae commented Apr 16, 2016

This seems also to be a valid issue when running npm in the new Windows 10 Bash

This solved it for me: https://gist.github.com/mattpodwysocki/4e6951fc93adae064a73ed0b2251d180

npm config set unsafe-perm true

I have no idea what it does however.

@paseto
Copy link

paseto commented Jul 4, 2016

If you are using with -g option, try to remove it.

@bitcrazed
Copy link
Contributor

FWIW, installing lodash as per the OP's request works fine on build 14931!

image

@nolanlawson
Copy link

I just ran into this trying to do npm install -g ember-cli/ember-cli on 15063.2. 😕

npm config set unsafe-perm=true fixed it, but makes me uneasy.

@Sparticuz
Copy link

You can bypass all permission problems by changing the prefix for npm.
See option 2: https://docs.npmjs.com/getting-started/fixing-npm-permissions

@nolanlawson
Copy link

Actually I had already set the prefix to a local user directory, and I was still getting this error.

To fully repro:

npm config set prefix="${HOME}/my-special-npm-directory"
npm install -g ember-cli/ember-cli

@joeRob2468
Copy link

Hey, I just managed to fix an issue with my setup by taking ownership of the folder that Node was installed to. I use NVM to manage node versions, so in my case Node was installed in /home/myusername/.nvm.

So, to fix it, I used sudo chown -R myusername:myusername /home/myusername/.nvm. Weirdly enough, I had to run that command again each time I installed something globally, and I don't know enough to figure out why. It's a mystery!

@ilyaigpetrov
Copy link

ilyaigpetrov commented Apr 12, 2017

The error still happens in Windows 10 Creator's Update 10.0.15063. Here is what I tried:

  1. Turn off antivirus.
  2. After npm install -g npm check that npm was actually updated (>=4.4.4). Run hash -r to update bash cache. ~/.profile is not executed in current BashOnWindows, so move all npm-related PATH modifications from ~/.profile to ~/.bashrc.
  3. Even though I set prefix for npm to directory owned/chowned by a user, I still run sudo npm install enduro -g.
  4. I get the error.

@aseering
Copy link
Contributor

Does this happen if you don't use sudo in step 3?

@ilyaigpetrov
Copy link

@aseering no, it didn't work unfortunately, same rename error on node v6.10.2 and npm 4.4.4.

@SaltFish001
Copy link

Resolving EACCES permissions errors when installing packages globally
If you see an EACCES error when you try to install a package globally, you can either:

  • Reinstall npm with a node version manager (recommended),

or

  • Manually change npm's default directory

Reinstall npm with a node version manager
This is the best way to avoid permissions issues. To reinstall npm with a node version manager, follow the steps in "Downloading and installing Node.js and npm". You do not need to remove your current version of npm or Node.js before installing a node version manager.
Manually change npm's default directory

Note: This section does not apply to Microsoft Windows.

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.

  1. Back up your computer.
  2. On the command line, in your home directory, create a directory for global installations:

mkdir ~/.npm-global

  1. Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

  1. In your preferred text editor, open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH

  1. On the command line, update your system variables:

source ~/.profile

  1. To test your new configuration, install 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
npx: an alternative to running global commands

If you are using npm version 5.2 or greater, you may want to consider npx as an alternative way to run global commands, especially if you only need a command occasionally. For more information, see this article about npx.

如果不用sudo就没有权限

你用的nvm安装对吧,我试过,我在root下也会报错

@JoshuaMorleyWoodside
Copy link

still getting this issue now, i agree that running it with sudo and changing ownership/file permissions is not a fix

@saigo4work
Copy link

I faced the same issue as @jamespacileo in Windows 10 WSL 2 while trying to install a Svelte template on the Ubuntu side of the terminal. This command "npx degit sveltejs/template myproj/" was failing.

I switched from Ubuntu to PowerShell on Terminal and ran the operation there successfully. Once "myproj" was setup, I switched back to my Ubuntu terminal.

@gabrielstuff
Copy link

gabrielstuff commented May 3, 2021

If you still want to use the Ubuntu terminal make sure you have WSL 2 activated. This means, you should follow the instruction there : #1375 (comment) and make sure you have Hyper Virtualization activated.

It also helps resolve this issue : #2097

@on-the-brink
Copy link

How is this still an issue five years later? Microsoft, explain.

@12144
Copy link

12144 commented May 9, 2021

I had the same problem, it has been fixed using nvm and wsl 2.

Before that I tried:

  • set unsafe-perm true
  • sudo npm install --global
  • Uninstaslling node from windows
  • Running Ubuntu as administrator
  • Uninstalling and installing with sudo

I followed all the steps and all worked fine for me.
https://docs.microsoft.com/en-us/windows/nodejs/setup-on-wsl2

Note: I'm using Windows 10 Home Single Language

this works for me, thanks! Use nvm to install node and npm, do not install them independently

@daalvand
Copy link

daalvand commented Jul 11, 2021

I removed nodejs sudo apt remove nodejs then install nodejs current vestion from this link -> link

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

it worked for me.

@Tofandel
Copy link

I needed nodejs@14 but npm@latest and using n to switch to node 14 and then npm i -g npm@latest always resulted in the error

To solve the issue I installed the latest node using n n latest and then export N_PRESERVE_NPM=1 and again n 14 which allowed me to have node v14 with an up to date npm without this weird error

@hanzhangyu
Copy link

Resolving EACCES permissions errors when installing packages globally

If you see an EACCES error when you try to install a package globally, you can either:

  • Reinstall npm with a node version manager (recommended),

or

  • Manually change npm's default directory

Reinstall npm with a node version manager This is the best way to avoid permissions issues. To reinstall npm with a node version manager, follow the steps in "Downloading and installing Node.js and npm". You do not need to remove your current version of npm or Node.js before installing a node version manager.

Manually change npm's default directory

Note: This section does not apply to Microsoft Windows.

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.

  1. Back up your computer.
  2. On the command line, in your home directory, create a directory for global installations:

mkdir ~/.npm-global

  1. Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

  1. In your preferred text editor, open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH

  1. On the command line, update your system variables:

source ~/.profile

  1. To test your new configuration, install 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 npx: an alternative to running global commands

If you are using npm version 5.2 or greater, you may want to consider npx as an alternative way to run global commands, especially if you only need a command occasionally. For more information, see this article about npx.

try set prefix out of c disk, such as npm config set prefix '/mnt/f/npm/.npm-global'

@vivek0097
Copy link

C:\Users\Dell>npm audit

npm audit report

ansi-regex >2.1.1 <5.0.1
Severity: moderate
Inefficient Regular Expression Complexity in chalk/ansi-regex - GHSA-93q8-gq69-wqmw
fix available via npm audit fix
node_modules/npm/node_modules/cli-table3/node_modules/ansi-regex
node_modules/npm/node_modules/string-width/node_modules/ansi-regex
strip-ansi 4.0.0 - 5.2.0
Depends on vulnerable versions of ansi-regex
node_modules/npm/node_modules/string-width/node_modules/strip-ansi
string-width 2.1.0 - 4.1.0
Depends on vulnerable versions of strip-ansi
node_modules/npm/node_modules/string-width

3 moderate severity vulnerabilities

To address all issues, run:
npm audit fix

please any one can help to remove this error

@saideepesh000
Copy link

As of now, I still faced the issue, closing vs code worked for me
image

@vivek0097
Copy link

I got error with 64 bit node 14,16,17v so i just uninstall this i am not able to create npx create-react-app, so i install 34 bit node latest version now i am able to create react-app my os is 64-bit.

@akillingbeck89
Copy link

Easiest solution here I found was to just use a node package manager (e.g. NVM), then global installs work fine at least

@tinarooot
Copy link

tinarooot commented Mar 16, 2022 via email

@jimbethancourt
Copy link

If you're using VS Code and find yourself getting this error message, close VS Code, run the desired command, and restart VS Code, as indicated in https://stackoverflow.com/questions/60853873/eaccess-error-when-installing-packages-on-wsl

@gifflet
Copy link

gifflet commented May 11, 2022

If you installed node from apt-get, uninstall it completely and install it from NVM (Node Version Manager)

Uninstalling node (Ubuntu)

sudo apt-get purge --auto-remove nodejs

Update apt indexes

sudo apt update && sudo apt upgrade

Install NVM

sudo apt-get install -y curl \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \
&& source ~/.bashrc

Finally, install node and npm

nvm install --lts

@tinarooot
Copy link

tinarooot commented May 11, 2022 via email

@Jahongirhacking
Copy link

Jahongirhacking commented Jul 19, 2023

@borovaka you can fix that error by allowing unsafe perms

npm config set unsafe-perm=true

it says:

npm ERR! `unsafe-perm` is not a valid npm option

npm ERR! A complete log of this run can be found in:
npm ERR! `path`    

@tinarooot
Copy link

tinarooot commented Jul 19, 2023 via email

@Jahongirhacking
Copy link

If you installed node from apt-get, uninstall it completely and install it from NVM (Node Version Manager)

Uninstalling node (Ubuntu)

sudo apt-get purge --auto-remove nodejs

Update apt indexes

sudo apt update && sudo apt upgrade

Install NVM

sudo apt-get install -y curl \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \
&& source ~/.bashrc

Finally, install node and npm

nvm install --lts

Thanks it worked

@PttRulez
Copy link

PttRulez commented Oct 8, 2023

I have fixed my problem on mac by
sudo chown -R 501:20 "/Users/<my_username>/.npm"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests