1. Overview
Homebrew is a free and open-source software package management system that simplifies software installation on macOS and Linux. It was initially created for macOS and has been recommended for its ease of use as well as its integration into the command-line interface.
In this tutorial, we’ll learn how to install and use Homebrew on Linux. In addition, we’ll discuss some of its advantages.
2. Advantages of Using Homebrew
Its advantages include:
- Since we can install Homebrew in the home directory and it can install software to the home directory, we don’t need sudo to run it
- We can install software that is not found in our Linux distro’s repositories
- We can install the latest versions of software even when our distro is old
- We can use the same package manager to manage our macOS, Linux, and Windows systems
Now that we know about Homebrew’s features let’s learn how to install it.
3. Installing Homebrew
Before installing Homebrew, we need to install its dependencies.
3.1. Installing Dependencies
We need to install build-essential which provides necessary packages that brew needs for building packages.
To install it on Ubuntu/Debian, we can run this:
$ sudo apt-get install build-essential procps curl file git
On Fedora, CentOS, and Red Hat:
sudo yum groupinstall 'Development Tools'
sudo yum install procps-ng curl file git
sudo yum install libxcrypt-compat # needed by Fedora 30 and up
Now we are ready to install Homebrew.
3.2. Installing Homebrew
To install Homebrew, we need to download its installation script and then run it using /bin/bash:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
==> Select a Homebrew installation directory:
- Enter your password to install to /home/linuxbrew/.linuxbrew (recommended)
- Press Control-D to install to /home/user/.linuxbrew
- Press Control-C to cancel installation
[sudo] password for user:
After running the script, it’ll ask us to enter our password. After that, it’ll begin installing Homebrew.
Now we need to add Homebrew to the PATH environment variable:
$ echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.bash_profile
$ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Finally, let’s make sure it’s properly installed:
$ brew doctor
Your system is ready to brew.
We’ve successfully installed Homebrew.
4. Managing Homebrew Packages
Now that we’ve installed Homebrew, we can use it to manage packages.
4.1. Installing Packages
To install a Homebrew package, we can run brew install:
$ brew install gcc
The above command will install the gcc package.
4.2. Removing Packages
To remove a Homebrew package, we can run:
$ brew remove gcc
This will remove gcc from our system. We can also run autoremove afterward to remove the dependencies that are no longer needed:
$ brew autoremove
4.3. Upgrading Packages
We can upgrade a single package by specifying its name after brew upgrade:
$ brew upgrade gcc
Warning: gcc 11.3.0_2 already installed
Since we had already installed the latest version of gcc, it showed a warning.
We can also upgrade all Homebrew packages by running it without a package name:
$ brew upgrade
Since all our Homebrew packages were up to date, it didn’t do anything.
5. Uninstalling Homebrew
To uninstall Homebrew, we can download the uninstallation script and run it using /bin/bash:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
After its removed, it lists some leftover files that we no longer need:
==> Homebrew uninstalled!
The following possible Homebrew files were not deleted:
/home/linuxbrew/.linuxbrew/bin/
...
/home/linuxbrew/.linuxbrew/share/
You may wish to remove them yourself.
We can manually remove them later.
6. Conclusion
To sum up, we learned how to install and use Homebrew on Linux. And, we learned about some of its features. So, we can now easily install Homebrew packages on our Linux system.