[Fixed] command not found: nvm

The NVM is the acronym of the Node Version Manager and the name implies that this is used to manage the node versions. Different versions of the node can be installed and removed using the NVM. Sometimes, while using NVM, the users face the error “command not found: nvm”.

This blog will explore the reasons and propose the solution to handle the reasons. The post’s content is as follows:

Let’s dig into the cause.

Reason: NVM not Installed

The “command not found” error occurs when the system does not have the executables of the package being run. Let’s check the version of the nvm:

In Bash:

In Zsh:

The error “Command not found” shows that the nvm is not installed.

Solution 1: Install the NVM Package

To resolve the installation, we have to install the NVM on that Linux. To install the nvm package on Ubuntu, use the command:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

After downloading the shell script of the nvm, reload the “bashrc” file as displayed below:

$ source ~/.bashrc

Now, again check the installed version of the nvm:

$ nvm --version

The nvm package has been installed on the computer, and the error has vanished.

Solution 2: Add the Load Lines in Bash Script

If the error is still sustained, we have to make changes to the shell script. By default, when we download and update the installation script of the nvm, it adds up the load lines in the “.bashrc” file. But sometimes, it does not add these lines; we have to manually by opening the “.bashrc” file in the bash shell:

$ nano .bashrc

Now, at the end of the file, copy and paste these two lines:

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

Exit the nano text editor by saving the file with the shortcut “CTRL+S”. Again update the bashrc file with the source command:

$ source ~/.bashrc

Note: If you are using the zsh shell, you must make the above changes in the “.zshrc” file.

Conclusion

The “command not found: nvm” error appears when the NVm is not installed on the Linux system. To fix this error, you need to download the nvm installation script and then reload the “bashrc” file if you use bash. This post has demonstrated the reason and possible solutions to fix “command not found: nvm”.