nvm: command not found error [Solved]

avatar
Borislav Hadzhiev

Last updated: Jan 19, 2023
2 min

banner

# nvm: command not found error [Solved]

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.

NOTE: if you are on Windows, follow the instructions in my how to install NVM on Windows article.

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

shell
# ๐Ÿ‘‡๏ธ e.g. zsh echo $0

print-which-shell-is-used

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

shell
command -v nvm

check if nvm is installed

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

If you still get the 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.

shell
command -v nvm

If you still get 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

check which shell you are using

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

verify if nvm is installed

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.

Copyright ยฉ 2024 Borislav Hadzhiev