Homebrew (or just “Brew”) is a package manager that is well known as the go-to package management tool for MacOS, but it also works on Linux systems. It has been providing Apple users with a means of installing Linux packages on their devices for many years now, and the development has since expanded it into a tool for Linux as well. Homebrew is free and open source, and its big catalog of installable software has made it an attractive supplement to built in package managers such as apt and dnf on some systems.
In this tutorial, we will go over the step by step instructions to install Brew on all major Linux distros. Then, we will go over a few commands and examples to help you get started installing packages with the Homebrew package manager.
In this tutorial you will learn:
- How to install Homebrew prerequisites git, curl, make, etc.
- How to install Homebrew on all major Linux distros
- How to search for, install, update, and remove a Brew package
- How to uninstall Homebrew from Linux
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to Install and Use Brew on Linux step by step instructions
The process of installing Homebrew will be a little different depending on your Linux distribution. But after you have it successfully installed, the usage examples should be the same across all systems. The step by step instructions below will cover the process for all modern and major Linux distros.
- Get started by opening a terminal and using the appropriate commands below to install the prerequisite packages for Homebrew with your system’s package manager.
$ sudo apt update $ sudo apt install build-essential curl git
$ sudo dnf groups mark install "Development Tools" $ sudo dnf groupinstall "Development Tools" $ sudo dnf install curl git
$ sudo pacman -Sy base-devel curl git
- Once the prerequisite packages are done installing, we can run the following one liner which will download and execute the Homebrew install script. This is the same line of code as shown on the Homebrew official website and installation instructions.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- The Homebrew script will run some quick checks and then display a summary of the files and paths it is about to create. The next part will take a litle while, as everything needs to be downloaded and compiled (do not worry, the process is done for you). If you can spare a few minutes and are ready to proceed, hit
- Once Homebrew is done installing, there is still one more thing we need to do in order to start using it, which is adding the executable to our PATH environment variable. Execute the following two commands to do that:
$ echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.profile $ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
- Next, we can run the following command to make sure that Homebrew has been successfully installed and can start being used to download and manage packages:
$ brew doctor Your system is ready to brew.
You should receive the output shown above if everything is working as expected.
- Now we are ready to get started with installing a package via Homebrew. You can use the
searchoption to find a program you want to install. In this example we will look for wget:
$ brew search wget
Homebrew calls software packages “Formulae.” These are just installable software packages that have been packaged with Brew and uploaded to their central repository. Our screenshot above shows three formulae that match our search criteria: wget, wgetpaste, and west. Like other modern package managers, Homebrew will automatically fetch and install dependency packages for us.
- Next, let’s install the wget package we searched for with the
$ brew install wget
- The program you installed should now be accessible. We can use the
whichcommand to verify that our system is now using the executable file that Brew installed, instead of some other system package (for example, one that was installed via
dnf, or came pre installed on the system by default).
$ which wget /home/linuxbrew/.linuxbrew/bin/wget
Note: For common programs like
wget, it is possible to have Brew’s version installed alongside some other one. We can still access our system’s ordinary
wgetbinary by specifying it directly:
- To uninstall a package in Brew, use the
removeargument and specify the package name:
$ brew remove wget
- To update all of your currently installed formulae:
$ brew upgrade
Or to upgrade an individual formula to the latest version:
$ brew upgrade wget
- In case you get sick of Homebrew and want to uninstall it in the future, the process is very simple because we can execute the following Bash script:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
In this tutorial, we saw how to install Homebrew on a Linux system. We also saw basic
brew commands that we can use to get started with searching for, installing, and removing formulae (software packages) via Homebrew. Homebrew makes for a great alternative package manager to an official one, and it performs very quickly and boasts a respectable software repository full of useful applications and commands. For more Homebrew usage instructions, check out the official FAQ page.