This article explains everything you need to know about Homebrew for Linux and how to install it in the simplest way!
What Is Homebrew for Linux?
Homebrew is a free and open-source software package management system that makes software installation easier on macOS and Linux. It was first designed for macOS and is praised for its user-friendliness and seamless integration with the command-line interface.
Homebrew for Linux serves as a package manager that was initially created for macOS, allowing users to install free and open-source software via the terminal. Linux systems typically use their built-in package managers, such as apt on Debian, Ubuntu, and their derivatives, as well as dnf on Red Hat, Fedora, and Rocky Linux, to install applications and tools from reliable and well-maintained package repositories.
Its benefits:
- We can set up Homebrew for Linux in our home directory, allowing us to install software there without needing sudo access.
- We have the ability to install software that isn’t available in the repositories of our Linux distribution.
- We can obtain the most recent versions of software, even if our distribution is outdated.
- We can utilize the same package manager across our macOS, Linux, and Windows systems.
- Now that we understand the features of Homebrew, let’s explore how to install it.
System Requirements for Installing Homebrew on Linux
To install build tools, paste at a terminal prompt:
Debian or Ubuntu
<code>sudo apt-get install build-essential procps curl file git</code>
Fedora
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
<code>sudo dnf group install development-tools sudo dnf install procps-ng curl file</code>
CentOS Stream or RHEL
<code>sudo dnf group install 'Development Tools' sudo dnf install procps-ng curl file</code>
Arch Linux
<code>sudo pacman -S base-devel procps-ng curl file git</code>
How to Use Homebrew to Install Packages on Linux
Step 1: Setting Up a Compiler Environment
Before you install Homebrew for Linux, you need a functioning compiler so that it can build packages. Although most packages come pre-compiled, some dependencies must be built on your machine. Most Linux distributions let you install a compiler with one command, but they don’t include one by default.
On Ubuntu, you can install a package named build-essential, which provides everything needed for a modern, well-supported compiler environment. Use apt to install the package:
sudo apt install build-essential
On Rocky Linux, CentOS, or other Red Hat-based systems, you can install a set of packages called Development Tools to get the same compiler capabilities. Use dnf to install the packages:
dnf groups mark install "Development Tools"<br>dnf groupinstall "Development Tools"
You can check if a compiler is available by searching for the ‘make’ command on your system. To do this, use the which command:
which make
Output/usr/bin/make
Now that you have a working compiler, you can move on to installing Homebrew.
Step 2: Installing and Configuring Homebrew
To install Homebrew for Linux, you will download an installation script and run it.
First, download the script to your local machine:
curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
This command uses curl to bring the Homebrew installation script from its GitHub repository.

Let’s go over the flags used with the curl command:
- The -f or– fail flag tells the shell not to output an HTML document on server errors.
- The -s or– silent flag silences curl so it doesn’t display the progress meter, and when combined with the -S or –show-error flag, it ensures that curl shows an error message if it fails.
- The -L or –location flag instructs curl to follow redirects. If the server indicates that the requested page has moved, it will automatically follow the new location.
Before executing a script you downloaded from the Internet, review its contents to understand its function. Use the less command to check the installation script so you know what it will do.
less install.sh
Once you are satisfied with the script’s contents, run it using the bash command:
/bin/bash install.sh
The installation script will detail its actions and ask for your confirmation to proceed. This informs you about what Homebrew will do to your system before it continues. It also checks that you have the necessary prerequisites in place.
During the installation process, you will be prompted to enter your password. If you do not have sudo privileges, you can press Ctrl+D to skip this prompt. This will allow Homebrew to install with limited permissions.
For more information about this option, check out Homebrew’s documentation.
Press the letter y for “yes” whenever you are asked to confirm the installation.
After installation, Homebrew will show you how to configure your shell environment to prioritize its tools over the system package manager. Copy the commands from the output to find the correct configuration paths for your system. Here’s an example for bash:example for bash:
Output<br>==> Next steps:Execute these two commands in your terminal to add Homebrew to your PATH:<br>echo 'eval "$(/home/sammy/.linuxbrew/bin/brew shellenv)"' >> /home/sammy/.profile<br>eval "$(/home/sammy/.linuxbrew/bin/brew shellenv)"<br>Once you run these two commands, the changes to your shell’s PATH environment variable will take effect. They will be set correctly when you log in again in the future, as the configuration file for your shell runs automatically when you start a new session.
Now check that Homebrew is set up correctly. Use this command:
brew doctor
If no updates are needed at this moment, you’ll see the following output:
Output<br>Your system is ready to brew.
Step 3: Installing, Upgrading, and Removing Packages
Now that Homebrew is set up, you can use it to download a package. The tree command allows you to view a graphical directory tree and can be installed through Homebrew.
To install tree, use the brew install command:
brew install tree
Homebrew will refresh its package list and then download and install the tree command:
Output<br>. . .<br>==> 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 in /home/linuxbrew/.linuxbrew/bin/ by default, so they won’t conflict with future Linux updates. To check if tree is installed, use the which command to display its location:
which tree
The output will show that tree is in /home/linuxbrew/.linuxbrew/bin/:
Output<br>/home/linuxbrew/.linuxbrew/bin/tree
To see the version of tree, run the command:
tree --version
The version will be displayed on the screen, confirming it’s installed:
Output<br>tree v2.0.2 (c) 1996 - 2022 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
Sometimes, you may want to upgrade an existing package. Use the brew upgrade command followed by the package name:
brew upgrade tree
You can also run brew upgrade without any arguments to upgrade all programs and packages managed by Homebrew.
When you install a new version, Homebrew for Linux keeps the previous version. After some time, you might want to free up disk space by removing these older versions. Use brew cleanup to delete all old versions of your Homebrew-managed software.
You might want to remove a package you no longer need; use ‘brew uninstall’. To uninstall the tree command, type this command:
brew uninstall tree
The output will confirm that the package has been removed:
Output<br>Uninstalling /home/linuxbrew/.linuxbrew/Cellar/tree/2.0.2… (8 files, 162.4KB)<em><br></em><br>
Step 4: Getting Rid of Homebrew for Linux
If you’ve decided you don’t need Homebrew for Linux anymore, you can run its uninstall script.
Grab the uninstall script using curl:
curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
Don’t forget to check out the script’s contents with the less command to make sure it’s all good:
less uninstall.sh
After you’ve confirmed the script looks okay, run it with the –help flag to see the different options available:
bash uninstall.sh --help
You’ll see the options pop up on your screen:
Output<br>Homebrew Uninstaller<br>Usage: uninstall.sh [options]<br>-p, --path=PATH Sets the Homebrew prefix. Defaults to /usr/local.<br>--skip-cache-and-logs<br>Skips the removal of HOMEBREW_CACHE and HOMEBREW_LOGS.<br>-f, --force Uninstall without asking for confirmation.<br>-q, --quiet Suppress all output messages.<br>-d, --dry-run Simulate the uninstall process without actually removing anything.<br>-h, --help Show this help message.
Use the -d flag to preview what the script will do:
bash uninstall.sh -d
The script will show you everything it plans to delete:
Output<br>Warning: This script would remove:<br>/home/linuxbrew/.linuxbrew/Caskroom/<br>/home/linuxbrew/.linuxbrew/Cellar/<br>/home/linuxbrew/.linuxbrew/Homebrew/<br>/home/linuxbrew/.linuxbrew/Homebrew/.dockerignore<br>/home/linuxbrew/.linuxbrew/Homebrew/.editorconfig<br>. . .<br>When you’re all set to delete everything, just run the script without any flags:
bash uninstall.sh
This will uninstall Homebrew along with any programs you’ve installed through it.
Conclusion
In conclusion, we learnt how to install Homebrew for Linux. Additionally, we explored some of its features. Now, we can effortlessly install Homebrew packages on our Linux system.
Given its ease of use and versatility, Homebrew is an essential tool for any workflow, regardless of whether you’re a system administrator, developer, or casual Linux user. You can easily begin exploring, installing, and managing packages now that it’s installed.
FAQ’s
1. Is it possible to install Homebrew on any Linux distribution?
Yes, Homebrew for Linux is compatible with most modern Linux distributions, such as Ubuntu, Debian, Fedora, and Arch. However, you must ensure that your system meets the basic requirements, like bash, curl, git, and procps, before you install it.
2. Is root access required to install Homebrew on Linux?
No, you do not need root (sudo) access to install Homebrew. It installs by default in the user’s home directory (~/.linuxbrew) and does not require any system-wide changes.
3. What is the process to update or uninstall Homebrew on Linux?
You can update Homebrew by executing brew update in the terminal. To uninstall it, you can either run the official uninstall script from Homebrew’s GitHub repository or manually delete the .linuxbrew directory along with its configuration files.
4. My Mac apps can’t locate Homebrew utilities. What should I do?
GUI applications on macOS do not include Homebrew’s prefix in their PATH by default. If you are using Mountain Lion or a newer version, you can resolve this issue by executing sudo launchctl config user path “$(brew –prefix)/bin:${PATH}” and then restarting your computer, as explained in man launchctl. Keep in mind that this modifies the launchctl PATH for all users.