DEV Community

Little Coding Things Blog
Little Coding Things Blog

Posted on • Originally published at littlecodingthings.com

How to install Homebrew — MacOS for beginners

Originally published on Little Coding Things

If you are making your first steps on macOS, you may have never heard of Homebrew before. Homebrew is a powerful package manager, similar to npm if you’ve worked with it before. It allows you to easily install, update, and remove software packages directly from your terminal, making it an incredibly handy tool for developers. In this post, you’ll find a step-by-step guide to install Homebrew on MacOS.

Why is it essential to install Homebrew?

Homebrew is widely regarded as the most popular package manager for macOS. It’s the go-to choice for developers and power users because of its simplicity and active community support.

Homebrew lets you easily get the tools and libraries you need for development or daily tasks, from developer tools like Git and Node.js to simple everyday utilities. It saves time by skipping the trouble of manual downloads and setup. It’s simple, fast, and perfect for customizing your Mac.

If you haven’t used a tool like Homebrew before, don’t overlook it — it could completely transform the way you manage software on your Mac.

Check if Homebrew is already installed

Just to make sure you haven’t already installed Homebrew in the past, let’s check it out. Open your terminal and type:

brew help
Enter fullscreen mode Exit fullscreen mode

If you have it installed, you should see something like

Example usage:
  brew search TEXT|/REGEX/
  brew info [FORMULA|CASK...]
  brew install FORMULA|CASK...
  brew update
  brew upgrade [FORMULA|CASK...
....
Enter fullscreen mode Exit fullscreen mode

otherwise, you will get the following result

command not found: brew
Enter fullscreen mode Exit fullscreen mode

How to install Homebrew

Ready to install Homebrew? Here’s everything you need to know. Open your terminal (Cmd + Space and type “Terminal“) and type

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

Oh, you say! What is this command? Let me explain. This command asks bash (which is a command-line shell language commonly used in macOS and Linux) to execute a script.

Here’s how it works:

  • /bin/bash: specifies the bash shell, ensuring the command is executed using bash, even if your default shell is something else (like zsh).

  • -c: This flag tells bash to execute the command provided in quotes.

  • $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh): This part fetches the Homebrew installation script directly from GitHub using curl (a tool for transferring data).

In simple terms, this command downloads the Homebrew installer script from GitHub and immediately runs it using bash to set up Homebrew on your system.

You will be asked for your super user password:

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

Checking for `sudo` access (which may request your password)...

Password:
Enter fullscreen mode Exit fullscreen mode

After typing your password, you’ll see a message prompting you to press ENTER to proceed with the installation. Simply press ENTER, and the installation will continue.

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

Checking for `sudo` access (which may request your password)...

Password:

==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
....
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/bin
/opt/homebrew/etc
/opt/homebrew/include
....
/opt/homebrew/Frameworks

Press RETURN/ENTER to continue or any other key to abort:
Enter fullscreen mode Exit fullscreen mode

Wait for the installation process to complete — it may take a few minutes. Once it’s done, you’ll see the message “Installation successful!”. However, to ensure everything was installed correctly, let’s verify it by typing the following command in the terminal:

brew help
Enter fullscreen mode Exit fullscreen mode

If it was successfully installed, you should see the following response.

Example usage:
  brew search TEXT|/REGEX/
  brew info [FORMULA|CASK...]
  brew install FORMULA|CASK...
....
Enter fullscreen mode Exit fullscreen mode

Homebrew doesn’t work after installing it

If you’ve already followed all the steps described to install Homebrew but see a “command not found” error when running, e.g., brew help it typically means that the Homebrew binary is not properly added to your system’s PATH.

To resolve the issue, revisit the logs from the Homebrew installation script. At the end of the script, you’ll typically find specific instructions for finalizing the installation.

Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the 'Next steps' section below.
==> Installation successful!
...
...
...
==> Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
echo >> /Users//.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users//.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Enter fullscreen mode Exit fullscreen mode

copy the last part of the Homebrew installation instructions — starting from the command that begins with echo — and paste it into your terminal. This command typically adds Homebrew to your system’s PATH.

By now, you should have Homebrew installed on your system successfully.

Congratulations! This is just the first small step on your exciting journey to mastering powerful tools and workflows as you grow your skills.If you’re exploring ways to automate parts of your development workflow next, you might find Git tools like Husky pre-commit hooks especially helpful.

Top comments (0)