How to Fix 'command not found: nvm' After Installing nvm

Introduction

When you install NVM (Node Version Manager) and find that your terminal still can't locate it, this error message command not found: nvm will show up. This tutorial will guide you through the process of resolving this issue.

Why You Might Get This Error

The NPM package manager has installed a version of Node.js on your machine without telling the shell (Terminal) that it's there. As a result, when you try to run a command for which NVM is needed, like nvm, the shell can't find it.

Troubleshooting Steps

This section outlines the steps to fix this issue.

  1. Check Your Installation:

Ensure your installation of nvm and node are up-to-date.

$ npm install -g nvm
  1. Reinstall Node.js:

Sometimes, reinstalling can fix issues with package managers not recognizing installed software correctly.

$ rm -rf ~/.nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
$ . $(brew --prefix nvm)/bin/nvm.sh
$ nvm install node
  1. Verify Node.js Installation:

Ensure you are using the correct version of Node.js.

$ node -v
v18.19.1
$ npm -v
9.2.0
  1. Check Your Shell Configuration File (~/.zshrc, ~/.bashrc, etc.):

Sometimes changes in your shell configuration file might cause issues with package installation paths. Replacing the path to Node.js in this file will help.

  1. Reinstall nvm:

If you want to completely remove and reinstall nvm:

$ rm -rf ~/.nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
$ . $(brew --prefix nvm)/bin/nvm.sh
  1. Install Node.js via nvm:

If you want to use nvm exclusively, make sure to install it this way.

Real Commands

Step 1: Check Installation:

$ npm -v
9.2.0

Step 2: Reinstall Node.js:

$ rm -rf ~/.nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
$ . $(brew --prefix nvm)/bin/nvm.sh
$ nvm install node

Step 3: Verify Installation:

$ node -v
v18.19.1
$ npm -v
9.2.0

Quick Answer

To fix 'command not found: nvm' after installing nvm, make sure you have installed nvm globally using npm install -g nvm. Then, re-install your preferred version of node via nvm install node.

Common Mistakes and Troubleshooting

Make sure to reinstall Node.js. The commands provided above should fix this issue.

If you have custom configurations for your shell, ensure that the path points to ~/.nvm/bin and not some other location where it might be installed.

Conclusion

By following these steps, you can easily resolve 'command not found: nvm' errors after installing NVM. This guide should help any developer or system administrator encounter similar issues with their Node.js setup.