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.
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.
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.
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.
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.
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.
Manage Homebrew Packages
Homebrew installs packages by referring to their package definitions called formulae. Update the list of available formulae by running:
brew update
If necessary, perform upgrades with the following command.
brew upgrade
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:
2. Install htop by typing:
brew install htop
Homebrew reads the package formula and installs the tool alongside its dependencies.
3. Test the installation by running htop:
htop
The list of system processes appears on the screen.
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.
5. To uninstall a package, use the brew uninstall
command. For example:
brew uninstall htop
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.
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.
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.