5

I see others have similar problems, but I have not found a solution.

Installation Steps

I performed the following to install nvm and node on Ubuntu / WSL2, as per these instructions:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

mkdir ~/.npm-global

npm config set prefix ~/.npm-global

cat >> ~/.bashrc <<EOF
export PATH="$HOME/.npm-global/bin:$PATH"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" 1>&2  # Loads nvm
EOF

nvm install node
$ which npm
/home/mslinn/.nvm/versions/node/v17.6.0/bin/npm

$ cat ~/.npmrc
fund=false
prefix=/home/mslinn/.npm-global

Now the Problem

$ source ~/.bashrc
Your user’s .npmrc file (${HOME}/.npmrc)
has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.
Run `nvm use --delete-prefix v17.6.0 --silent` to unset it.

Removing the prefix setting ignores the manually changed default directory for npm.

1 Answer 1

6

i had the same problem on mac os, an i solved it following these steps;

  1. installing nvm, (dont forget this command source ~/.nvm/nvm.sh)
  2. running the command 'nvm use --delete-prefix v16.4.0 --silent', in your case it's 'nvm use --delete-prefix v17.6.0 --silent' I hope this works for you
1
  • I don't think this answers the question. The problem is that we need to set the npm prefix manually, so we can run npm install -g <packagename> without sudo. Commented Aug 1, 2023 at 18:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.