Issue With NVM Node Version Across Terminals: Command Node Not Found

Murtuzaali Surti
Murtuzaali Surti

• 2 min read

If you use a unix based operating system like macOS or Linux, you might have encountered this issue with switching node versions with nvm - where if you do nvm use <version>, the version is switched correctly in the current terminal shell, but if you try to use node on a new terminal shell or in a different terminal, you get a command node not found error.

I recently experienced this issue myself, and will try to consolidate the fixes here in this post as a reference to my future self as well as for all of you folks.

First thing I did was, I checked the ~/.zprofile file on my system - for you it may be ~/.bash_profile or ~/.bashrc or ~/.zshrc depending on your shell - and then moved the following lines at the bottom of the file, so that no other application overrides them. For me, it was VS Code, which was overriding the PATH variable at the end of the file. - https://stackoverflow.com/a/47883587/17241798

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
# -- end of file

The second thing you should do is set the default alias of nvm to a node version which you would like to use by default. I set it to lts/* which is the latest long term support version of node. But before you do that, make sure you install the lts/* version by running (wrap lts/* in single quotes for zsh):

nvm install 'lts/*' # wrap lts/* in single quotes for zsh

CAUTION

If you don't have it installed, you might run into:

! WARNING: Version 'lts/*' does not exist. default -> lts/* (-> N/A)

And then, setting the default alias:

nvm alias default 'lts/*'

After that, when you switch to a different node version using nvm use, you can use the new version in the current terminal session (verify it by node -v), but on a new terminal instance, it will fallback to the default node version you just set using the default alias.

TLDR

  1. Go to your ~/.zprofile or ~/.bash_profile or ~/.bashrc or ~/.zshrc file, locate these nvm lines, and move them at the end of the file:
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
# -- end of file
  1. Install the lts/* node version by running:
nvm install 'lts/*' # wrap lts/* in single quotes for zsh
  1. Set the default alias of nvm to a node version which you would like to use by default.
nvm alias default 'lts/*'

If any of the above solutions don't work, try uninstalling nvm and any other node version you have pre-installed and then re-install nvm. That should fix the issue.


App Defaults 2025 - with some AI stuff

Previous