How to fix "command not found: nvm" in Node

Updated onbyAlan Morel
How to fix "command not found: nvm" in Node

When you install Node, it comes bundled with NVM, which is the Node Version Manager. It allows you to install multiple versions of Node and switch between them.

To check if you have NVM installed, run the following command:

BASH
nvm --version

Sometimes, when you run this command, you might get:

BASH
command not found: nvm

In this post, we'll learn how to fix this error in Node.

How to fix command not found: nvm

As mentioned before, to double-check that you have NVM installed, you can run the following command:

BASH
nvm --version

If it goes well, you should get back a version number, but if not, you might get command not found: nvm.

The reason for this is that NVM is not in your PATH.

To fix this, open up your /.bashrc file and add the following line:

BASH
export NVM_DIR="$HOME/.nvm"

This will set the NVM_DIR variable to the location of your NVM installation.

Now, let's load NVM:

BASH
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Finally, let's load NVM bash_completion:

BASH
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

If done properly, you should be able to run the following command:

BASH
nvm --version

And get back a version number.

How to open your bash file in Visual Studio Code

A recommended way to open your bash file is to use the code command. This command will open the file in Visual Studio Code.

All you need to do is pass it the path to your file.

To open your bash file, run the following command:

BASH
code ~/.bashrc

If you are using ZSH, you can run the following command:

BASH
code ~/.zshrc

Conclusion

In this post, we learned how to fix the command not found: nvm error in Node.

Simply add the aforementioned lines to your bash file and you should be good to go after you restart your terminal.

Thanks for reading!

To learn more about web development, founding a start-up, and bootstrapping a SaaS, follow me on X!
Copyright © 2017 - 2024 Sabe.io. All rights reserved. Made with ❤ in NY.