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

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.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 146
  • Comments: 181 (7 by maintainers)

Most upvoted comments

@borovaka you can fix that error by allowing unsafe perms

npm config set unsafe-perm=true

This is a known issue with VSCode remoting and WSL (Microsoft/WSL#3395, Microsoft/WSL#1956) and should be fixed in WSL2.

This is caused because VSCode remoting watches files, which prevents them from being accessed elsewhere. The fix is to tell VSCode to poll when remote instead of watch. See below:

  1. ctrl+shift+p then type & select Preferences: Open Settings (JSON).
  2. Add "remote.WSL.fileWatcher.polling": true to the config
  3. ctrl+shift+p then type & select Developer: Reload Window.

For more information, see the documentation on VSCodes website regarding EACESS.

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

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.

Closing VSCode before npm install solved the issue.

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.

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!

If it helps anyone I’ve traced it down to having vscode-insider open while npm installing.

When it’s turned off, it appears to work fine. It might have something to do with the watchers.

FWIW our team was having this problem intermittently trying to npm install on a mounted windows directory and were pulling our collective hair out re-installing node, checking versions, etc. It turns out it was just because we were all using vscode with the folder open in a workspace. You also need to make sure you don’t have any running node processes (dev server, watching build script, etc). Once I shut all of those down I stopped getting the errors. I do suspect that there are many root causes of this issue though, and open file handles are just one of them.

In my case it was VS Code locking a file in node_modules. Closing VS code unlocked the file and made the error go away. npm config set unsafe-perm true, disabling antivirus etc. did not work.

sudo npm install -g npm@5.3.0 that sorted it for me

Anyone who got here with this issue whilst trying to run npm i in VSCode remote WSL:

Restart VSCode or close VSCode and run npm in your terminal. Seems to be a separate issue where VSCode is holding onto file references or something.

It turns out it was just because we were all using vscode with the folder open in a workspace

This fixes it.

Yes. For me too. To be clearer: I closed VSCode. Instead of using VSCode integrated terminal, I used the Ubuntu 18.04 LTS app directly (in Windows, this opens a terminal).

It turns out it was just because we were all using vscode with the folder open in a workspace

This fixes it.

Hey quick fix! Instead of using npm install -g typescript use sudo npm install -g typescript Hope that helps. 😃

I’ve discovered it’s an issue with open handles. VSCode can hold handles for longer than it should. Trying a command in just a bash shell open in Powershell can give EACESS errors. The act of just closing VSCode and trying the command again the bash shell works.

This has happened even when I close the related workspace on VSCode. The handle seems to only release when I actually close VSCode.

That doesn’t make much sense, but perhaps the WSLv1 filesystem isn’t properly closing files, or perhaps some logic faulty when a file handle is open and another tries to delete it?

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

For anyone facing this issue: If you have mounted any windows folder in ubuntu so that you can use the command line functionalities and also GUI code editors through windows, this is bound to happen. Its because of some file locking rules done by windows.

So whenever this error comes up, close all the code editors or any other programs using this mounted folder in windows.

This has worked for me all the time.

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

It is not recommended to use sudo when installing npm packages.

Similarly, npm config set unsafe-perm true should be avoided.

Regardless of security concerns, neither option is necessary. A better solution:

  1. Open a terminal from your home directory and make a new directory for global installs: mkdir ~/.npm-global
  2. Configure npm to use the new directory path: npm config set prefix ~/.npm-global
  3. Open or create a ~/.profile file (I use vim, use whatever) and add the following line: export PATH=~/.npm-global/bin:$PATH
  4. After saving your ~/.profile ([Esc] -> :x! -> [Enter]), update system variables: source ~/.profile
  5. Test your new configuration by installing a package globally without using sudo: npm install -g pnpm

You can skip steps 2-4 if you prefer not to modify ~/profile by setting an ENV variable: NPM_CONFIG_PREFIX=~/.npm-global

Things work better for me when I set fewer environment variables… YMMV.

Tested with:

  • Windows 10 Home - Insiders: Version 1903 Build 18353.1
  • Visual Studio Code - Insiders: Version 1.33.0-user
  • WSL: 4.4.0-18353-Microsoft
  • Ubuntu: 18.04.2 LTS
  • Node: 11.11.0
  • npm: 6.7.0

Reference => official NPM docs:

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

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.

sudo npm install -g npm worked for me

Get this error in 2020 (after openninig this issue in 2016) it still appearing. What the heck?! With this problem, I cannot to delete ./node_modules/ in my react project on last version of Windows LTSC. And VS Code does not support IntelliSense and autocomplete with error of access.

Ghost methods with unsafe-perm=true and sudo not worked. At least sudo not supported in Git Bash on Windows.

And with old projects I have no this issue (created about half year ago). That feeling that problem in release of Create React App. But I can’t understand where is the problem to fix it by self.

Try to use sudo -S npm i

@allain I can confirm this. Just shut down VSC Insider and my npm install worked fine.

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)

As a new developer, this issue has had me stumped for days. In order to keep in-line with the rest of the team who use Linux or MacOS, I have to develop through WSL. This issue really needs to be solved.

For me, closing VSCode, opening WSL terminal and running npm install there worked.

hey guys , if you using mac try running the command with sudo . it may help alot 😃

Although, I’m using Ubuntu, I tried cleaning npm cache sudo npm cache clear --force

and then it allowed me to run without sudo npm i

The other options didn’t work for me and I can’t asure that this is the best option.

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

Still have the same issue, this is ridiculous! Opened in 2016 still not resolved.

This fixed my issue sudo chown -R $USER ~/.npm

Using MacOS Mojave

Fixed my install with NVM and NPM 8.8.0 using:

sudo chown -R u:p node_modules
sudo chown -R u:p u/.nvm

Where u is username and p is password. Had to do this on both directories! Thanks for the tips above, chmod wouldn’t do.

Hope that helps someone!

PS - that was in the root directory of the project and root directory of WSL, respectively.

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

If it helps anyone I’ve traced it down to having vscode-insider open while npm installing.

When it’s turned off, it appears to work fine. It might have something to do with the watchers.

Same here as well. Win 10 WSL Ubuntu 18.04. Once I close code-insider it works like a charm.

sudo chown -R myusername: /usr/local/lib/node_modules

This solved my issue

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.

I updated Windows to version 2004 today so I could use WSL2. I am now encountering this exact issue for the first time, having never been troubled by it in WSL1.

Windows 10 2004 WSL 2 WSL 1 Ubuntu 20.04 LTS nvm v0.35.3 node v12.18.0 npm v6.14.4

Edit: Apparently my distro was somehow still on WSL 1, even though it was installed after running wsl --set-default-version 2. Apologies for the false alarm.

Not sure what else to try but consistently running into this issue on Ubuntu 18.04 WSL 2 on 19033. Node v12.13.0, NPM v. 6.12.0. 1. Running npm i -g npm with npm installed via nvm to get away from global restrictions. $NVM_DIR, set in ~/.bash_profile pointing to /home/myuser/.nvm and I’ve tried sudo chown -R $(whoami) $HOME/.nvm, cleaning the cache, and setting npm config set unsafe-perm=true but so far no luck. Previously I think I had installed node via curl (?) and it showed in usr/lib/ but removed those directories and now which npm and which node shows the correct nvm locations. Still no luck, even with VS Code closed and on repeat attempts. Error messages seem to always revolve around node/versionnumber/lib/node_modules/.staging.

Figured you don’t even have to close VSC, just make sure the directory is not currently open in the files list. Thanks for the tip!!!

@allain I can confirm this. Just shut down VSC Insider and my npm install worked fine.

great! thanks!!

If you have mounted any windows folder in ubuntu so that you can use the command line functionalities and also GUI code editors through windows, this is bound to happen

This whole two year thread is #1529. The problem here is not permissions and never has been. [It is utterly unrelated to #3 which was a symlink problem, and how this one got closed.] You can install your whole NodeJS ecosystem as user yourself; you are still going to trip #1529. I asked in a related post that WSL at least throw off a (nonconforming) EBUSY so we could differentiate from actual EACESS problems but there was no response (what you gonna do).

Closing editors will help, if the thing holding open a handle is an editor. But if you take the example a couple of posts back, .loader-fs-cache is still holding a handle. No one is editing anything there. Y’all have been rebooting and discovering “works fine now”, because you’ve closed all the handles. And the thing is you’ve got open handles in node in spades much of the time, because of the client-server nature of the beast.

For now you can (a) be meticulous about making sure there are no file handles open in your node universe before running npm (b) hope that your node packages get updated to be more tolerant of the problem and/or © wait for #1529 to flip.

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

We have someone looking into it.

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

Using sudo worked.

sudo npm install -g npm@latest

@hajimurtaza :

This issue seems to come when changes are made to package.json file without npm knowing about it. Just do a plain npm install. Then install your module again. It should work.

You’re wrong there. This issue occurs when VSCode / VSCode Insiders is open in the project folder and you’re trying an npm install.

If it helps anyone I’ve traced it down to having vscode-insider open while npm installing.

When it’s turned off, it appears to work fine. It might have something to do with the watchers.

Yep. Confirmed here too

I just change my npm@5.4.1 to npm@5.3.0, it’s fine now. You can use npm i -g npm@5.3.0 to downgrade.

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

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

I had the same problem, but you have to write “sudo npm i -g typescript” and it worked. 😃

我也遇到过同样的问题,但是你必须写“ sudo npm i-g typescript” ,结果奏效了。 😃

不行 如果用了sudo npm xxxx就会报npm找不到命令

Finally got a fix: ensured I did a full uninstall of any global (non-nvm) node/npm directories with sudo apt-get purge --auto-remove nodejs (and whether this next bit was necessary or not) reinstalled my node version by doing nvm install [other_version], nvm uninstall [current_version], then reinstalled. Now working fine at the moment. Assuming there was something still trying to point to files in that original node install.

npm adduser --registry=http://xx.xx.xx.xx then: npm publish --registry=http://xx.xx.xx.xx

well, I still have the issue. sudo chown -R $(whoami) /usr/lib/node_modules and sudo chown -R $(whoami) ~/.npm didn’t worked. sudo npm i -g npm throws this error:

npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/yargs
npm ERR! dest /usr/local/lib/node_modules/.staging/yargs-1b99ab7e
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/yargs' -> '/usr/local/lib/node_modules/.staging/yargs-1b99ab7e'
npm ERR!  [OperationalError: EACCES: permission denied, rename '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/yargs' -> '/usr/local/lib/node_modules/.staging/yargs-1b99ab7e'] {       npm ERR!   cause: [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/yargs' -> '/usr/local/lib/node_modules/.staging/yargs-1b99ab7e'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'rename',
npm ERR!     path: '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/yargs',
npm ERR!     dest: '/usr/local/lib/node_modules/.staging/yargs-1b99ab7e'
npm ERR!   },
npm ERR!   stack: "Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/yargs' -> '/usr/local/lib/node_modules/.staging/yargs-1b99ab7e'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/yargs',
npm ERR!   dest: '/usr/local/lib/node_modules/.staging/yargs-1b99ab7e'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/kamil/.npm/_logs/2019-11-15T12_54_32_666Z-debug.log

VSCode is closed, like every other node process via killall node.

NPM was installed via NVM and copied to /usr/local via:

n=$(which node); \
n=${n%/bin/node}; \
chmod -R 755 $n/bin/*; \
sudo cp -r $n/{bin,lib,share} /usr/local

Installing any given node version via NVM works. Trying to update any NPM for the selected version gives the same error as above.

Tried aliasing the npm prefix - didn’t work as well.

If you are on windows, re-installing IIS on my solved the problem for me.

first run sudo su (as a root/administrator) and run npm install -g typescript as a root/administrator y… worked for me

@hajimurtaza : This issue seems to come when changes are made to package.json file without npm knowing about it. Just do a plain npm install. Then install your module again. It should work.

You’re wrong there. This issue occurs when VSCode / VSCode Insiders is open in the project folder and you’re trying an npm install.

There is no one specific scenario that is triggering this issue. It happens for different reasons for different people: from VSCode & other apps being open, from npm installation ordering details, or from permissions settings. Some problems can be resolved by closing or changing something, but some are deeply rooted in the issue.

Updated the answer.

@hajimurtaza : This issue seems to come when changes are made to package.json file without npm knowing about it. Just do a plain npm install. Then install your module again. It should work.

You’re wrong there. This issue occurs when VSCode / VSCode Insiders is open in the project folder and you’re trying an npm install.

There is no one specific scenario that is triggering this issue. It happens for different reasons for different people: from VSCode & other apps being open, from npm installation ordering details, or from permissions settings. Some problems can be resolved by closing or changing something, but some are deeply rooted in the issue.

This solved all my EACESS problem (on MAC):

sudo chown -R myusername: /Users/myusername/.npm/

npm config set unsafe-perm=true

@therealkenc can confirm it has to do with things being open elsewhere in your system, a pernicious and consistently annoying issue in Windows in general. At first I thought it was the ongoing node processes I had running from dev servers (I’d close them with task manager) but my latest test seems to indicate my text editor is the culprit, using Sublime Text 3. When I close it I can install modules normally.

Even adding node_modules directory to the folder_exclude_pattern and binary_file_patterns settings I still have the issue somehow. Perhaps Sublime’s project implementation is touching the directories still? Not sure. Atom doesn’t seem to have the same issue (but I decided against using it on Windows since it apparently can’t do multi-line find replace. I just can’t win[dows]!).

I’m running node 8.8.1 This is how I managed to get this to work:

  1. Start CMD.exe
  2. Type bash
  3. sudo npm install -g npm@5.3.0

With the normal bash i could not get this to work.

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.

Related: https://github.com/Microsoft/CommandLine-Documentation/issues/26

It seems to be an issue with symlinks

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

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就没有权限

I’ve come up with another possible solution npm set unsafe-perm true here is a link

I tried npm cache clean --force and then perform npm install and it works for me

I’m still using https://github.com/microsoft/WSL/issues/14#issuecomment-481028594 to work around this reliably. Don’t use VSCode myself.

@ilanc - did you sudo your npm install -g ...?

On windows 10 I was trying to update dependencies in my project with npm update --save and it was returning permission errors. I tried to start the console in administrator mode but it wasn’t solving the problem.

But with npm config set unsafe-perm=true it worked

following @vinifala suggestion (reverting npm v5.4.0 to 5.3.0) fixed my recent permissions issues on Windows 10 git bash. npm install -g npm@5.3.0

restart your bash. It seems there’s some permission timeout with forked(?) process.

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 "/."

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

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下也会报错

I was able to install a package by using sudo before npm and --force at the end.

Example: sudo npm install [package name] --save-dev --force

Following. This still seems like a problem (or maybe a problem again now that WSL2 is out).

不懂,太邪乎了

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

+1 it fixed the same issue for me after moving from dirictly installed nodejs to nodejs intalled from nvm. Thank you very much! You saved my hours!

Got the same issue today running npm install -g gatsby-cli on WSL 2.

npm config set unsafe-perm true and npm config set unsafe-perm=true couldn’t solve the problem.

I also didn’t had my VSC open.

sudo chown -R $(whoami) ~/.npm and sudo chown -R $(whoami) /usr/lib/node_modules got me further but didn’t solve the problem since gatsby wants to write into /usr/bin/gatsby.

Had to sudo it.

After following this this and this tutorials, I was able to install it without sudo.

Turns out it was just a matter of using nvm.

I’ve tried many other solutions and none of them has worked! This one did!!! Thanks

So I have to work on a machine with WSL v1 (no issues on v2). I can replicate it pretty easily by trying to install a package with VSCode. I believe there’s some sort of access limit or open handles.

Basically, I know VSCode is monitoring the folder I’m working in. If I install a package with VSCode is open, I’ll get EACCESS errors. If I close VSCode and install the packages over the Ubuntu bash, no errors.

So, to create this issue, I believe you just have to:

  • Initiate some sort of file system watcher on a folder (VSCode)
  • Create and delete files within the same folder very quickly (npm install)

I would think VSCode isn’t handling the file system changes faster than npm can create or delete them. That’s why this only happens sometimes and on some machines. The machine I’m working on currently is REALLY slow in general and I get this errors consistently if I try it installing a package with VSCode open. WSLv2 may have fixed this issue, or it’s just so much faster than WSLv1 that the it’s rare for the collision to occur.

I’m still having the problem even though I closed VSCode and used:

sudo npm install -g npm@latest

Got the same issue today running npm install -g gatsby-cli on WSL 2.

npm config set unsafe-perm true and npm config set unsafe-perm=true couldn’t solve the problem.

I also didn’t had my VSC open.

sudo chown -R $(whoami) ~/.npm and sudo chown -R $(whoami) /usr/lib/node_modules got me further but didn’t solve the problem since gatsby wants to write into /usr/bin/gatsby.

Had to sudo it.

After following this this and this tutorials, I was able to install it without sudo.

Turns out it was just a matter of using nvm.

This issue seems to come when changes are made to package.json file without npm knowing about it. Just do a plain npm install. Then install your module again. It should work. This is one of the scenarios that worked for me. There might be other issues causing similar problems.

^— Added some discussion in #1529 since it has the virtue of still being open.

I’ve successfully worked around this issue, letting for example cordova function correctly.

My fix is at https://github.com/fuzzyTew/nodejswslfix . The library must be compiled by hand and preloaded into npm’s environment, and it intercepts the problematic call, providing a quick fix to this issue.

npm would be able to resolve this issue by altering their concurrent behavior when moving multiple submodules out of the staging folder. I haven’t mentioned it to them or looked at the npm code, myself.

If your workspace has package-lock.json please remove and try again to npm i. It might work, since i had a same issue in MS.

@joeRob2468 thanks a bunch! Worked like a charm!

I fixed this issue using npm install -g npm@next I am working on a Windows 7 pro

My anti-virus was blocking the download of packages. Thanks ilyaigpetrov.

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.