DEV Community

Jackline Kaunda
Jackline Kaunda

Posted on

How to Install Homebrew on Ubuntu (Step-by-Step Guide)

TL;DR

Install Homebrew on Ubuntu in these steps:

sudo apt-get install build-essential procps curl file git

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

echo >> /home/pc/.bashrc
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> /home/pc/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
Enter fullscreen mode Exit fullscreen mode

Then verify:

brew doctor
Enter fullscreen mode Exit fullscreen mode

If you see:

Your system is ready to brew.
Enter fullscreen mode Exit fullscreen mode

You’re all set.

Introduction

If you have used macOS before, you’ve probably come across brew (Homebrew). It’s a simple and powerful package manager that makes installing developer tools much easier.

I previously used brew on macOS and really liked the experience, so I decided to try it on Ubuntu as well. My goal was to use both Homebrew and the native Ubuntu package manager apt in my development.

In this guide, I’ll walk through how to install Homebrew on Ubuntu.

Throughout this installation, we’ll reference the official Homebrew documentation:

Let’s get started.

1: Install the prerequisite packages

Homebrew requires a few system packages before installation.
Run the following command in your terminal:

sudo apt-get install build-essential procps curl file git
Enter fullscreen mode Exit fullscreen mode

These packages provide the basic tools needed to compile and manage software.

You can find the full requirements in the official guide:
https://docs.brew.sh/Homebrew-on-Linux#requirements

Step 2: Run the Homebrew installation script

Next, run the official Homebrew installation script:

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

The script will:

  • Show the packages that will be installed
  • Display the directories that will be created
  • Pause and ask whether you want to continue

At this point, press Enter/Return to continue the installation.

The installation will proceed automatically, and once it finishes, the terminal will display the next steps required to configure Homebrew.

Step 3: Configure Homebrew after installation

After installation, Homebrew needs to be added to your shell environment.

Add Homebrew to your PATH
If you are using bash, run:

echo >> /home/pc/.bashrc
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> /home/pc/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
Enter fullscreen mode Exit fullscreen mode

If you are using zsh, add the same command to ~/.zshrc.

Test the installation

To confirm everything is working, run:

brew doctor
Enter fullscreen mode Exit fullscreen mode

If everything is set up correctly, you should see:

Your system is ready to brew.
Enter fullscreen mode Exit fullscreen mode

Possible errors

You might encounter an error like this:

/home/pc/.linuxbrew/Library/brew.sh: line 177: exec: : not found
Enter fullscreen mode Exit fullscreen mode

This usually indicates a missing dependency, often Ruby.

First, check whether Ruby is installed:

which -a ruby
Enter fullscreen mode Exit fullscreen mode

If Ruby is missing, install it with:

sudo apt-get install ruby
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can install all common Homebrew dependencies with:

sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g
Enter fullscreen mode Exit fullscreen mode

Top comments (0)