NVM
Install
nvm is a version manager for node.js, designed to be installed per-user and invoked per-shell.
Install according to the Install & Update Script
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
The above script will add the following to ~/.zshrc
as I'm using Oh My ZSH:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Commands
# uninstall specific versions
❯ nvm uninstall 20.12.1
Uninstalled node v20.12.1
❯ nvm uninstall v20.14.0
Uninstalled node v20.14.0
# install latest LTS version
❯ nvm install --lts
Installing latest LTS version.
v22.12.0 is already installed.
Now using node v22.12.0 (npm v10.9.0)
# install specific versions
❯ nvm use 22
Now using node v22.12.0 (npm v10.9.0)
# set default alias to stable
❯ nvm alias default stable
default -> stable (-> v22.12.0)
.nvmrc
You can create a .nvmrc
file containing a node version number in the project root directory. Afterwards, nvm install
, nvm use
, nvm exec
, nvm run
, nvm which
will use the version specified in .nvmrc
file if no version is supplied.
❯ echo "v20.18.0" > .nvmrc
❯ nvm use
Found '/Users/ling/projects/test-project/.nvmrc' with version <v20.18.0>
Now using node v20.18.0 (npm v10.8.2)
# default to the lastest LTS version
❯ echo "lts/*" > .nvmrc