Homebrew installs nvm but nvm can't be found afterwards?

MacosHomebrewOsx YosemiteOh My-ZshNvm

Macos Problem Overview


I'm using homebrew and oh-my-zsh on a fresh OSX 10.10.1 install. I got nvm via homebrew and then attempted to run it but says - zsh: command not found: nvm

Any idea what the problem is? I was able to install and use git just fine...

enter image description here

enter image description here


UPDATED 9/20/2019

As stated by more recent answers from DarkPurple141 and Elise van Looij. nvm doesn't appear to be compatible with homebrew. This is also stated in the official nvm-sh repo located here.

> 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. > > Note: If you're using zsh you can easily install nvm as a zsh plugin. > Install zsh-nvm and run nvm upgrade to upgrade.

The following steps should help:

  1. $ brew uninstall nvm

  2. $ brew cleanup (just for good measure)

  3. $ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

  4. Check that nvm was installed correctly by running $ command -v nvm.

    4.a If the response is anything other than $ nvm, add the following two lines to the ~/.bash-profile file: export NVM_DIR=~/.nvm source ~/.nvm/nvm.sh 4.b Restart your computer (you can try closing Terminal and restarting it first) 4.c $ command -v nvm should now return nvm`

  5. Now update Node.js with $ nvm install --lts

  6. Update npm: $ nvm install-latest-npm

  7. $ npm install --global mocha. Finally, success! Well, for me and I hope for you too.

Macos Solutions


Solution 1 - Macos

Did you follow the instructions listed in the caveats?

[~] brew info nvm
nvm: stable 0.20.0, HEAD
https://github.com/creationix/nvm
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nvm.rb
==> Caveats
Add the following to $HOME/.bashrc, $HOME/.zshrc, or your shell's
equivalent configuration file:

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

Node installs will be lost upon upgrading nvm. Add the following above
the source line to move install location and prevent this:

  export NVM_DIR=~/.nvm

Without the extra config it doesn't look like it will find NVM by default..

Solution 2 - Macos

There are TWO things you need to do. Follow the caveats shown after installing nvm via brew, and THEN you need to activate/reload the .bash_profile changes.

  1. Run brew install nvm
  2. Follow caveats shown in console, mine were as follows, yours MAY be different!:

> Add the following to ~/.bash_profile or your desired shell > configuration file: > > export NVM_DIR="$HOME/.nvm" > . "$(brew --prefix nvm)/nvm.sh"

  1. Run . ~/.bash_profile to apply the changes you made to your .bash_profile file

Solution 3 - Macos

I've spent a couple of hours going round and round on this issue, but I've come to the conclusion that DarkPurple141 is right: nvm just isn't compatible with Homebrew, as they state on their Github nvm-sh/nvm Node Version Manager. Homebrew will install nvm and everything looks fine, until one tries to get npm to install a module, Mocha in my case. That threw me right back to the dreaded error:

> ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

NOTE: On step 3, make sure to replace version with correct release.

The solution, on MacOS 10.14 Mojave, was:

  1. $ brew uninstall nvm

  2. $ brew cleanup (just for good measure)

  3. $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash

  4. Check that nvm was installed correctly by running $ command -v nvm.

    4.a If the response is anything other than $ nvm, add the following two lines to the ~/.bash-profile file: export NVM_DIR=~/.nvm source ~/.nvm/nvm.sh 4.b Restart your computer (you can try closing Terminal and restarting it first) 4.c $ command -v nvm should now return nvm`

  5. Now update Node.js with $ nvm install --lts

  6. Update npm: $ nvm install-latest-npm

  7. $ npm install --global mocha. Finally, success! Well, for me and I hope for you too.

Solution 4 - Macos

While the accepted answer does technically work, it's worth noting that Homebrew installation is not officially supported by the nvm package. The recommended way to avoid issues like those raised above is to apply either of the below methods of installation.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

# or wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

source: https://github.com/creationix/nvm

Solution 5 - Macos

To install nvm, brew install nvm

To run nvm after installation or just once, $(brew --prefix nvm)/nvm.sh

To run nvm everytime zsh opens

  1. nano ~/.zshrc
  2. Add this line source $(brew --prefix nvm)/nvm.sh

Solution 6 - Macos

The reason you would need to reload your bash profiles or any other bash files might be because the command nvm may not be a program but a function that is defined and can only be used if the corresponding bash file is sourced.

On a system that I checked

which nvm 

does not work but

nvm list

does. This means that you can use the word "nvm" to invoke something. That something isn't a program. In the current case, it is a function which can be verified by

typeset -F | grep -P ' nvm$'

which outputs

declare -F nvm

which means nvm is a function, whose body can be inspected by doing

type -F nvm

Solution 7 - Macos

One possibility if brew was used is that the nvm may be unlinked, especially if it was installed by another MAC OS user.

In this case, execute:

brew link nvm

Solution 8 - Macos

I'd like to add that nvm's location on github changed and the version bumped. The curl command now should be:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash

Solution 9 - Macos

if you happen to be using fish shell, consider https://github.com/jorgebucaran/nvm.fish

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDayanView Question on Stackoverflow
Solution 1 - MacosDoonView Answer on Stackoverflow
Solution 2 - Macosredfox05View Answer on Stackoverflow
Solution 3 - MacosElise van LooijView Answer on Stackoverflow
Solution 4 - MacosDarkPurple141View Answer on Stackoverflow
Solution 5 - MacosRicky DamView Answer on Stackoverflow
Solution 6 - MacosSaurabh HiraniView Answer on Stackoverflow
Solution 7 - MacosLindoélio LázaroView Answer on Stackoverflow
Solution 8 - MacosOnno van der ZeeView Answer on Stackoverflow
Solution 9 - MacostutuDajujuView Answer on Stackoverflow