Brew install nvm. nvm: command not found

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

How can I get the command to execute?

5 Answers

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.

5

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 
2

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?!!

0

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.

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like