355

According to the Homebrew site, to install it, I need to type:

brew install wget

I get an error message:

-bash: brew: command not found

Found this answer. The problem, however, is I don't see brew in /usr/local/bin.

I added the below line to my .bashrc file

export PATH=/usr/local/bin:$PATH

Still getting the command not found error.

How do I install Homebrew on macOS?

Cœur
  • 37,241
  • 25
  • 195
  • 267
DBWeinstein
  • 8,605
  • 31
  • 73
  • 118

26 Answers26

732

It's on the top of the Homebrew homepage.

From a Terminal prompt:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

The command brew install wget is an example of how to use Homebrew to install another application (in this case, wget) after brew is already installed.


Historic...

Before about 2020, the command given on the Homebrew page was:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Fattie
  • 27,874
  • 70
  • 431
  • 719
Jay Harris
  • 9,935
  • 1
  • 26
  • 27
  • 2
    A easy to remender way: `ruby -e "$(curl -fsSL bit.ly/brew-install)"` – Lucas Lopes Jan 24 '19 at 20:06
  • 6
    Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in Bash. Please migrate to the following command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" – App Work May 03 '20 at 21:49
  • 3
    After "installing" you need to do something else: ```Add Homebrew to your PATH in /Users/username/.bash_profile: echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/username/.bash_profile eval "$(/opt/homebrew/bin/brew shellenv)" ``` – M. Beausoleil Mar 26 '21 at 00:48
  • 1
    Actually, after the installation ends, there is a `next steps` section at the bottom of the terminal, there are 2 steps to run like: `echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[user]/.zprofile` and `eval "$(/opt/homebrew/bin/brew shellenv)"` – JORGE GARNICA Aug 11 '21 at 06:22
  • this failed, error `Error: homebrew-core is a shallow clone. homebrew-cask is a shallow clone.` – Charlie Parker Dec 17 '21 at 15:37
  • isn't it super fishy that we are asked to do `/bin/bash` given that `zsh` is the new default in mac? – Charlie Parker Dec 17 '21 at 15:41
  • for me I had to do `sudo rm -rf /usr/local/HomeBrew` it seems for the install to work ref: https://apple.stackexchange.com/questions/419724/homebrew-installation-failed – Charlie Parker Dec 17 '21 at 15:42
  • And don't forget for non Intell Mac put after install brew : echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc – iEvgen Podkorytov Jul 20 '22 at 09:30
  • You can find the full documentation and step by step guide here, https://brew.sh/ – M.Hossein Rahimi Aug 29 '22 at 20:59
223

If you are using m1 chip mac then run below command after installing homebrew and open the terminal again:

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
Awadesh
  • 3,530
  • 2
  • 20
  • 32
71

For Mac with Apple Silicon (M1), export the path of the shell where you want to run the brew command and enter it.

export PATH=/opt/homebrew/bin:$PATH
brew
Sathnindu Kottage
  • 1,083
  • 6
  • 17
55

Check if Xcode is installed or not:

$ gcc --version

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

$ brew doctor

$ brew update

http://techsharehub.blogspot.com/2013/08/brew-command-not-found.html "click here for exact instruction updates"

Viji
  • 2,629
  • 1
  • 18
  • 30
  • Worth noting that you may have to use the default mac terminal app. I was trying in ITERM and the install was not working. Just kept telling me to visit linuxbrew.sh – Ed Fryed Mar 26 '17 at 23:32
  • I had to install xcode command line developer tools after `brew doctor` – Matthew Lock Dec 05 '17 at 04:04
  • 2
    I have to log in to give you an upvote, it has been a while I haven't used MacOS. – Tran Minh May 15 '19 at 10:44
  • 1
    This install command is changed to: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" – sgupta Jan 14 '21 at 14:09
42

How To Set Up Your Mac for Homebrew

Step 1

Check you have already Install the Xcode. Run the below command in your terminal

/usr/bin/xcodebuild -version

It will print the below sample output:

Xcode 12.3 Build version 12C33

Step 2

Now Open Xcode:

  1. Select preferences
  2. Select location tab
  3. Now in command Line Tool select your Xcode version from dropdown menu

Step 3

In terminal run below command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Note : if you have M1 Chip Mac run the below command, close terminal and open the terminal again

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
Varma Mukesh
  • 883
  • 6
  • 12
  • 4
    Whether the `export` should go to `.zshrc` or `.bash_profile` depends on your login shell. New user accounts default to Zsh but Bash is still an option, and will probably be your shell if you created your account on an older version of macOS where Bash was the default, or you subsequently explicitly configured Bash as your shell. – tripleee Jan 09 '21 at 12:49
  • It does not need to close the terminal in my case. – Memphis Meng Apr 15 '21 at 15:27
  • isn't it super fishy that we are asked to do `/bin/bash` given that `zsh` is the new default in mac? – Charlie Parker Dec 17 '21 at 15:41
13

For m1 mac, use this command and restart the terminal.

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc

Buddhika Lakmal
  • 155
  • 1
  • 3
  • 4
    This is the same solution as in [this other answer](https://stackoverflow.com/a/67109482/2227743). *When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers.* – Eric Aya Sep 13 '21 at 09:52
10

I might be late to the party, but there is a cool website where you can search for the packages and it will list the necessary command to install the stuff. BrewInstall is the website.

However you can install wget with the following command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install wget

Hope this helps :)

drishti ahuja
  • 1,379
  • 2
  • 15
  • 26
6

On an out of the box MacOS High Sierra 10.13.6

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Gives the following error:

curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option.

If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL).

If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option.

HTTPS-proxy has similar options --proxy-cacert and --proxy-insecure.

Solution: Just add a k to your Curl Options

$ ruby -e "$(curl -fsSLk https://raw.githubusercontent.com/Homebrew/install/master/install)"
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
ximbal
  • 3,178
  • 2
  • 17
  • 19
6

first, install the homebrew by pasting the command in the mac terminal

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

then edit your .bashrc file

vi .bashrc

paste the below command at the end and save it

export PATH=/opt/homebrew/bin:$PATH

to save simply type :wq and press enter

if bashrc file is not there then simply create and then edit the file, to create type

touch ~/.bashrc

and then simply run the command

source ~/.bashrc

now try to use the brew command hopefully it will work now

Update: if you are in M1 mac then after installing homebrew just run the command mentioned below and reload the terminal

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
Tanmoy Bhowmick
  • 1,305
  • 15
  • 20
5

Brew has now been rewritten in Bash!

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Roman
  • 8,826
  • 10
  • 63
  • 103
  • 1
    This is the correct answer as of August, 2020. You could also add the homepage link into this answer! https://brew.sh/ There is the right command. – Enis Arik Aug 05 '20 at 20:41
3

Here is a version that wraps the homebrew installer in a bash function that can be run from your deployment scripts:

install_homebrew_if_not_present() {
    echo "Checking for homebrew installation"
    which -s brew
    if [[ $? != 0 ]] ; then
        echo "Homebrew not found. Installing..."
        ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    else
        echo "Homebrew already installed! Updating..."
        brew update
    fi
}

And another function which will install a homebrew formula if it is not already installed:

brew_install () {       
    if brew ls --versions $1 > /dev/null; then
        echo "already installed: $1"
    else
        echo "Installing forumula: $1..."
        brew install $1
    fi
}

Once you have these functions defined you can use them as follows in your bash script:

install_homebrew_if_not_present
brew_install wget
brew_install openssl
...
ccpizza
  • 28,968
  • 18
  • 162
  • 169
3

I faced the same problem of brew command not found while installing Homebrew on mac BigSur with M1 processor.

I - Install XCode if it is not installed yet.

II - Select terminal.app in Finder.

III - RMB click on Terminal and select "Get Info"

IV - Select Open using Rosetta checkbox.

V - Close any open Terminal windows.

VI - Open a new Terminal window and install Hobebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

VII - Test Homebrew installation.

IIX - Uncheck Open using Rosetta checkbox.

Ivan
  • 399
  • 2
  • 5
  • 18
2

If you still get error after running,

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then try to download and install command line tool from https://developer.apple.com/download/more/ for your particular Mac os and Xcode version.

Then try to run,

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

and then

brew install node
Rajesh Maurya
  • 3,026
  • 4
  • 19
  • 37
  • The advice to install `node` is completely spurious here. The question asks how to install `brew`, not `node`. – tripleee Jan 09 '21 at 12:51
2

Open Terminal and put below command.
Install:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Uninstall:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Once install complete after entering brew commands:

brew install wget
brew install node
brew install watchman
...
...
Ramprasath Selvam
  • 3,868
  • 3
  • 25
  • 41
2

You can install brew using below command.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

However, while using this you will get warning that it buy homebrew installer is now deprecated. Recommended to use Bash instead.

Screenshot 1

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Screenshot 2

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
1

add the following in your terminal and click enter then follow the instruction in the terminal. /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Meh
  • 339
  • 2
  • 5
1

Following command doesn't work if your are under proxy.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Instead user following -

ruby -e "$(curl -x http://DOMAIN%5cUSER_NAME:PASSWORD@PROXY:PORT -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Note we have to use %5c instead of "\" Similarly if your password has any special character replace it with unicode e.g for @ use %40 Refer this Unicodes

Replace above command with your own params

DOMAIN - Your Domain

USER_NAME - Your User Name

PASSWORD - password

PROXY - 10.10.10.10

PORT - 8080

Harshad
  • 7,904
  • 3
  • 24
  • 42
  • "Domain" apparently means Active Directory user group here. It makes sense if you are a Windows victim, but is probably only confusing to everybody else. – tripleee Jan 09 '21 at 12:53
1

macOS Big Sur

Had to add this to Terminal cmd to get Brew running.

  • Add Homebrew to your PATH in /Users/*username/.zprofile:

      echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/*username/.zprofile
      eval $(/opt/homebrew/bin/brew shellenv)
    

*username = your local machine username

K-G
  • 2,799
  • 4
  • 26
  • 42
1

Resolve " -bash: brew: command not found "

  • Add Homebrew to your PATH in /Users//.bash_profile:

echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users//.bash_profile

eval $(/opt/homebrew/bin/brew shellenv)
TechGeek
  • 11
  • 1
1

For Users who installed homebrew for local user account using Untar Anywhere method in MacOS Ventura - M2 pro:


Step 1: Create ~/.zprofile if not there already: touch ~/.zprofile , check with ls -a

Step 2: Open nano ~/.zprofile

Step 3: Paste the eval command portion with appropriate User name: eval "$(/Users/rakibulhaq/Applications/homebrew/bin/brew shellenv)" here, rakibulhaq is a sample user name which should be replaced with your user name.

Step 3: Save and exit Control + X and return

Step 4: Reload the shell session source ~/.zprofile

Now the brew command will work even after restarting the session.

Rakibul Haq
  • 1,348
  • 23
  • 32
0

Not sure why nobody mentioned this : when you run the installation command from the official site, in the final lines you would see something like below, and you need to follow the ==> Next steps:

==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this `install` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Add Homebrew to your PATH in /Users/{YOUR USER NAME}/.bash_profile:
    echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/{YOUR USER NAME}/.bash_profile
    eval $(/opt/homebrew/bin/brew shellenv)

This is for bash shell. You will see different steps for every different shell, but the source of the steps are same.

mcvkr
  • 3,209
  • 6
  • 38
  • 63
0

What worked for me was setting the BREW_FILE_DIRECTORY as below

echo "export BREW_FILE_DIRECTORY=/opt" >> ~/.zshrc

since the brew.sh file is present under /opt/homebrew/bin going through the script everything seems to be computed from the BREW_FILE_DIRECTORY variable. This worked on a MacBook Pro (M1)

0

installing homebrew on macOS

to install homebrew you can simply just run this command in the terminal...

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

if you need help installing any packages from homebrew this page should help

Angus
  • 70
  • 6
-1

For Apple Silicon M1/M2 Pro, run the steps below to add brew to your path:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/username123/.zprofile

eval "$(/opt/homebrew/bin/brew shellenv)"
Alexandre Juma
  • 3,128
  • 1
  • 20
  • 46
-2

After I had tried everything described, I looked up into the folder permission of brew in /usr/local/etc/. Somehow the permission were changed and I was not able to open the folder. I changed the folder permissions(with chmod) with same permissions as the other folders and brew start working.

  • Interesting war story, but there isn't enough information here to decide whether it's useful at all. – tripleee Jan 09 '21 at 14:17
-2

Here's the script:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"