nvm
nvm copied to clipboard
Why does `nvm use` have to be run again when installing a package that exists on other version
[Sorry I removed the issue template because it didn't seem to fit this question]
Background I installed Node 20 using nvm and then installed a package on Node 20 that I already had on Node 18.
After running npm install -g <package> on Node 20, nvm was still targeting the Node 18 version of the package. Only after running nvm use 20 again did it target the Node 20 version.
Question I guess I would expect nvm to target the Node 20 version of the package immediately after npm installing it, but it stays on Node 18. Is this expected?
Logs
➜ photoshop-api git:(main) nvm use 20 <---- Switch to Node 20
Now using node v20.6.1 (npm v9.8.1)
➜ photoshop-api git:(main) aio --version
› Warning: @adobe/aio-cli update available from 9.3.0 to 9.4.0.
› Run npm install -g @adobe/aio-cli to update.
@adobe/aio-cli/9.3.0 darwin-arm64 node-v20.6.1
➜ photoshop-api git:(main) which aio
/Users/mgoberling/.nvm/versions/node/v18.17.1/bin/aio. <---- Still running Node 18 pkg, which is ok
➜ photoshop-api git:(main) npm i -g @adobe/aio-cli <---- Install package on Node 20
added 1401 packages in 31s
186 packages are looking for funding
run `npm fund` for details
➜ photoshop-api git:(main) which aio
/Users/mgoberling/.nvm/versions/node/v18.17.1/bin/aio <---- Nvm stays targeting Node 18 pkg
➜ photoshop-api git:(main) aio --version
› Warning: @adobe/aio-cli update available from 9.3.0 to 9.4.0.
› Run npm install -g @adobe/aio-cli to update.
@adobe/aio-cli/9.3.0 darwin-arm64 node-v20.6.1
➜ photoshop-api git:(main) nvm use 20 <---- Re-switch to Node 20
Now using node v20.6.1 (npm v9.8.1)
➜ photoshop-api git:(main) aio --version
@adobe/aio-cli/9.4.0 darwin-arm64 node-v20.6.1
➜ photoshop-api git:(main) which aio
/Users/mgoberling/.nvm/versions/node/v20.6.1/bin/aio <---- Nvm now targeting Node 20 pkg
Still running Node 18 pkg, which is ok
that’s not ok - when you’re using v20, packages installed on v18 should not be available. That suggests that your PATH is incorrect (which may have been revealed by some of the items in the template :-p )
Ah sorry about that. Thanks for the explanation
Okay, I'm using zsh and do have a couple things modifying my PATH in ~/.zshrc (Notably Homebrew, pnpm, and Bun.js)
I'll have to check my setup. It seems like every time I run nvm use, the new Node bin path is pre-pended to my PATH. If I nvm use a lot in a shell session my PATH grows very long, i.e:
PATH=/Users/mgoberling/.nvm/versions/node/v20.6.1/bin:/Users/mgoberling/.nvm/versions/node/v18.17.1/bin:
/Users/mgoberling/.nvm/versions/node/v16.20.2/bin:/Users/mgoberling/.nvm/versions/node/v20.6.1/bin:
/Users/mgoberling/.nvm/versions/node/v18.17.1/bin:/Users/mgoberling/.nvm/versions/node/v18.17.1/bin...
What version of nvm are you using? If not the latest, try updating.
Was previously running 0.39.1. Just updated to 0.39.5
Does that fix the PATH issue?
No unfortunately, the PATH var is still growing when I use nvm use. I'm thinking it's something in my .zshrc
Can you share it? If you’re using omz, please share the output of setopt as well.
I have the same issue