Fix “nvm: command not found” after installation

Load nvm into the shell you are actually running, check startup files, and handle noninteractive Docker or CI shells.

Best practices
Illustration of software development and testing

nvm is a shell function, not a standalone executable. Installation can put its files on disk without loading the function into your current session. Open a new terminal first. If nvm is still missing, check whether that shell's startup file loads nvm.sh.

Load nvm into the current shell

First, check the usual installation directory and look for startup configuration:

cat ~/.nvm/nvm.sh > /dev/null && echo "nvm files are installed"
grep -l NVM_DIR ~/.bashrc ~/.zshrc ~/.profile 2>/dev/null

If you installed into a custom location, use that path instead. $SHELL usually identifies your configured login shell, which may differ from the shell currently running. In Bash or zsh, inspect the current process with:

ps -p $$ -o comm=

Add the following to the startup file your shell actually reads, adjusting NVM_DIR if necessary:

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

The second line loads nvm; completion is optional. Reload the appropriate file, such as source ~/.zshrc for interactive zsh, then run nvm --version.

Match the symptom to the cause

Cause What to check
The current terminal predates installation Open a new terminal or load the configuration in this one
Setup was added to .bashrc, but you use zsh Put the loading lines in .zshrc
Shell customization skips the setup Check conditions and ordering in the startup file
An IDE, tmux, or script starts a different shell mode Check the actual startup files; noninteractive Bash normally does not read .bashrc
nvm was installed as root Install it for the user that will run it

Docker and CI shells

nvm can run in noninteractive shells, but those shells usually do not load interactive startup files. Explicitly source nvm.sh in the same shell that runs nvm, or follow nvm's Docker guidance for BASH_ENV. A fixed Node image or CI setup action is often simpler when the job needs only one runtime version.

Frequently asked questions

Why does command -v nvm return nothing when nvm.sh exists?

The file's presence does not mean your shell has sourced it. Run the loading lines individually and inspect any errors. If they work, investigate startup-file selection. Do not rely on $SHELL alone to identify the current shell.

Why must I source the file every time?

The loading code is probably in a file that the session does not read. Interactive zsh reads .zshrc, including interactive login sessions. Login zsh also reads .zprofile; interactive non-login Bash reads .bashrc, while login Bash reads the first available file among .bash_profile, .bash_login, and .profile. A Bash login file can explicitly source .bashrc. macOS Terminal commonly starts an interactive login zsh, for which .zshrc is an appropriate place to load nvm.

Can nvm be installed once for every user?

nvm is designed for per-user installation. Avoid a shared installation that mixes users' runtime state. For a server requiring one system-wide Node version, consider a system package or official binary installation instead.

References

Related reading

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting