How to Install and Use Homebrew on Linux

Homebrew is a free and open source package manager for Linux and macOS. Although several Linux distributions come with their own package managers, such as APT, DNF, Pacman, etc., to facilitate software installation, we recommend Homebrew on your system if you want to install programs that are not available in the default Linux repository. distribution.


Let’s take a look at Homebrew and the steps to install and use it on Linux.

What is homebrew?

Homebrew is a package manager that makes it easy to install programs that aren’t available in the official Linux distro repositories. It contains over 5000 packages (also called “formulas”) and is perfect for installing Unix tools and other open source programs and utilities.

One of the advantages of using Homebrew is that its packages are better maintained than those available on other repositories. This means that you can install the latest versions of the programs even if you are running an older Linux distribution on your computer.

How to install Homebrew on Linux

Homebrew is easy to set up. Follow these instructions to install Homebrew on your Linux machine:

Step 1: Install the build tools

The first thing you need to do is install the build tools on your Linux machine. The compilation tools, for the uninitiated, are programs that facilitate the creation of packages on a Linux machine.

On Debian or Ubuntu, open the terminal and install the build-essential package and other dependencies using the following command:

sudo apt install build-essential procps curl file git

If you are using Fedora, CentOS or Red Hat, you can install build tools with:

sudo yum group install 'Development Tools'
sudo yum install procps-ng curl file git
sudo yum install libxcrypt-compat

To verify that the compiler is available, run this command:

which make

If this returns a path, it means you have a working compiler on your Linux box. Otherwise, there is something wrong with the installation, in which case you need to repeat the installation process.

Step 2: Install Homebrew on Linux

With the build tools in place, all you need to do now to install Homebrew is run the installation script. Open the terminal and run this command to do this:

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

When prompted to continue the installation, press log intoand the script will start downloading and installing Homebrew on your system. Wait a few minutes for the installation to complete.

As soon as it’s done, you’ll see the installation was successful message on the terminal, along with a section called Next steps which tells you what you need to do next before you can start using Homebrew.

Here you will see two commands to add Homebrew to your PATH. Copy these and run them one by one below. Here’s what these commands look like:

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

We need to set the PATH for Homebrew so that the shell can find it when you call it to install, upgrade, or delete packages, regardless of your current working directory.

How to use Homebrew on Linux

With Homebrew installed, you can now use it to install, update, and delete existing Homebrew packages on your Linux machine. Follow the instructions in the following sections to perform these operations.

1. Installing a package using Homebrew

Before jumping and installing a package using Homebrew, you must first update Homebrew and all of its package definitions. Open the terminal and run this command to do this:

brew update

Since you’ve just installed Homebrew, it’s likely already up to date, but it’s always a good practice to do this before installing a new package.

Now, if you are following an online guide to install a package, you would be sure that the package is present on Homebrew and, therefore, you can install it right away. However, if you are unsure, you can search for the package to verify that Homebrew has it by running:

brew search package_name

For example, to search if htop is available in the Homebrew repositories, enter:

brew search htop

Finally, to install the package, use:

brew install package_name

For instance:

brew install htop

2. Upgrading a Homebrew Package

Over time, as you use a program, it will receive new updates with bug fixes, new features and other improvements. Since Homebrew does not automatically update (does not update) the packages themselves, you will have to do it manually.

But before updating a Homebrew package, you may want to check the version of a package to know exactly which version you are using. To do this, open the terminal and run the following command:

brew list --versions package_name

To check the versions available for the htop package:

brew list --versions htop

Now, if there is a new version for the package, you can update it like this:

brew upgrade package_name

For instance:

brew upgrade htop

Alternatively, if you want to update all Homebrew packages installed on your system at the same time, you can do so by running:

brew upgrade

3. Uninstalling a Homebrew package

If for some reason you no longer need a package on your computer, you can uninstall it, just like you do with traditional Linux package managers. To uninstall a package using Homebrew, run this command in the terminal:

brew uninstall package_name

How to uninstall Homebrew on Linux

Similar to the Homebrew installation process, uninstalling Homebrew also involves using a script, which automatically uninstalls the package manager from your Linux system.

Open the terminal and run this command to download and run the uninstall script:

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

As soon as the script finishes uninstalling Homebrew, it will list some files that were not removed during the uninstall process. You can remove these leftover files from the file manager or terminal as you see fit.

Other useful homebrew commands you should know about

While the commands discussed so far are pretty much all you need to know to use Homebrew on Linux, Homebrew also has a few other useful commands you should know. These include:

  1. help with preparation: Print various Homebrew commands with their use and purpose.
  2. brew help sub_command: It is useful when you want to learn more about a specific Homebrew command, including the options and usage available.
  3. beer doctor: Check your system for any potential problems and list them so you can fix them and avoid running into problems when using Homebrew.
  4. obsolete beer: It is used to list all Homebrew packages on your system that are out of date and need to be updated.
  5. beer brooch package_name: It allows you to specify a Homebrew package to prevent it from being updated when you run the brew upgrade command on your system. Later, if you want to unlock the package, Homebrew will update it along with all other packages.
  6. beer cleaning: It is used to clean up old package versions on the system and other related data.


Install your favorite programs on Linux with Homebrew

Now that you’ve installed Homebrew and have an idea of ​​how to use it for installing new packages, you can easily find and install programs that wouldn’t otherwise be available through traditional Linux package managers on your computer.

If you are a budding programmer, Homebrew can come in very handy for you, as you can install several CLI tools on your system using it effortlessly. Likewise, while you’re at it, you may also want to check out the Git installation and configuration to familiarize yourself with a version control system.

Leave a Comment