Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
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.
Its advantages include:
Now that we know about Homebrew’s features let’s learn how to install it.
Before installing Homebrew, we need to install its 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.
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.
Now that we’ve installed Homebrew, we can use it to manage packages.
To install a Homebrew package, we can run brew install:
$ brew install gcc
The above command will install the gcc package.
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
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.
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.
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.