I am doing some Rails programming and I consistently see Homebrew referenced in solutions around the web but have never used it.
I also notice Homebrew in the terminal version 2.9 as an option next to "Shell -> New" from the terminal drop down but when I select homebrew and issue commands, they fail.
Usually with the "command not found" error.
Strangely enough I have been unable to locate a simple command to determine whether brew is installed or not.
How do I check to see if Homebrew is already installed on my Mac?
brew help. If brew is there, you get output. If not, you get 'command not found'. If you need to check in a script, you can work out how to redirect output and check $?.
I use this to perform update or install:
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
brew update
fi
The standard way of figuring out if something is installed is to use which.
If Brew is installed.
>>> which brew
/usr/local/bin/brew
If Brew is not installed.
>>> which brew
brew not found
Note: The "not installed" message depends on your shell. zsh is shown above. bash will just not print anything. csh will say brew: Command not found. In the "installed" case, all shells will print the path.)
It works with all command line programs. Try which grep or which python. Since it tells you the program that you're running, it's helpful when debugging as well.
While which is the most common way of checking if a program is installed, it will tell you a program is installed ONLY if it's in the $PATH. So if your program is installed, but the $PATH wasn't updated for whatever reason*, which will tell you the program isn't installed.
(*One example scenario is changing from Bash to Zshell and ~/.zshrc not having the old $PATH from ~/.bash_profile)
command -v foo is a better alternative to which foo. command -v brew will output nothing if Homebrew is not installed
command -v brew
Here's a sample script to check if Homebrew is installed, install it if it isn't, update if it is.
if [[ $(command -v brew) == "" ]]; then
echo "Installing Hombrew"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
echo "Updating Homebrew"
brew update
fi
brew -v or brew --version does the trick!
I just type brew -v in terminal if you have it it will respond with the version number installed.
Location of the brew where it installed
which brew
version of home brew install
brew --version
[ ! -f "`which brew`" ] && echo "not installed"
Explaination: If brew is not installed run command after &&
brew doctor checks if Homebrew is installed and working properly.
use either the which or type built-in tools.
i.e.: which brew or type brew
Maybe your mac don't received the path
enter image description here
Run command below
eval "$(/opt/homebrew/bin/brew shellenv)"
And run to check that work
brew help
Beginners normally do, the homebrew --version which is wrong.
Do instead, brew --version. brew help works also. If these two commands are not executed, you don't have homebrew installed.
Another one possible way:
# Check if Ninja is installed
if ! which ninja > /dev/null
then
echo 'Ninja installation...'
brew install ninja
fi
In my case Mac OS High Sierra 10.13.6
brew -v
OutPut-
Homebrew 2.2.2
Homebrew/homebrew-core (git revision 71aa; last commit 2020-01-07)
Homebrew/homebrew-cask (git revision 84f00; last commit 2020-01-07)
Yes you can run which brew, but you may have it installed and it says it is not found if you are using zsh. You will need to add it to your .zshrc file.
I find it simple to use brew help command to find it is installed or not. There was a user guide on the homebrew download page.
If it is not installed then it will show 'command not found'
If you need to install homebrew then paste this on terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
jest write brew -v in terminal and if you have it , you will see there version number and the install date .
like this :
Homebrew 3.3.12
Homebrew/homebrew-core (git revision c3cacc9cd1d; last commit 2022-01-31)
Homebrew/homebrew-cask (git revision fb6ec06d8b; last commit 2022-01-31)
Once you install Homebrew, type command brew doctor in terminal.
If you get the following message:
Your system is ready to brew
then you are good to go and you have successfully installed homebrew.
If you get any warnings, you can try fixing it.
Another way to do it is using the "command" builtin tool
if [ "$(command -v brew)" ]; then
echo "command \"brew\" exists on system"
fi
in your terminal, do which brew and itll tell you where it was installed at within your computer, but itll only work in zsh not in bash.
Running Catalina 10.15.4 I ran the permissions command below to get brew to install
sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*
Related
Recently I wrote a bash script to delete unused images from the Xcode project. That was working fine on Mountain Lion. Today I installed latest version of Mavericks (I did clean install). But now while running the terminal command i.e.bash removeunusedimages.sh. I'm getting following error:
removeUnusedImages.sh: line 5: ack: command not found
I have tried searching about ack on google but still not able to fix the issue.
Installed using homebrew:
brew install ack
Note: If you're getting brew command not found error. Then you can install brew using following command:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Homebrew source: http://brew.sh/
Ack is a tool similar to grep. You can install it from here...
curl http://beyondgrep.com/ack-2.12-single-file > ~/bin/ack && chmod 0755 !#:3
I'm trying to get brew going on my OS X 10.7.5 and having some issues. My brew install is now broken.
$ brew doctor
/usr/local/bin/brew:34:in `<': comparison of String with Float failed (ArgumentError)
from /usr/local/bin/brew:34
My best guess is that I managed to kill brew somehow by running:
$ sudo chown -R myusername:admin /usr/local
Thoughts?
My plan is to simply uninstall brew and start from scratch.
p.s. The brew version is 0.9.5
$ brew -v
0.9.5
Try the following command:
vi +34 /usr/local/bin/brew
This in order to see what that comparison is. I had the same problem here, and it was trying to compare if MACOS_VERSION < 10.5. Since I'm using Lion, I just commented that if and got it working:
=begin
if MACOS_VERSION < 10.5
abort <<-EOABORT.undent
Homebrew requires Leopard or higher. For Tiger support, see:
http://github.com/sceaga/homebrew/tree/tiger
EOABORT
end
=end
I fixed this by simply "checking out" a "fresh" version of /usr/local/bin/brew....
cd /usr/local && git checkout origin/master -- bin/brew
then a requisite visit to the brew doctor. ouch. 🚑
I'm trying to install glue 0.3 for OXS Mountain Lion and ran into this error after installing homebrew (Error: Cowardly refusing to sudo brew install You can use brew with sudo, but only if the brew executable is owned by root. However, this is both not recommended and completely unsupported so do so at your own risk.) I got this error after the first step for installing glue 0.3 ($ sudo brew install jpeg). No idea how to fix this...please help!
sudo chown root /usr/local/bin/brew
sudo chown -R $USER /usr/local
Use the above command instead of changing the owner of brew to root.
This is the suggested method by the Owner of homebrew in https://github.com/Homebrew/homebrew/issues/9953
Answered by the developers here:
https://github.com/Homebrew/homebrew/issues/9953
I solved it by NOT using sudo, and changing the permissions on whatever file it says cannot be accessed without sudo.
For example, I could not access /usr/local/Cellar, so I entered the following (as specified here: https://github.com/Homebrew/homebrew/issues/3930)
sudo chmod g+w /usr/local/Cellar
sudo chgrp staff /usr/local/Cellar
For High Sierra macOS 10.13.3 or newer.
None of the solutions given here worked for me on this version. The only (and the best) fix is to uninstall brew and install it again with the following terminal commands. Note you will lose your current kegs, so you should get a list of the installed kegs, for reinstalling them after reinstalling brew as shown below under step 1. Actually, this was a good opportunity for me to get rid of those kegs that I am no longer using:
List your current kegs for reinstalling, those you wan't to keep:
brew list
Uninstall brew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Reinstall brew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Optionally to prevent your usage being sent to Google Analytics (Update: Fortunately, now this has been stopped, so you may skip this step):
brew analytics off
Finally reinstall your previous kegs from step 1 (or those you still want to use). Replace the text with the square brackets with the list, (i.e. brew install sqlite heroku ):
brew install [list of kegs from step 1]
I have updated my macos to sierra and npm stopped working. Below are the steps followed to fix them.
Uninstall Node and install it from brew and follow the below steps
sudo chmod g+w /usr/local/Cellar
sudo chgrp staff /usr/local/Cellar
sudo chown root /usr/local/bin/brew
sudo brew postinstall node
This was helpful for me
http://digitizor.com/fix-cowardly-refusing-sudo-error-brew/
As quoted in the text, you essentially have to change the user and group of brew to root and wheel respectively.
unknown7cd1c37eb7ca:local shoaibali$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
-e:67: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
-e:96: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
unknown7cd1c37eb7ca:local shoaibali$ ls
CONTRIBUTING.md foreman hw_mp_userdata
Library git libexec
PortDetect.log heroku opt
bin hw_mobile_userdata share
unknown7cd1c37eb7ca:local shoaibali$
I have some problems with my brew when I was trying to install ffmpeg. I think I did the immature thing (note - after hours of trying) of uninstalling brew (through some article i read online) and trying to reinstall it. But the above output comes in my terminal when I try to install brew again. How can it say Homebrew is already installed when clearly the Cellar file isn't there ?
I had the same issue.
There was no directory called., /usr/local/Cellar but brew installation kept reporting it is already installed.
I resolved the issue by doing the following.,
Step 1 : run
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
(It reported error and didn't run successfully., but I believe it did cleanup)
Step 2 : Being from Windows world., restarted the terminal
Step 3 : Ran again
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
It ran successfully.,
A simple
sudo rm -rf /usr/local/.git
fixed my problem and I could re-install brew
I tried this solution but running "brew cleanup" when the system doesn't detect brew is not possible XD
I came up with a possible solution... I've tried to install MacPort and also didn't installed well, but it seems to uninstall (somehow) brew, so I could reinstall it from scratch
And this time it works! So, maybe it helps somebody!
PS: I think my original problem was that I had internet connection problem when I installed Brew for the first time, and didn't installed well
I followed
this tutorial
to install rvm on ubuntu 12.04
when run rvm requirements, I got the following message
Installing requirements for ubuntu, might require sudo password.
Running 'apt-get --quiet --yes update' would require sudo.
Cowardly refusing to continue, please read 'rvm autolibs'.
Updating repositories
Missing required packages: libgdbm-dev, libffi-dev.
Cowardly refusing to continue, please read 'rvm autolibs'.
I got same message when run rvm install 1.9.3
Can anyone help?
Thanks.
Sometimes the official documentation it's more reliable than a blog. Take a look at the rvm documentation. The command from the blog to install rvm is:
curl -L get.rvm.io | bash -s stable
and the official documentation recommend that one:
\curl -L https://get.rvm.io | bash -s stable --autolibs=3 --rails
Probably this will solve your problems with autolibs, the same that was happening for example in that question .
from https://rvm.io/rvm/autolibs - there are two modes that will be useful for you:
rvm autolibs read-only - it will do all the steps and only show the required commands / missing libraries
rvm autolibs enable - it will install everything for you, it might require sudo password so a nice trick for tools like capistranos is to:
rvm autolibs read-only
sudo rvm --autolibs=enabled requirements ruby-2.0.0
rvm install ruby-2.0.0
A writeup about autolibs https://blog.engineyard.com/2013/rvm-ruby-2-0
I was getting some sort of same error:
Missing required packages: libreadline6, libreadline6-dev, libyaml-dev, libffi-dev.
Cowardly refusing to continue, please read 'rvm autolibs'.
Even though Ubuntu Software Center showing "libreadline6, libreadline6-dev etc" installed.
I got this fixed disabling autolibs:
rvm autolibs disable
ruby install 1.9.X worked!
Below solution is to solve the rvm requirment error returns 100
If any deb command is commented in /etc/apt/sources.list than try to uncomment that command from /etc/apt/sources.list
Command is:
$sudo vi /etc/apt/sources.list
If problem is not solved than replace sources.list file with other Ubuntu's sources.list
Command is:
$mv <file path of sources.list from other Ubuntu machine> /etc/apt/sources.list
Please make a backup before doing that
Command is:
$cp /etc/apt/sources.list sources_backup.list
Problem should solve by this time, if not than reinstall the Ubuntu.
Note: If sources.list file is corrupted than it will gives problem to install other packages.