6

This is what I get when I try to install Homebrew: Error: Git is unavailable

Downloading and installing Homebrew...
Error: Git is unavailable

It gives me an error and says that Git is unavailable, although I have downloaded Git and installed it.

pkamb
  • 33,281
  • 23
  • 160
  • 191
S. Caperna
  • 61
  • 1
  • 1
  • 5

4 Answers4

7

Make sure that you have your brew updated. First run the following command:

brew doctor

Now, if you get Your system is ready to brew, you can move on to install Git.

With Homebrew, installing Git is as easy as this:

brew update
brew install git

Note: it's a good habit to run update before installing anything with Homebrew because Homebrew is updated regularly.

To verify:

git --version

You should get git version 2.3.1 or later.

Run brew doctor to make sure everything is still working. In case brew doctor doesn't work you can use these commands:

cd `brew --prefix`
git remote add origin https://github.com/Homebrew/homebrew.git
git fetch origin
git reset --hard origin/master
brew update

Already up-to-date.

If you're seeing permission errors tried running

sudo chown -R $(whoami) $(brew --prefix)

Or if it complains that any directories inside /usr/local aren't writable, fix it with this command:

sudo chown -R `whoami` /usr/local

Lastly, if you get Warning: /usr/bin occurs before /usr/local/bin, run the command below and quit and relaunch Terminal:

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

This command takes everything between the single quotes and adds it >> to a file called .bash_profile in your user's root directory ~/. Every time you open a new Terminal window or tab, .bash_profile is called. The export PATH line tells your system to look in /usr/local/bin first, since that's where Homebrew installs tools.

Download and Install the Command Line Tools

For El Capitan, Yosemite and Mavericks
  1. Inside the Terminal window, copy and paste (or type) the following command, and press the return key on your keyboard:

    xcode-select --install
    
  2. You should see the pop up below on your screen. Click Install when it appears.

install xcode

  1. Click Agree when the License Agreement appears.

  2. Your computer will then attempt to find the software, and then will start downloading it. The following popup will appear:

  3. Once the software is installed, click Done. That's it! You're now ready to go to Step 2.

install xcode, done

Teocci
  • 7,189
  • 1
  • 50
  • 48
  • 1
    when i try run brew doctor it returns with : Error: Git is unavailable Error: Failure while executing: /usr/local/bin/brew tap homebrew/core -q – S. Caperna Jul 14 '16 at 04:30
  • in fact when i try to run any line with the command brew it returns with the same error Also I downloaded Git 2.8.1 so the version should be fine thanks so much for your help! – S. Caperna Jul 14 '16 at 04:32
  • If you think that my answer was useful please give me a point. Thanks~ – Teocci Jul 14 '16 at 04:55
  • all the commands you wrote it returns they are illegal instructions :/ – S. Caperna Jul 14 '16 at 05:00
  • no I didn't.. where can i find versions to download compatible with my version? (10.6.8) – S. Caperna Jul 14 '16 at 05:17
  • I've written an [open source script](https://github.com/teocci/DevLaptop) that can set everything up for you, including configuring your Mac to work with GitHub. If you prefer to do everything manually, start with Install Step above. – Teocci Jul 14 '16 at 05:51
5

So the PATH was getting filtered, setting

export HOMEBREW_NO_ENV_FILTERING=1

helped avoid this issue

Mario Codes
  • 689
  • 8
  • 15
Subraminion
  • 197
  • 1
  • 2
  • 1
    This is the only thing that worked for me. I tried all the suggestions from https://stackoverflow.com/questions/36237537/brew-doctor-warning-how-to-add-git-to-path – kunigami Dec 03 '21 at 02:40
  • As of 2022, this is the only solution that worked for me for a 2019 Macbook Air. – abautista Mar 05 '22 at 00:47
  • Error: HOMEBREW_NO_ENV_FILTERING was deprecated for over a year and has now been removed (because it breaks many things)! – filip stepniak Dec 05 '22 at 09:10
0

If you see the message "Error: Git is unavailable" it usually means that the git part of the brew installation is broken. To have a better hint of what's wrong with your installation, try running this:

ls -ld `brew --prefix`/.git

If you downloaded brew from git, then obviously you already have git. So this error means you have a broken $PATH or broken brew symlink or something wonky with your brew installation.

I also had this error, but after I fixed my $PATH to ensure the good brew was first, then this error vanished.

Rob
  • 1
0

This solved my issue

  1. Run ‘xcode-select --install‘ (let the installation complete)
  2. ‘brew update’
  3. ‘brew install “postman” or
Manjula
  • 1
  • 1