Solve - nvm: command not found error

avatar

Borislav Hadzhiev

Last updated: Mar 15, 2022

banner

Photo from Unsplash

'Solve - nvm: command not found error' #

To solve the error "nvm: command not found", run the curl or wget commands to download and run the installation script, close your terminal and open a new one. The script from the commands clones the nvm repository to ~/.nvm and loads nvm on system start.

Open your terminal and run one of the following commands:

shell
# 👇️ using curl curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash # 👇️ using wget wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Running either of the commands above will download the nvm script and run it.

The script clones the nvm repository to ~/.nvm and tries to add 2 lines of code to the correct profile (~/.bash_profile, ~/.zshrc, ~/.profile, ~/.bashrc) to load nvm on system boot.

You can see which shell you are using with the following command:

shell
# 👇️ e.g. zsh echo $0

You can verify if nvm was installed successfully by running the following command:

shell
command -v nvm

If nvm was installed successfully, it should output "nvm".

If you still get the "nvm: command not found error", try to close your terminal, open a new one and try running the command again.

Alternatively, try running the command that corresponds to your shell to source it.

shell
# 👇️ for bash source ~/.bashrc # 👇️ for zsh source ~/.zshrc # 👇️ for ksh . ~/.profile

And try to run command -v nvm again.

If you're still getting the error, open the file that corresponds to your shell (~/.bash_profile, ~/.zshrc, ~/.profile, ~/.bashrc) and make sure it contains the following 2 lines:

shell
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
The second line loads nvm on system boot.

If your shell doesn't have a corresponding config file, e.g. your shell is zsh, but you don't have a ~/.zshrc file, you have to create one by running touch ~/.zshrc.

You can see which shell you are using with the following command:

shell
# 👇️ e.g. zsh echo $0

If you had to create a config file for your shell, you have to re-run the installation script again:

shell
# 👇️ using curl curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash # 👇️ using wget wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Try to close your terminal, open a new one and verify whether nvm is installed:

shell
command -v nvm

Or run the source command that corresponds to your shell.

shell
# 👇️ for bash source ~/.bashrc # 👇️ for zsh source ~/.zshrc # 👇️ for ksh . ~/.profile # 👇️ verify nvm installed command -v nvm

If running command -v nvm still returns nvm: command not found, check out the troubleshooting section in the nvm repository.

The nvm package works on Unix, macOS and Windows WSL (Windows Subsystem for Linux) platforms. It should also work with GitBash (MSYS) or Cygwin.

If you're on Windows, you can try using nvm for windows, which is the most popular package for managing multiple installations of Node.js on Windows.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.