Skip to content

Instantly share code, notes, and snippets.

@RoboWeb
Last active April 13, 2022 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoboWeb/4886f81ae84a5ca913a18b0df2f547ec to your computer and use it in GitHub Desktop.
Save RoboWeb/4886f81ae84a5ca913a18b0df2f547ec to your computer and use it in GitHub Desktop.
Automatic node version switcher

Automatic Node version switcher

Ubuntu & Visual Studio Code

Requirements:

  • nvm must be installed on your system
  • you should have a .nvmrc file in root folder of the project
  • install manually the version of Node referred in .nvmrc with nvm install

Configuration:

in ~/.bashrc find lines with:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

change it to:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

if [ -f ".nvmrc" ]; then
  nvm use > /dev/null
else
  nvm use default > /dev/null
fi

In project folder add file .nvmrc

Example of .nvmrc file:

v16.14.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment