nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
80.04k stars 8.01k forks source link

Error EACCES -13 when using npm globally #2176

Open MithicSpirit opened 4 years ago

MithicSpirit commented 4 years ago

Operating system and version:

Ubuntu 18.04.4 (WSL)

nvm debug output:

```sh $ nvm debug nvm --version: v0.35.3 $SHELL: /usr/bin/zsh $SHLVL: 1 ${HOME}: /home/mithic ${NVM_DIR}: '${HOME}/.nvm' ${PATH}: ${NVM_DIR}/versions/node/v12.16.1/bin:${HOME}/.local/texlive/2019/bin/x86_64-linux:${HOME}/.local/bin:${HOME}/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/Python38/Scripts/:/mnt/c/Program Files/Python38/:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/Program Files/nodejs:/mnt/c/Program Files/AMD/StoreMI/ECmd:/mnt/c/Program Files (x86)/LilyPond/usr/bin:/mnt/c/Users/rpc01/AppData/Local/Programs/Python/Python37-32:/mnt/c/Program Files (x86)/texlive/2019/bin/win32:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Hunspell/src/tools:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Users/rpc01/.windows-build-tools/python27/:/mnt/c/Users/rpc01/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/rpc01/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/rpc01/AppData/Local/Programs/Microsoft VS Code/bin $PREFIX: '' ${NPM_CONFIG_PREFIX}: '' $NVM_NODEJS_ORG_MIRROR: '' $NVM_IOJS_ORG_MIRROR: '' shell version: 'zsh 5.4.2 (x86_64-ubuntu-linux-gnu)' uname -a: 'Linux 4.4.0-19041-Microsoft #1-Microsoft Fri Dec 06 14:06:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux' OS version: Ubuntu 18.04.4 LTS curl: /usr/bin/curl, curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3 wget: /usr/bin/wget, GNU Wget 1.19.4 built on linux-gnu. git: /usr/bin/git, git version 2.17.1 ls: cannot access 'grep:': No such file or directory grep: grep: aliased to grep --color (grep --color), grep (GNU grep) 3.1 awk: /usr/bin/awk, GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2) sed: /bin/sed, sed (GNU sed) 4.4 cut: /usr/bin/cut, cut (GNU coreutils) 8.28 basename: /usr/bin/basename, basename (GNU coreutils) 8.28 ls: cannot access 'rm:': No such file or directory rm: rm: aliased to rm -i (rm -i), rm (GNU coreutils) 8.28 ls: cannot access 'mkdir:': No such file or directory mkdir: mkdir: aliased to nocorrect mkdir (nocorrect mkdir), mkdir (GNU coreutils) 8.28 xargs: /usr/bin/xargs, xargs (GNU findutils) 4.7.0-git nvm current: v12.16.1 which node: ${NVM_DIR}/versions/node/v12.16.1/bin/node which iojs: iojs not found which npm: ${NVM_DIR}/versions/node/v12.16.1/bin/npm npm config get prefix: ${NVM_DIR}/versions/node/v12.16.1 npm root -g: ${NVM_DIR}/versions/node/v12.16.1/lib/node_modules ```

nvm ls output:

```sh $ nvm ls -> v12.16.1 default -> lts/* (-> v12.16.1) node -> stable (-> v12.16.1) (default) stable -> 12.16 (-> v12.16.1) (default) iojs -> N/A (default) unstable -> N/A (default) lts/* -> lts/erbium (-> v12.16.1) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.17.0 (-> N/A) lts/dubnium -> v10.19.0 (-> N/A) lts/erbium -> v12.16.1 ```

How did you install nvm?

Install and update script from readme: wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

What steps did you perform?

I only ran npm -g upgrade

What happened?

I got the EACCES -13 error:

```sh $ npm -g upgrade npm ERR! code EACCES npm ERR! syscall rename npm ERR! path /home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/npm-d9b9c5ef/node_modules/yargs npm ERR! dest /home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/yargs-b6502a51 npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, rename '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/npm-d9b9c5ef/node_modules/yargs' -> '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/yargs-b6502a51' npm ERR! [OperationalError: EACCES: permission denied, rename '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/npm-d9b9c5ef/node_modules/yargs' -> '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/yargs-b6502a51'] { npm ERR! cause: [Error: EACCES: permission denied, rename '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/npm-d9b9c5ef/node_modules/yargs' -> '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/yargs-b6502a51'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'rename', npm ERR! path: '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/npm-d9b9c5ef/node_modules/yargs', npm ERR! dest: '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/yargs-b6502a51' npm ERR! }, npm ERR! stack: "Error: EACCES: permission denied, rename '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/npm-d9b9c5ef/node_modules/yargs' -> '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/yargs-b6502a51'", npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'rename', npm ERR! path: '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/npm-d9b9c5ef/node_modules/yargs', npm ERR! dest: '/home/mithic/.nvm/versions/node/v12.16.1/lib/node_modules/.staging/yargs-b6502a51' 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/mithic/.npm/_logs/2020-03-09T18_06_31_294Z-debug.log ```

What did you expect to happen?

I expected it to upgrade any packages that might be out of date, and not throw any errors, especially given that the reason I began using nvm was to solve this very issue (as npm docs explain here).

Is there anything in any of your profile files that modifies the PATH?

Yes: export PATH="/home/mithic/.local/texlive/2019/bin/x86_64-linux:$HOME/.local/bin:$HOME/bin:/usr/local/bin:$PATH"

Additionally, since I am using WSL it also uses the PATH from windows (the full path can be seen in the nvm debug output above). I do not believe this to be part of the issue as all of the directories seem to be the correct one.

ljharb commented 4 years ago

npm update -g (the actual command you ran) doesn't actually work for global packages the way you think it should (i think there's an open issue on npm about it). It's best to use npm install -g, for each package, explicitly (npm ls -g --depth=0 to list them).

Separately, the error seems like it's a bug in WSL - I'd suggest filing an issue there (https://github.com/microsoft/WSL/issues/new/choose), or perhaps in npm. Once nvm has installed and activated a node version, it's not really involved after that :-)