86

After installing nvm with brew, and running nvm, it says nvm: command not found

How can I get the command to execute?

user3207874
  • 2,815
  • 2
  • 13
  • 18

8 Answers8

166

There are two steps to installing nvm with brew.

First use brew to install the application:

brew install nvm

Then take a look at the brew info "caveats" section, to see what else you have to do:

brew info nvm

You might see something like (this can change!):

You should create NVM's working directory if it doesn't exist:

  mkdir ~/.nvm

Add the following to ~/.bash_profile or your desired shell
configuration file:

  export NVM_DIR="$HOME/.nvm"
  . "/usr/local/opt/nvm/nvm.sh"

If you do not have a ~/.bash_profile file, then you can simply create one.

Make sure to restart your terminal before trying to run the nvm command again.

user3207874
  • 2,815
  • 2
  • 13
  • 18
83

I followed @user3207874's answer, but it still wasn't working for me. I had to run this command after those steps:

source $(brew --prefix nvm)/nvm.sh
Aaditya Singh
  • 931
  • 6
  • 4
11

please run this command

source ~/.nvm/nvm.sh

Imran Rasheed
  • 825
  • 10
  • 25
10

From the docs:

Your system may not have a [.bash_profile file] where the command is set up. Simply create one with touch ~/.bash_profile and run the install script again

you might need to restart your terminal instance. Try opening a new tab/window in your terminal and retry.

Restarting worked for me...Why can't all bugs be so easy?!!

Kyle Pennell
  • 5,747
  • 4
  • 52
  • 75
8

Just adding some explanation for Aaditya's answer to explain why it works. I can't replay because I don't have enough reputation.

Basically there are 2 important steps to follow

Export NVM_DIR location. You need to create this folder if it doesn't exist first.

export NVM_DIR="$HOME/.nvm"

Second you need to source nvm's script. It is usually like this

. "/usr/local/opt/nvm/nvm.sh"

If the path on the second step does work it may be because the path is different in your device. One easy way to find its path is with the command

brew --prefix nvm

The output will be the path for the nvm installation directory in which the nvm.sh file resides. Setting the command inside $() will create a subshell to get that path. We can use it to source the nvm.sh script wherever it is located like this:

. $(brew --prefix nvm)/nvm.sh

Using that command is a replacement for . "/usr/local/opt/nvm/nvm.sh" in your .bash_profile.

1

I had the same problem after running npm install

The following solution worked for me:

  1. Run brew doctor to find broken symlinks for NPM

  2. Run brew cleanup to clean them up

1

Just adding some new info. The docs for nvm have this note:

Homebrew installation is not supported. If you have issues with homebrew-installed nvm, please brew uninstall it, and install it using the instructions below, before filing an issue.

So for anyone coming here, potentially uninstall via brew and install as per recommendation : https://github.com/nvm-sh/nvm

nevster
  • 6,271
  • 7
  • 35
  • 42
0

run

brew reinstall nvm

and then

You should create NVM's working directory if it doesn't exist: mkdir ~/.nvm

Add the following to your shell profile e.g. ~/.profile or ~/.zshrc:

export NVM_DIR="$HOME/.nvm" [ -s "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh" ] && . "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh" # This loads nvm [ -s "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm" ] && . "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion

ENOR
  • 1