How to install and use Homebrew on Linux

Homebrew is a free and open source package manager for Linux and macOS. Although different Linux distributions come with their own package managers, such as APT, DNF, Pacman, etc., to make installing software easier, you’ll want Homebrew on your system if you want to install programs that aren’t available on the default Linux. distribution repositories.

Let’s 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 are not available in the official Linux distribution repositories. It contains over 5,000 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 in other repositories. This means that you can install the latest versions of 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 build tools

The first thing you need to do is install build tools on your Linux machine. Build tools, for the uninitiated, are programs that make it easy to create 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’re 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 machine. If not, there is something wrong with the installation, in which case you should go through the installation process again.

Step 2Install Homebrew on Linux

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

/bin/bash -c "$(curl -fsSL"

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

As soon as you’re done, you’ll see the Installation successful message in the terminal, along with a section called Next steps which tells you what to do next before you can start using Homebrew.

Here you will see two commands to add Homebrew to your PATH. Copy and run them one by one below. This is 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 it calls it to install, update, or remove packages, regardless of its current working directory.

How to use Homebrew on Linux

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

1. Install a package using Homebrew

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

brew update

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

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

brew search package_name

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

brew search htop

Finally, to install the package, use:

brew install package_name

For example:

brew install htop

2. Updating a Homebrew Package

Over time, as you use a program, you will receive new updates with bug fixes, new features, and other improvements. Since Homebrew doesn’t automatically update (update) the packages themselves, you’ll need to do this manually.

But before you update a Homebrew package, you may want to check the version of a package so you know exactly which version you’re running. To do this, open the terminal and run the following command:

brew list --versions package_name

To check the available versions 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 example:

brew upgrade htop

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

brew upgrade

3. Uninstall a Homebrew Package

If you no longer need a package on your computer for some reason, 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 the use of a script, which automatically uninstalls your Linux system’s package manager.

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

/bin/bash -c "$(curl -fsSL"

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 the terminal in any way you see fit.

Other Useful Home Commands You Should Know

Although the commands discussed so far are pretty much everything you need to know to use Homebrew on Linux, Homebrew also has some other useful commands you should know. These include:

  1. prepare help: Print various Homebrew commands with their use and purpose.
  2. prepare help sub_command: It’s useful when you want more information about a specific Homebrew command, including available options and usage.
  3. brew doctor: Checks your system for possible problems and lists them, so you can fix them and avoid 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. brew pin package_name: Allows you to specify a Homebrew package to prevent from being upgraded when you run the brew upgrade command on your system. Later, if you want to unpin the package, Homebrew will update it along with all other packages.
  6. beer cleaning: It is used to clean up old versions of packages on your 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 to install new packages, you can easily find and install programs that aren’t otherwise available through traditional Linux package managers on your machine.

If you are a budding programmer, then Homebrew can come in very handy as you can install different CLI tools on your system effortlessly. Likewise, while you’re at it, you can also refer to Git installation and configuration to get familiar with a version control system.

Leave a Comment