Reputation: 3647
After installing nvm with brew, and running nvm
, it says nvm: command not found
How can I get the command to execute?
Upvotes: 116
Views: 158615
Reputation: 21
For me I had to add on my ~/.profile
AND ~/.zshrc
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
This has never happened before, now I can run:
nvm use 20
without needing this workaround:
source $(brew --prefix nvm)/nvm.sh && nvm use 20 --default
Upvotes: 1
Reputation: 3733
After running brew install nvm
Add the following lines into ~/.profile
or ~/.bashrc
or ~/.zshrc
in anyone of files
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d"
and then run
source ~/.<filename>
which reloads the bash configuration. So you don't need to logout and login to see the changes in the bash.
This should solve the problem.
Note: Close and reopen the other terminal tabs to see the changes.
Upvotes: 1
Reputation: 151
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 .bashrc/.zshrc.
Upvotes: 15
Reputation: 71
If you use brew --prefix nvm
you will get your nvm directory path, it may be different to the default in the brew instructions, e.g. /opt/homebrew/opt/nvm
You need to replace the path in the .zshrc export statement:
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d"
then source ~/.zshrc
Upvotes: 7
Reputation: 11
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
Upvotes: 1
Reputation: 6465
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
Upvotes: 3
Reputation: 3647
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.
Upvotes: 216
Reputation: 1359
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
Upvotes: 125
Reputation: 11
I had the same problem after running npm install
The following solution worked for me:
Run brew doctor
to find broken symlinks for NPM
Run brew cleanup
to clean them up
Upvotes: 1
Reputation: 6097
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?!!
Upvotes: 10