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.
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 2Your 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?!!
0Just 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:
Run
brew doctorto find broken symlinks for NPMRun
brew cleanupto clean them up