Upgrading npm to latest fails with permission error

(I am unsure if you are currently using nvm.)

The error message you included had .nvm in the path. Is that still the case?

How have you installed without using sudo? Are you using nvm?

What do these show:

npm prefix -g
command -v npm

Yes I’m using nvm. I installed it fresh using the curl command as described in the docs without sudo. The prefix is manged by nvm.

What are the permissions on the folder mentioned in the error message?

ls -ld /home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs

The .staging directory does not exist. It’s likely an ethereal directory used during the installation process.

$ ls -ld /home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs
ls: cannot access '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs': No such file or directory
~/.nvm/versions/node/v12.6.0/lib/node_modules$ ls -alh
total 0
drwxr-xr-x 1 user user 512 Jul  5 03:04 .
drwxr-xr-x 1 user user 512 Jul  3 13:47 ..
drwxr-xr-x 1 user user 512 Jul  3 13:47 npm
~/.nvm/versions/node/v12.6.0/lib$ ls -alh
total 0
drwxr-xr-x 1 user user 512 Jul  3 13:47 .
drwxrwxrwx 1 user user 512 Jul  4 14:01 ..
drwxr-xr-x 1 user user 512 Jul  5 03:04 node_modules

There doesn’t appear to be any issue with the unix permissions on these folders.

(Drat. I am out of questions and suggestions!)

I have exactly the same problem…
If someone can help :slight_smile:

Ok. I fix it with this doc: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Hey, this fix requires you to change the prefix and that isn’t compatible with nvm. It’s not really a solution to this issue then.

Are there any known solutions that would work with nvm?

I have seen issues with past versions where the .staging directory tries to move before it’s ready. It’s weird that you’re getting EACCES errors when all the ownership seems fine.

Do you have a virus scanner or anything else that might be locking the directory?

The “custom prefix in $HOME” solution really is what nvm does by default, so yeah, that’s not it.

Out of curiosity:

  • What happens when you run it with sudo?
  • Are there root-owned files in your cache? find $(npm get cache) -uid 0

Another possible avenue to explore:

git clone https://github.com/npm/cli npm
cd ./npm
git checkout -t origin/release-next # or origin/latest for npm@latest
make install

That’ll build all the docs and then pack it into a local tarball and install that globally. At least then you’re using the latest npm to install it, so if it’s an issue that’s been fixed, you won’t see the problem.

Thank you for your response!

I ran find $(npm get cache) -uid 0 but it finished without a result.

Using sudo won’t work as nvm only runs as the global user. It can’t find the command npm.

For building npm locally – won’t that interfere with nvm? I’ve started the build with the commands you’ve proposed.

It shouldn’t interfere any more than just installing npm globally would.

When you run make install, npm infers the global prefix from the location of the node binary running it, so it ought to drop it in the same place that npm i -g npm would. (In fact, what it’s actually doing is just running node . pack and then node . install <tarball generated> to install the tarball, instead of using the one downloaded from the registry.)

The relevant variable in make install is that you’d be installing npm using the latest npm, rather than using whatever version nvm gave you (which might be the source of the bug). If make install has the same issue, than it’s a current bug.

make install is presenting the same issue:

npm notice ssri
npm notice opener
npm notice path-is-inside
npm notice sorted-object
npm notice === Tarball Details ===
npm notice name:          npm
npm notice version:       6.10.1
npm notice filename:      npm-6.10.1.tgz
npm notice package size:  4.7 MB
npm notice unpacked size: 18.7 MB
npm notice shasum:        be7ced3483f4e720a285a026f9c2bdde06d685d6
npm notice integrity:     sha512-a2mvSHffQjEXS[...]q11T/xOUcS2vw==
npm notice bundled deps:  122
npm notice bundled files: 3629
npm notice own files:     475
npm notice total files:   4104
npm notice
node bin/npm-cli.js install -g -f  npm-6.10.1.tgz
npm WARN using --force I sure hope you know what you are doing.
npm ERR! path /home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename
npm ERR! Error: EACCES: permission denied, rename '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs' -> '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/yargs-81a9147b'
npm ERR!  [OperationalError: EACCES: permission denied, rename '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs' -> '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/yargs-81a9147b'] {
npm ERR!   cause: [Error: EACCES: permission denied, rename '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs' -> '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/yargs-81a9147b'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'rename',
npm ERR!     path: '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs',
npm ERR!     dest: '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/yargs-81a9147b'
npm ERR!   },
npm ERR!   stack: "Error: EACCES: permission denied, rename '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs' -> '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/yargs-81a9147b'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/npm-60bf52cc/node_modules/yargs',
npm ERR!   dest: '/home/user/.nvm/versions/node/v12.6.0/lib/node_modules/.staging/yargs-81a9147b'
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 (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2019-07-17T17_54_57_138Z-debug.log
Makefile:60: recipe for target 'install' failed
make: *** [install] Error 243

Oh, another thing that occurs to me: you’re running under WSL. Is your home directory mounted from the Windows environment? That might be making things weird.

If so, does it work if you do this?

# first, remove the NVM bits from ~/.profile, ~/.bash_profile, and/or ~/.bashrc
unset NVM_DIR
unset NVM_BIN

sudo mkdir -p /newhome/.config
sudo chown -R $USER:$GROUP /newhome
export XDG_CONFIG_HOME=/newhome/.config
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
which npm # verify that it's finding it in /newhome/.config/versions/node/...
npm i -g npm@next

The home directory is not mounted but just acts as a regular unix directory in /home/user.

Regardless I installed nvm under /newhome/.config.

$ which npm

And the error persists.

Error: EACCES: permission denied, rename '/newhome/.config/versions/node/v12.6.0/lib/node_modules/.staging/npm-3c4f3ca2/node_modules/yargs' -> '/newhome/.config/versions/node/v12.6.0/lib/node_modules/.staging/yargs-c80cc2b0'

I am hoping to do an upgrade to WSL2 soon but I’m waiting for the current limitations in networking to be resolved.


I’m encountering the same kind of error, regarding the rename command and I’m using WSL as well. any updates on this ?

Same issue, Win10 and WSL, rename + EACCESS error.

Update: Maybe this is related https://github.com/microsoft/WSL/issues/14

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.