Last updated: Jan 19, 2023
Reading timeยท2 min
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:
# ๐๏ธ 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:
# ๐๏ธ e.g. zsh echo $0
You can verify if nvm
was installed successfully by running the following
command:
command -v nvm
If nvm
was installed successfully, it should output "nvm".
Alternatively, try running the command that corresponds to your shell to source it.
# ๐๏ธ for bash source ~/.bashrc # ๐๏ธ for zsh source ~/.zshrc # ๐๏ธ for ksh . ~/.profile
And try to run command -v nvm
again.
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:
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
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:
# ๐๏ธ 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:
# ๐๏ธ 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:
command -v nvm
Or run the source command that corresponds to your 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.
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.