# Setting up Homebrew

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

# macOS

### Zsh — recommended for modern macOS

nano ~/.zprofile

Add: eval "$(/opt/homebrew/bin/brew shellenv)"
source ~/.zprofile

### Verify

brew --version
which brew
/opt/homebrew/bin/brew



# Linux

### If using bash

nano ~/.bashrc
Add: eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
source ~/.bashrc


### If using zsh

nano ~/.zshrc
Add: eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
source ~/.zshrc



# What about `.bash_profile`?

This is where things can get confusing.

Bash has different startup files depending on whether it is a **login shell** or an **interactive non-login shell**.

Typically:

~/.bash_profile is used for login Bash shells, while ~/.bashrc is used for interactive non-login Bash shells.

So if you're on a Mac using Bash, you can put:

eval "$(/opt/homebrew/bin/brew shellenv)"
in: ~/.bash_profile



If you use Bash regularly, there's a common pattern that avoids having to duplicate everything.

Your ~/.bash_profile can contain:

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

Which means that you can then put your Homebrew configuration in: ~/.bashrc

eval "$(/opt/homebrew/bin/brew shellenv)"

This means your login Bash shell loads `.bash_profile`, which in turn loads `.bashrc`.

On Linux, use:

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

---

# A setup that works across Mac + Linux

If you want one configuration that you can use on both macOS and Linux, Homebrew actually documents a nice approach.

You can put this in your shell configuration:

command -v brew || export PATH="/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin:/usr/local/bin"
command -v brew && eval "$(brew shellenv)"

This checks the likely Homebrew locations and then lets `brew shellenv` configure the environment appropriately.