Homebrew is a package manager that was originally developed for macOS to let you install free and open-source software using your terminal. Linux systems all make use of their own built-in package managers, such as apt
on Debian, Ubuntu, and derivatives, and dnf
on Red Hat, Fedora, and Rocky Linux, to install programs and tools from trusted and maintained package repositories.
However, it is not always practical to install all software via apt
or dnf
. For example, some programming languages prefer to use their own package managers, such as Python’s pip
, or Node.js’ npm
to install additional scripts or libraries that are localized to your own user account.
More recently, Homebrew has added native support for Linux. While Homebrew was originally created to install Linux tools on macOS, many Homebrew packages are better maintained or more convenient to use than the equivalent packages available in Linux repositories. Also, since Homebrew packages are designed to only provide per-user functionality, Homebrew can be used alongside your system package manager without creating conflicts.
In this tutorial you’ll install and use Homebrew in a Linux environment. You’ll install system tools and configure your shell environment to use Homebrew from the command line interface.
A Linux server or desktop environment, and a non-root user with sudo privileges. You can learn more about how to set up a user with these privileges in our Initial Server Setup with Ubuntu 20.04 guide.
The version control tool git
installed on your machine. You can refer to How To Install Git on Ubuntu 20.04 on Linux specifically, or follow the official Git documentation on another platform.
Before installing Homebrew, you will need a working compiler so that Homebrew can build packages. While most packages are pre-compiled, some package dependencies will need to be built directly on your machine. Most Linux distributions allow you to install a compiler with a single command, but do not provide one by default.
On Ubuntu, you can install a package called build-essential
that will provide all the packages needed for a modern, well-supported compiler environment. Install the package with apt
:
- sudo apt install build-essential
On Rocky Linux, CentOS, or other RedHat derivatives, you can install a group of packages called Development Tools to provide the same compiler functionality. Install the packages with dnf
:
- dnf groups mark install "Development Tools"
- dnf groupinstall "Development Tools"
You can verify that a compiler is available by checking for the existence of the make
command on your system. In order to do that, use the which
command:
- which make
Output/usr/bin/make
Now that you have a working compiler, you can proceed to install Homebrew.
To install Homebrew, you’ll download an installation script and then execute the script.
First, download the script to your local machine:
- curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
The command uses curl
to download the Homebrew installation script from Homebrew’s Git repository on GitHub.
Let’s walk through the flags that are associated with the curl
command:
f
or --fail
flag tells the shell to give no HTML document output on server errors.-s
or --silent
flag mutes curl
so that it does not show the progress meter, and combined with the -S
or --show-error
flag it will ensure that curl
shows an error message if it fails.-L
or --location
flag will tell curl
to handle redirects. If the server reports that the requested page has moved to a different location, it’ll automatically execute the request again using the new location.-o
switch specifies a local filename for the file. Rather than displaying the contents to the screen, the -o
switch saves the contents into the file you specify.Before running a script you’ve downloaded from the Internet, you should review its contents so you know what the script will do. Use the less
command to review the installation script so you understand what it will do.
- less install.sh
Once you’re comfortable with the contents of the script, execute the script with the bash
command:
- /bin/bash install.sh
The installation script will explain what it will do and will prompt you to confirm that you want to do it. This lets you know exactly what Homebrew is going to do to your system before you let it proceed. It also ensures you have the prerequisites in place before it continues.
You’ll be prompted to enter your password during the process. If you do not have sudo
privileges, you can press Ctrl+D
instead to bypass this prompt, and Homebrew will be installed with more restrictive permissions. You can review this option in Homebrew’s documentation.
Press the letter y
for “yes” whenever you are prompted to confirm the installation.
When complete, Homebrew’s installer output will also include Next steps
in order to configure your shell environment for working with Homebrew packages. This configuration ensures that Homebrew’s tools will be used in favor of the tools provided by the system package manager. Copy and paste commands from your output, which will detect the correct configuration paths on your system. The below example is from bash
:
Output==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
echo 'eval "$(/home/sammy/.linuxbrew/bin/brew shellenv)"' >> /home/sammy/.profile
eval "$(/home/sammy/.linuxbrew/bin/brew shellenv)"
Once you run these two commands, the changes you have made to your shell’s PATH
environment variable will take effect. They’ll be set correctly when you log in again in the future, as the configuration file for your shell is run automatically when you open a new session.
Now verify that Homebrew is set up correctly. Run this command:
- brew doctor
If no updates are required at this time, you’ll receive the following output:
OutputYour system is ready to brew.
Otherwise, you may get a warning to run another command such as brew update
to ensure that your installation of Homebrew is up to date. Follow any on-screen instructions to finish configuring your environment before moving on.
Now that Homebrew is installed, use it to download a package. The tree
command lets you see a graphical directory tree and is available via Homebrew.
Install tree
with the brew install
command:
- brew install tree
Homebrew will update its list of packages and then download and install the tree
command:
Output. . .
==> Downloading https://ghcr.io/v2/homebrew/core/tree/manifests/2.0.2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/tree/blobs/sha256:e1d7569f6930271d694e739e93eb026aac1e8b386
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:e1d7569f6930271d694e739
######################################################################## 100.0%
==> Pouring tree--2.0.2.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/tree/2.0.2: 8 files, 162.4KB
==> Running `brew cleanup tree`...
Homebrew installs files to /home/linuxbrew/.linuxbrew/bin/
by default, so they won’t interfere with future Linux updates. Verify that tree
is installed by displaying the command’s location with the which
command:
- which tree
The output shows that tree
is located in /home/linuxbrew/.linuxbrew/bin/
:
Output/home/linuxbrew/.linuxbrew/bin/tree
Run the tree
command to see the version:
- tree --version
The version prints to the screen, indicating it’s installed:
Outputtree v2.0.2 (c) 1996 - 2022 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
Occasionally, you’ll want to upgrade an existing package. Use the brew upgrade
command, followed by the package name:
- brew upgrade tree
You can run brew upgrade
with no additional arguments to upgrade all programs and packages Homebrew manages.
When you install a new version, Homebrew keeps the older version around. After a while, you might want to reclaim disk space by removing these older copies. Run brew cleanup
to remove all old versions of your Homebrew-managed software.
To remove a package you’re no longer using, use brew uninstall
. To uninstall the tree
command, run this command:
- brew uninstall tree
The output shows that the package was removed:
OutputUninstalling /home/linuxbrew/.linuxbrew/Cellar/tree/2.0.2... (8 files, 162.4KB)
If you no longer need Homebrew, you can use its uninstall script.
Download the uninstall script with curl
:
- curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
As always, review the contents of the script with the less
command to verify the script’s contents:
- less uninstall.sh
Once you’ve verified the script, execute the script with the --help
flag to see the various options you can use:
- bash uninstall.sh --help
The options display on the screen:
OutputHomebrew Uninstaller
Usage: uninstall.sh [options]
-p, --path=PATH Sets Homebrew prefix. Defaults to /usr/local.
--skip-cache-and-logs
Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.
-f, --force Uninstall without prompting.
-q, --quiet Suppress all output.
-d, --dry-run Simulate uninstall but don't remove anything.
-h, --help Display this message.
Use the -d
flag to see what the script will do:
- bash uninstall.sh -d
The script will list everything it will delete:
OutputWarning: This script would remove:
/home/linuxbrew/.linuxbrew/Caskroom/
/home/linuxbrew/.linuxbrew/Cellar/
/home/linuxbrew/.linuxbrew/Homebrew/
/home/linuxbrew/.linuxbrew/Homebrew/.dockerignore
/home/linuxbrew/.linuxbrew/Homebrew/.editorconfig
. . .
When you’re ready to remove everything, run the script without any flags:
- bash uninstall.sh
This removes Homebrew and any programs that you’ve installed with it.
In this tutorial you installed and used Homebrew in a Linux environment. You can now use Homebrew to install command line tools, programming languages, and other utilities that you’ll need for software development.
Homebrew has many packages you can install. Visit the official list to search for your favorite programs.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
For anyone wondering if they should give it a try
Homebrew on Linux can be a great addition, especially if you’re used to its simplicity on macOS or if you want an easy way to manage dependencies and tools. Here’s an overview of why you might want to use Homebrew on Linux, and a guide on how to install it.
Why Use Homebrew on Linux?
brew
). If you’re already familiar with Homebrew, this can make the transition to Linux smoother.Potential Downsides
apt
on Ubuntu ordnf
on Fedora), adding Homebrew may create redundancy.