Skip to content

Instantly share code, notes, and snippets.

@j-ulrich
Last active February 17, 2026 12:09
Show Gist options
  • Select an option

  • Save j-ulrich/f35c461cf0b321bb35df0f90c6286a70 to your computer and use it in GitHub Desktop.

Select an option

Save j-ulrich/f35c461cf0b321bb35df0f90c6286a70 to your computer and use it in GitHub Desktop.
Integrating nvm (https://github.com/nvm-sh/nvm) and Visual Studio Code

Integrating nvm and Visual Studio Code

Respecting the .nvmrc in the integrated terminal

  1. Create a variant of the nvm-exec script which does not fail if there is no .nvmrc present. I called it nvm-exec-2 (see below).
  2. Place that script inside the .nvm directory in your user's home directory (~/.nvm) and make it executable:
    chmod +x ~/.nvm/nvm-exec-2
    
  3. Modify the "profiles" of the integrated terminal of VSCode in the settings.json. The keys of the corresponding settings are:
    • For the "automationProfile" - this is the terminal used when running "tasks" or when debugging:

      • terminal.integrated.automationProfile.osx
      • terminal.integrated.automationProfile.windows
      • terminal.integrated.automationProfile.linux

      Set those to:

      "terminal.integrated.automationProfile.<your OS>": { 
        "path": "/<path to your user home>/.nvm/nvm-exec-2",
        "args": ["<your shell>"],
      }

      so for example on my machine:

      "terminal.integrated.automationProfile.osx": { 
        "path": "/Users/julrich/.nvm/nvm-exec-2",
        "args": ["zsh"],
      }
    • For the regular terminal profiles:

      • terminal.integrated.profiles.osx
      • terminal.integrated.profiles.windows
      • terminal.integrated.profiles.linux

      There you can define multiple profiles in case you have multiple shells available on your machine. Again, use <path to user home>/.nvm/nvm-exec-2 as the path for the shell and provide the actual shell command via args. For example:

      "terminal.integrated.profiles.osx": {
        "zsh": {
          "path": "/Users/julrich/.nvm/nvm-exec-2",
          "args": ["zsh", "-l"],
        },
        "bash": {
          "path": "/Users/julrich/.nvm/nvm-exec-2",
          "args": ["bash", "-l"],
          "icon": "terminal-bash",
        },
      }
#!/usr/bin/env bash
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
unset NVM_CD_FLAGS
# shellcheck disable=SC1090,SC1091
\. "$DIR/nvm.sh" --no-use
if [ -n "$NODE_VERSION" ]; then
nvm use "$NODE_VERSION" > /dev/null || exit 127
else
nvm use >/dev/null 2>&1 || true
fi
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment