How to Install Homebrew in Linux

October 20, 2022

Introduction

Homebrew is a package manager originally developed for macOS to provide users with a convenient way to install Linux applications. After the tool gained popularity for its large selection of applications and ease of use, Homebrew developers created a native Linux version.

This tutorial shows you how to install Homebrew in Linux. It also covers the steps to find, install, and manage applications using Homebrew.

How to install Homebrew in Linux.

Prerequisites

  • A system running Linux.
  • Administrative access to the system.
  • Git installed.

How to Install Homebrew for Linux

Installing Homebrew on a Linux distribution involves checking for dependencies and running an installation script. The sections below cover the installation in more detail and provide basic commands for application management in Homebrew.

Step 1: Install Package Dependencies

Homebrew uses a compiler to build packages. Most Linux systems come with a compiler preinstalled, along with the make command, which assists in the compilation process.

1. To check if make is installed, type:

make --version

The output shows the installed version of the GNU Make utility.

The output showing the version of GNU Make.

2. If the make utility does not exist on the system, install it with the following command:

sudo apt install build-essential

The build-essential package contains GNU Make and other packages necessary for the compiler to work correctly.

Installing the build-essential package in Ubuntu.

3. Type Y and press Enter to finish the installation process.

Note: On Rocky Linux, CentOS, and other related distributions, the package containing the compiling tools is called Development Tools. To install it, type:

dnf groups mark install "Development Tools"

Then execute the groupinstall command:

dnf groupinstall "Development Tools"

Step 2: Download and Execute Homebrew Installation Script

After installing the dependencies, proceed to install Homebrew itself.

1. Visit the official Homebrew website.

2. Copy the command in the Install Homebrew section by clicking the button on the right side of the command text box.

The location of the installation command on the official Homebrew website.

Below is the installation command available at the time of writing this article:

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

3. Execute the command in a terminal window. Press Enter to confirm and wait for the installation to complete.

Executing the Homebrew install script in Linux.

4. After the installation, set the path for Homebrew. Use the command below to add the path to the .profile in your home directory:

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/marko/.profile

5. Next, execute the following command:

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

Step 3: Verify the Homebrew Installation

Check if Homebrew installed correctly by using the doctor command:

brew doctor

The output confirms the installation was successful.

Using brew doctor to test the Homebrew installation.

Manage Homebrew Packages

Homebrew installs packages by referring to their package definitions called formulae. Update the list of available formulae by running:

brew update
Updating Homebrew formulae.

If necessary, perform upgrades with the following command.

brew upgrade
Upgrading Homebrew formulae.

Alternatively, upgrade a specific formula by referring to it in the command:

brew upgrade [formula]

Follow the steps below to search, install, test, and uninstall a Homebrew formula.

1. Search for an application using brew search. The example below searches for the htop interactive process viewer:

brew search htop

If the application formula exists, the output displays its name:

Searching for a Homebrew formula.

2. Install htop by typing:

brew install htop

Homebrew reads the package formula and installs the tool alongside its dependencies.

Installing a Homebrew formula.

3. Test the installation by running htop:

htop

The list of system processes appears on the screen.

The htop interactive process viewer.

4. Use the witch command to confirm that you are using the application version installed by Homebrew.

which htop

The output displays the Homebrew path.

Checking the installation path of the application.

5. To uninstall a package, use the brew uninstall command. For example:

brew uninstall htop
Uninstalling a Homebrew formula.

How to Uninstall Homebrew

If you wish to remove Homebrew from your system, uninstall it by following the steps below:

1. Visit the Homebrew GitHub repository.

2. Copy the command listed in the Uninstall Homebrew section.

The Uninstall Homebrew section in the official Homebrew GitHub repository.

Below is the current version of the command:

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

3. Execute the command in a terminal window. When prompted, confirm that you want to uninstall Homebrew by typing Y and pressing Enter.

Running the Homebrew uninstall script in Linux.

The script removes Homebrew from your system. Refer to the output for the list of files you need to remove manually.

Conclusion

After reading this tutorial, you should know how to install and use Homebrew on a Linux distribution. For the macOS tutorial, read How to Install Homebrew on Mac.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How to use apt Package Manager on Ubuntu Linux
October 20, 2022

Linux operating systems use a software tool known as a package manager to ensure the software is correctly installed and up-to-date.
Read more
How to Uninstall or Remove Software Packages From Ubuntu
May 23, 2024

This tutorial will walk you through several methods for removing software packages from...
Read more
How to Install RPM Packages on Ubuntu
March 28, 2024

It is possible to install .rpm files on Debian based distributions like Ubuntu. However, you need to be careful as it could lead to package dependency conflicts.
Read more
Flatpak vs. Snap vs. AppImage
June 8, 2022

Distribution-independent package formats work on every Linux system because they bundle the application with all its required dependencies. Snap, Flatpak, and AppImage are some...
Read more