How to install Homebrew on Ubuntu 22.04

Endrit Qerreti

Endrit Qerreti

Homebrew is a package manager that you can use on MacOS and Linux to manage packages on your system.

Homebrew in MacOS is like apt in Ubuntu, both can download and install packages on the system easily without having to download dependencies manually.

Homebrew is very easy to install on Ubuntu, as Homebrew provides an installation script that you can run on your machine, and to install Homebrew with a single command line in your terminal.

In this tutorial, you will learn how to install Homebrew on Ubuntu 22.04.

Step 1 - Install Dependencies

Before installing Homebrew on your Ubuntu machine, you need to install the required dependencies that Homebrew will need in order to run.

To install Homebrew dependencies, run the following

sudo apt-get install build-essential procps curl file git

Step 2 - Download Homebrew setup

Homebrew provides a shell script that will install Homebrew on your machine. This script needs to be downloaded on your machine, and then you can use it to install Homebrew.

1) First download The installation script

To download the installation script, you can use curl or wget. However, in this tutorial, we are using curl to download Homebrew installation script

curl -fsSL -o install-homebrew.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh

2) Make installation script executable

Once you have downloaded Homebrew installation script on your machine, this script by default won't be able to execute without giving it execute permissions. To make this file executable, run the command below

chmod +x install-homebrew.sh

Step 3 - Install Homebrew

Now you can proceed to install Homebrew. To install Homebrew, all you have to do is run the installation script that you downloaded on your machine.

./install-homebrew.sh

Next, you will be prompted with the following prompt. Press enter to proceed installing Homebrew

Once Installed, you will see "Installation successful" on your terminal.

Step 4 - Add Homebrew to Path

To be able to use Homebrew, you need to add Homebrew into your Path. To do this, simply run the commands below

(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/owlhowto/.bashrc 
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

Make sure to replace /home/owlhowto with your home path.

Step 5 - Use Homebrew

Once Homebrew is installed on your machine, you should be able to use it now.

Below we'll cover some of the most common commands that you should know when using Homebrew

Install a package with Homebrew

To install a package with Homebrew is very easy, the syntax of doing this is as below

brew install package-name

Replace package-name with the package name that you want to install on your system

Update a package with Homebrew

Updating a package that you already installed with Homebrew, then you can do so by running the update command

brew update package-name

Uninstall a package with Homebrew

To uninstall a package with Homebrew, use the uninstall command

brew uninstall package-name

Conclusion

In this tutorial, you learned how to install Homebrew on Ubuntu 22.04, and also how to use Homebrew to install, update, uninstall packages on your system.