Skip to content

previously used node version is not removed from the PATH variable #3561

Open

Description

@0xorial

Operating system and version:

macOS

nvm debug output:

nvm --version: v0.40.2
$TERM_PROGRAM: vscode
$SHELL: /bin/zsh
$SHLVL: 1
whoami: 'user'
${HOME}: /Users/user
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${NVM_DIR}/versions/node/v20.19.0/bin:${NVM_DIR}/versions/node/v22.14.0/bin:${NVM_DIR}/versions/node/v22.14.0/bin:${NVM_DIR}/versions/node/v20.19.0/bin:${HOME}/.pixi/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/share/dotnet:~/.dotnet/tools:${HOME}/.pixi/bin:${HOME}/Library/pnpm:${NVM_DIR}/versions/node/v18.20.6/bin:${HOME}/.cargo/bin:${HOME}/Library/Application Support/JetBrains/Toolbox/scripts:${HOME}/.spicetify:${HOME}/Library/Application Support/JetBrains/Toolbox/scripts:${HOME}/.spicetify
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.9 (arm64-apple-darwin24.0)'
uname -a: 'Darwin 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:24 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6030 arm64'
checksum binary: 'sha256sum'
OS version: macOS 15.3.2 24D81
awk: /usr/bin/awk, awk version 20200816
curl: /usr/bin/curl, curl 8.7.1 (x86_64-apple-darwin24.0) libcurl/8.7.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.12 nghttp2/1.63.0
wget: /opt/homebrew/bin/wget, GNU Wget 1.25.0 built on darwin24.1.0.
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /usr/bin/git, git version 2.39.5 (Apple Git-154)
grep: /usr/bin/grep, grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
nvm current: v20.19.0
which node: ${NVM_DIR}/versions/node/v20.19.0/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v20.19.0/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v20.19.0
npm root -g: ${NVM_DIR}/versions/node/v20.19.0/lib/node_modules

nvm ls output:

Details
->     v20.19.0
       v22.14.0
default -> 20 (-> v20.19.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v22.14.0) (default)
stable -> 22.14 (-> v22.14.0) (default)
lts/* -> lts/jod (-> v22.14.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.20.8 (-> N/A)
lts/iron -> v20.19.0
lts/jod -> v22.14.0

How did you install nvm?

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

What steps did you perform?

nvm install 20
nvm install 22
nvm use 20

What happened?

PATH variable is polluted with bin paths of the previously used node.

What did you expect to happen?

PATH to only contain selected node

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

no

Activity

  1. ljharb commented on Apr 8, 2025

    @ljharb
    Member

    Interesting - there's explicit code in nvm to purge the PATH of nvm entries before using a new version. What happens if you manually clear out the nvm stuff from the PATH, and then nvm use 20?

  2. 0xorial commented on Apr 8, 2025

    @0xorial
    Author

    then it's added once. I also noticed that it only happens in vscode terminal, but not in the system terminal

  3. ljharb commented on Apr 8, 2025

    @ljharb
    Member

    oh interesting. so you can't reproduce the problem in a real terminal, but you can consistently reproduce it in vscode's terminal?

  4. 0xorial commented on Apr 8, 2025

    @0xorial
    Author

    exactly!

  5. xianghongai commented on Apr 28, 2025

    @xianghongai

    nvm alias default v22.15.0
    nvm use default

    After restarting the terminal: v16.20.2

  6. ljharb commented on Apr 28, 2025

    @ljharb
    Member

    @xianghongai same problem for you? works on the real terminal, not on vscode's?

  7. ljharb commented on Apr 28, 2025

    @ljharb
    Member

    Sounds like it's vscode-specific behavior, then, that nvm wouldn't be able to fix.

  8. atox996 commented on Apr 30, 2025

    @atox996

    nvm alias default v22.15.0 nvm use default

    After restarting the terminal: v16.20.2

    I have the same problem

  9. mattyforth commented on May 12, 2025

    @mattyforth

    Just chiming in, I can also reproduce this issue on a real terminal, not VSCode (Ghosstty terminal to be exact).

    Steps:

    1. New terminal (node v16.20.2)
    2. nvm use default (set to lts/* - 22.14.0)
    3. node --version = 22.14.0
    4. nvm debug
    ${PATH}: ${NVM_DIR}/versions/node/v22.14.0/bin:${HOME}/.config/bin:${HOME}/.pyenv/shims:${NVM_DIR}/versions/node/v16.20.2/bin:${HOME}/.config/herd-lite/bin:/usr/local/bin:/usr/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:${HOME}/bin:${HOME}/.config/phpmon/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:${HOME}/.config/bin:${NVM_DIR}/versions/node/v16.20.2/bin:${HOME}/.config/herd-lite/bin:/Applications/iTerm.app/Contents/Resources/utilities:${HOME}/.composer/vendor/bin:${HOME}/Library/Application Support/JetBrains/Toolbox/scripts:/Applications/Ghostty.app/Contents/MacOS
    

    Note the path still contains reference to v16.20.2 node, which is what was set before using nvm use default.

    Also as @xianghongai described, new terminals aren't respecting the default alias that I have set. All terminals start with v16.20.2 by default. Once nvm use default is ran, node --version correctly returns v22, but only in that terminal session.

  10. SQDR2 commented on Jun 9, 2025

    @SQDR2

    Image

    and new a terminal run node -v

    Image

    So I failed to switch the node version using nvm, only the current terminal switched successfully

  11. xianghongai commented on Dec 10, 2025

    @xianghongai

    real terminal

    real terminal + vscode terminal

  12. gitenstuff commented on Jan 22, 2026

    @gitenstuff

    same problem. i noticed that if after gnome login, the first thing that i do is nvm alias default then makes default current. but if the first thing i do after login is nvm use some other version, then that version is sticky across sessions, and terminals.

  13. added a commit that references this issue on Oct 14, 2026
    57a0301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions