nvm icon indicating copy to clipboard operation
nvm copied to clipboard

Getting error on "nvm install-latest-npm"

Open K2ouMais opened this issue 5 years ago • 24 comments

Hello everyone,

I am getting an error when trying to install the latest npm.

Am I doing something wrong?

nvm

K2ouMais avatar Nov 28 '20 19:11 K2ouMais

The implication is that you don’t have owner permissions on your $NVM_DIR. Can you chown/chmod it until that’s fixed?

ljharb avatar Nov 29 '20 03:11 ljharb

diluka@Diluka-Z7:~$ chown -R diluka:diluka $NVM_DIR
diluka@Diluka-Z7:~$ ll $NVM_DIR
总用量 208
drwxr-xr-x 1 diluka diluka    512 7月  23 09:50 ./
drwxr-xr-x 1 diluka diluka    512 12月  3 17:31 ../
drwxr-xr-x 1 diluka diluka    512 7月  23 09:50 alias/
-rw-r--r-- 1 diluka diluka   2122 7月  23 09:39 bash_completion
drwxr-xr-x 1 diluka diluka    512 7月  23 09:42 .cache/
-rw-r--r-- 1 diluka diluka   1057 7月  23 09:39 CONTRIBUTING.md
-rw-r--r-- 1 diluka diluka   4043 7月  23 09:39 Dockerfile
-rw-r--r-- 1 diluka diluka    140 7月  23 09:39 .dockerignore
-rw-r--r-- 1 diluka diluka    416 7月  23 09:39 .editorconfig
drwxr-xr-x 1 diluka diluka    512 7月  23 09:39 .git/
-rw-r--r-- 1 diluka diluka      9 7月  23 09:39 .gitattributes
drwxr-xr-x 1 diluka diluka    512 7月  23 09:39 .github/
-rw-r--r-- 1 diluka diluka    253 7月  23 09:39 .gitignore
-rwxr-xr-x 1 diluka diluka  13527 7月  23 09:39 install.sh*
-rw-r--r-- 1 diluka diluka   1113 7月  23 09:39 LICENSE.md
-rw-r--r-- 1 diluka diluka     51 7月  23 09:39 .mailmap
-rw-r--r-- 1 diluka diluka   5364 7月  23 09:39 Makefile
-rw-r--r-- 1 diluka diluka     19 7月  23 09:39 .npmrc
-rwxr-xr-x 1 diluka diluka    344 7月  23 09:39 nvm-exec*
-rw-r--r-- 1 diluka diluka 115357 7月  23 09:39 nvm.sh
-rw-r--r-- 1 diluka diluka   2004 7月  23 09:39 package.json
-rw-r--r-- 1 diluka diluka  31814 7月  23 09:39 README.md
-rw-r--r-- 1 diluka diluka    882 7月  23 09:39 ROADMAP.md
drwxr-xr-x 1 diluka diluka    512 7月  23 09:39 test/
-rw-r--r-- 1 diluka diluka   4186 7月  23 09:39 .travis.yml
-rwxr-xr-x 1 diluka diluka   2364 7月  23 09:39 update_test_mocks.sh*
drwxr-xr-x 1 diluka diluka    512 7月  23 09:50 versions/
diluka@Diluka-Z7:~$ nvm install-latest-npm
Attempting to upgrade to the latest working version of npm...
* Installing latest `npm`; if this does not work on your node version, please report a bug!
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/npm-52a5d73a/node_modules/yargs-parser
npm ERR! dest /home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/yargs-parser-88a15fdd
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/npm-52a5d73a/node_modules/yargs-parser' -> '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/yargs-parser-88a15fdd'
npm ERR!  [OperationalError: EACCES: permission denied, rename '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/npm-52a5d73a/node_modules/yargs-parser' -> '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/yargs-parser-88a15fdd'] {
npm ERR!   cause: [Error: EACCES: permission denied, rename '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/npm-52a5d73a/node_modules/yargs-parser' -> '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/yargs-parser-88a15fdd'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'rename',
npm ERR!     path: '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/npm-52a5d73a/node_modules/yargs-parser',
npm ERR!     dest: '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/yargs-parser-88a15fdd'
npm ERR!   },
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/npm-52a5d73a/node_modules/yargs-parser',
npm ERR!   dest: '/home/diluka/.nvm/versions/node/v12.20.0/lib/node_modules/.staging/yargs-parser-88a15fdd'
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/diluka/.npm/_logs/2020-12-08T01_19_54_219Z-debug.log
* npm upgraded to: v6.14.8

Diluka avatar Dec 08 '20 01:12 Diluka

The implication is that you don’t have owner permissions on your $NVM_DIR. Can you chown/chmod it until that’s fixed?

How do I change the ownership of $NVM_DIR? Change the ownership of .nvm?

lzkids avatar Mar 14 '21 10:03 lzkids

@lzkids yes, using chown and/or chmod.

ljharb avatar Mar 14 '21 17:03 ljharb

@ljharb I tried, but it still didn't work. I upgraded wsl to wsl2 and it updated npm successfully. I don't know why? Very strange.

lzkids avatar Mar 15 '21 07:03 lzkids

My setup: Using WSL(1) with shell zsh on Win10, using Ubuntu 20.04.2 lts.

  • Installed NVM via cloning repo in root directory. This called the latest version to the date
  • Also installed succesfully node lts (as to the date)
  • npm and npx are installed.

Problem: npm -v and npx -v reveal outdated versions - older than the lts reported. I would like to update them both, but I can't change to WSL2 like @ljharb and I know I want to keep my npm/npx versions under nvm, without istallling them globally.

What have I tried:

  • npm install npm runs successfully, but when I check npm -v it is the same (old) version.
  • nvm install-latest-npm and/or npm install -g npm reveal EACCES error same as revealed by OP.
  • sudo chown -R $(whoami) ~/.nvm did not solve the EACCESS error.

Is there any possible solution?

Dilogritando avatar Aug 11 '21 23:08 Dilogritando

@Dilogritando what does npm root -g and which node and which npm print out?

ljharb avatar Aug 12 '21 06:08 ljharb

When I do npm root -g this is the output:

/home/lithya/.nvm/versions/node/v14.17.5/lib/node_modules

When I do which node this is the output:

/home/lithya/.nvm/versions/node/v14.17.5/bin/node

When I do which npm this is the output:

/home/lithya/.nvm/versions/node/v14.17.5/bin/npm

image

Dilogritando avatar Aug 12 '21 16:08 Dilogritando

The EACCESS error is strange then, if you do in fact fully own ~/.nvm (not just chown but also chmod)

ljharb avatar Aug 12 '21 16:08 ljharb

Not quite sure as to what value of chmod I should give to which directory/file.

  • Ran chmod -R 777 .nvm and sudo chmod -R 777 .nvm from root -still EACCES error.
  • Ran chmod -R 775 .nvm and sudo chmod -R 775 .nvm from root -still EACCES error.

Dilogritando avatar Aug 12 '21 18:08 Dilogritando

nah those should work.

what does /home/lithya/.nvm/versions/node/v14.17.5/bin/npm -v print out?

ljharb avatar Aug 12 '21 21:08 ljharb

6.14.14...

If it wasn't for the 100+ vulnerabilities I would have given up, honestly. I tried updating the dependencies manually (audit fix doesn't work due to he same error)... There has to be something I can do.

Dilogritando avatar Aug 13 '21 15:08 Dilogritando

and if you run npm install -g npm?

ljharb avatar Aug 13 '21 16:08 ljharb

Running npm install -g npm from inside the project, or running it from root:

image

Running it with sudo from either pwd simply returns sudo: npm: command not found

Dilogritando avatar Aug 13 '21 16:08 Dilogritando

You definitely don’t need and shouldn’t ever use sudo with nvm.

It’s likely that this is a bug in WSL 1, and that nothing can fix it short of upgrading to WSL2.

ljharb avatar Aug 13 '21 20:08 ljharb

@ljharb I also have this bug and I am on WSL v1. If I upgrade to version 2, will my files on my current WSL version be lost? Could this upgrade cause issues?

AJLandry1000000000 avatar Feb 09 '22 00:02 AJLandry1000000000

@AJLandry1000000000 i have no idea; i don't use WSL. I assume that you wouldn't lose any files, though.

ljharb avatar Feb 09 '22 00:02 ljharb

I have tried all the above steps and am still getting the issue image I see on the NPM docs website image I do not remember where I downloaded node or npm originally, but I think this could be related. Beyond this I have no idea where to go with this issue. I also cannot upgrade to WSL v2 as my company specifically uses WSL v1...

AJLandry1000000000 avatar Feb 09 '22 05:02 AJLandry1000000000

That particular error suggests you used sudo npm install -g at some point, and permissions are messed up. You should fully own everything inside $NVM_DIR.

ljharb avatar Feb 09 '22 15:02 ljharb

I have run each of the following commands:

  • sudo chown -R austin:austin $NVM_DIR
  • chown -R austin:austin $NVM_DIR
  • sudo chmod -R 777 $NVM_DIR
  • chmod -R 777 $NVM_DIR

I own the directory and everything inside: image

I am still getting the same permission denied error. image 😥

AJLandry1000000000 avatar Feb 09 '22 22:02 AJLandry1000000000

hm, very strange. it might be an npm 7 bug just on Windows, or just on WSL1; also, node 13 is very very EOL.

ljharb avatar Feb 09 '22 22:02 ljharb

Running npm install -g npm from inside the project, or running it from root:

image

Running it with sudo from either pwd simply returns sudo: npm: command not found

So, coming back to this after some time because I realized what was causing this:

I hadn't taken into account that although I was running the terminal from inside my WSL, I was hosting my proyects inside the windows distro... So it was "fixed" by simply creating a new folder under my "root" using the terminal (mkdir ...) , and moving the project files there, then opening my IDE from the terminal (code .).

Sharing is caring.

Dilogritando avatar Feb 11 '22 00:02 Dilogritando

I had a similar permissions issue when trying to upgrade npm using nvm install-latest-npm. It turned out to be the result of a conflicting installation of npm installed from apt (and thus under ownership of root). Uninstalling the conflicting version with sudo apt remove npm, followed by reinstalling npm via nvm solved the issue for me.

Example using node v14. Substitute for whatever version of node you're using for your project.

sudo apt remove npm
nvm use 17                  # any version other than your desired version
nvm uninstall 14            # uninstall and reinstall your desired node version
nvm install 14
nvm install-latest-npm

Granted this was in WSL 2, Ubuntu 18.04, not WSL 1

BraxtonLowers avatar Mar 25 '22 15:03 BraxtonLowers

@BraxtonLowers apt should never be used to install node or npm, and npm should never be installed separately (except by npm itself), so that likely was your issue.

ljharb avatar Mar 25 '22 16:03 ljharb

@K2ouMais were you able to resolve the permissions issue?

ljharb avatar Dec 14 '22 22:12 ljharb

I have this same issue on WSL 1. No idea what to do about it unfortunately. There's so many hits that come back for similar errors via searches on google.

kczx3 avatar Dec 20 '22 15:12 kczx3

@kczx3 can you update to WSL2? i don't think WSL1 is fully POSIX-compliant

ljharb avatar Dec 20 '22 19:12 ljharb

Anyone care to share how they resolved this issue? Upgrading to WSL2 is not an option for me sadly.

gtim04 avatar Jan 21 '23 15:01 gtim04