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

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...
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:
$ brew uninstall nvm
$ brew cleanup (just for good measure)
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
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`
Now update Node.js with $ nvm install --lts
Update npm: $ nvm install-latest-npm
$ npm install --global mocha. Finally, success! Well, for me and I hope for you too.

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..

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.
Run brew install nvm
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"
Run . ~/.bash_profile to apply the changes you made to your .bash_profile file

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:
$ brew uninstall nvm
$ brew cleanup (just for good measure)
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
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 returnnvm`
Now update Node.js with $ nvm install --lts
Update npm: $ nvm install-latest-npm
$ npm install --global mocha. Finally, success! Well, for me and I hope for you too.

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

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
nano ~/.zshrc
Add this line source $(brew --prefix nvm)/nvm.sh

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

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

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

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

Instructions from
lukechilds/zsh-nvm#as-an-oh-my-zsh-custom-plugin
If you are using mac os + zsh + oh-my-zsh:
Clone zsh-nvm into your custom plugins repo
git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm
Then load nvm as a plugin in your .zshrc file
plugins+=(zsh-nvm)
Keep in mind that plugins need to be added before oh-my-zsh.sh is sourced.
f.e.
$ nano ~/.zshrc
// edit .zshrc contents
...
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
# docs: f.e. https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/kubectl
plugins=(zsh-nvm)
source $ZSH/oh-my-zsh.sh
...
Finally reload the configuration $ source ~/.zshrc

Related

I am trying to install git on my mac and it's showing the same error while installing any package

Code in terminal:
harshdhariwal#Harshs-MacBook-Air ~ % $ brew install git
zsh: command not found: $
harshdhariwal#Harshs-MacBook-Air ~ %
What is the problem?
You need to remove $ from your command line. It's a command prompt and probably was copied from a tutorial you were using.
Also before you install anything with brew you need to install brew itself. See here on how it can be done.
Please do not include the '$' in your command. only run 'brew install git'

Terminal not recognizing nvm after installed with home brew

I installed nvm via homebrew, but when I run nvm -v or nvm --version form terminal I receive the message command not found: nvm. When I look in finder and cmd+shift+. I can see the ~/.nvm folder.
Initially I did not have a .bash_profile in my user directory, so I added one and the command to recognize nvm per this post:
Brew install nvm. nvm: command not found
However, that did not resolve the issue. I've not had this issue with an nvm install before, What could be going on here?
I am on macOS Catalina 10.15.6
I was facing the same issue after installing nvm. Whenever my iTerm / terminal restarts, nvm is gone.
Steps I followed to make it work.
After installing it, update the Homebrew package list and install NVM.
brew update
brew install nvm
Next, create a directory for NVM.
mkdir ~/.nvm
Now add these lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or later)
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Echoing $NVM_DIR should now return your NVM directory
:$ echo $NVM_DIR
/Users/username/.nvm
Now running nvm -v should return nvm’s options.
To see what Node versions are available to install run:
nvm ls-remote
For me, I just needed the latest point release of Node version 11 so I ran
nvm install 11
After installing you can verify what is installed with
nvm ls
If you have multiple versions and you want to specify which version you would like to use, simply use:
nvm use 11
to use Node version 11.
Switching back to, let’s say, version 12 would be as easy as nvm use 12.
After switching to node version 11, all my packages installed properly.
For my scenario, I was able to fix by uninstalling nvm and then reinstalling via curl, which seems to have worked.
I also created a .zshrc file, which apparently mac OS 10.15 and up needs.
I used the documentation here to uninstall and reinstall:
https://github.com/nvm-sh/nvm#about
.zshrc requirement:
https://github.com/nvm-sh/nvm#troubleshooting-on-macos
The steps I took:
From terminal, run
rm -fr "$NVM_DIR"
Then on the same terminal,
run touch ~/.zshrc
to create a .zshrc file.
Now run
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Finally, run
~/.nvm/nvm.sh

msgmerge on macos Catalina

I am trying to run a unix command line for some i18n work on a project. Using gettext library my issue is about running msgmerge
$ msgmerge
zsh: command not found: msgmerge
I tried brew instal gettext and brew link gettext but with no success. This was working well on my previous machine, but can't make it work on a fresh install.
I can confirm binary is available in /usr/local/opt/gettext/bin/msgmerge.
Fixed. When running brew reinstall gettext, command actually give the answer:
If you need to have gettext first in your PATH run:
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.zshrc
Export is only triggered when opening a new zsh prompt, PATH was not updated yet and worked when I re-openned a new window.
I tried running this brew link gettext --force, but I was getting:
$ brew install gettext
Warning: gettext 0.20.2 is already installed and up-to-date
To reinstall 0.20.2, run `brew reinstall gettext`
$ brew link gettext --force
Warning: Refusing to link macOS provided/shadowed software: gettext
If you need to have gettext first in your PATH run:
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile
For compilers to find gettext you may need to set:
export LDFLAGS="-L/usr/local/opt/gettext/lib"
export CPPFLAGS="-I/usr/local/opt/gettext/include"
Then, I just added it to the system path with:
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile
Related:
https://apple.stackexchange.com/questions/299048/can-not-use-the-gettext-which-is-installed-by-brew
Homebrew refusing to link OpenSSL
How to install gettext on MacOS X
Installed, just not linked

Brew older version of mysql not available at cmd line

I've installed mysql 5.7 via brew. The binary files are installed at /usr/local/opt/mysql\#5.7/bin/ however I can't access these files as this location isn't in my path.
Is there a brew way to fix this rather than me making symlinks around the system myself?
The Homebrew way of "fixing" this is to use link --force:
brew link --force mysql#5.7
Alternatively, you can add this location to your $PATH by modifying it in your ~/.bashrc or ~/.bash_profile:
export PATH="$(brew --prefix mysql#5.7):$PATH"
The simple "brew way" to do this is answered here
$ brew info mysql (to get info about the installed versions)
$ brew switch mysql 5.7.21 (to switch to a stable version)

Can't reinstall or uninstall Homebrew after blowing away contents of /usr/local/bin

I removed ALL content from /usr/local/bin folder (including 'brew'). Homebrew isn't working anymore and I seem to be stuck in a limbo. When I try to install it says:
It appears Homebrew is already installed. If your intent is to
reinstall you should do the following before running this installer
again:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
When I run the given uninstall command it says:
Failed to locate Homebrew!
Background
The problem arose when I attempted to remove node.js by following this guide:
https://stackoverflow.com/a/11178106/1736012
To completely uninstall node + npm is to do the following:
go to /usr/local/lib and delete any node and node_modules
go to /usr/local/include and delete any node and node_modules directory
if you installed with brew install node, then run brew uninstall node in your terminal
check your Home directory for any local or lib or
include folders, and delete any node or node_modules from there
go to /usr/local/bin and delete any node executable
Especially 5 was bad! That's what led me to remove everything under /usr/local/bin. So brew doctor won't work (brew isn't recognized anymore). Brew worked fine before this.
What I tried
This does not work either as brew is missing:
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )"
I tried various scripts like this one for example: https://apple.stackexchange.com/a/85481. And this: https://gist.github.com/SteveBenner/11254428. None of them is working (both assumes that brew command is there)...
What can I do to re install Homebrew so that it works as before??
This should bring back a working brew command:
cd /usr/local/Homebrew
git init
git remote add origin https://github.com/Homebrew/homebrew
git pull origin master
Next I would check the output of brew doctor and see if there are major problems. There is an official uninstalling guide on homebrew's github wiki in case you want to completely uninstall.
Try to move or remove the Homebrew file in the user/local file and then try the regular link from the homebrew homepage to install the brew!
By the way, I did not try moving but I am pretty sure it should work.
Note: While the operation you might have to use the sudo
I faced the same issue, the following link really worked for me
https://github.com/Homebrew/brew/issues/10368
especially comment from MrBenFTW commented on Feb 2021

Resources