How to Install Homebrew on Ubuntu 24.04

Homebrew or brew is an open-source package manager primarily used by the macOS systems. With Homebrew, you can install, update, manage and remove applications from the system through the terminal. The advantage of using Homebrew is that it will automatically install dependencies needed to run the package. Thus, you don’t need to manually download packages separately on the system. 

Ubuntu 24.04 is the latest Ubuntu LTS release that uses the default apt package manager to install packages on the system. However, if you want to use Homebrew as an external package manager for your Ubuntu system, you can do it easily. 

This guide will cover all about:

How to Install Homebrew on Ubuntu 24.04

You can install Homebrew on Ubuntu 24.04 using the following steps:

Step 1: Install curl on Ubuntu

For Homebrew installation, first install curl command line utility on Ubuntu using the following command:

sudo apt install curl -y
Install Homebrew on Ubuntu 24.04 a

Step 2: Download and Run Brew Installation Script

Next, download and execute the Homebrew installation script on Ubuntu using the below-given command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install Homebrew on Ubuntu 24.04

During the script execution, press Enter to continue installing Homebrew on Ubuntu system:

Install Homebrew on Ubuntu 24.04 c

Wait for the Homebrew installation to be completed:

Install Homebrew on Ubuntu 24.04 d

Step 3: Finalize the Homebrew Installation

To finalize the Homebrew installation, wait for the script to end, then complete some additional steps for a successful installation of brew on Ubuntu. These steps will appear right before the completion of the script and include multiple commands that need to be executed one by one on the terminal. It is done so that the system will know the PATH where Homebrew is installed on Ubuntu:

Install Homebrew on Ubuntu 24.04 f

The first command will add the Homebrew PATH to the .bashrc file so that the system will know the location where Homebrew is placed on the system. The command can be copied from the output of the above script and is similar to the one provided below except for the username, which is ubuntu in our case:

(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/ubuntu/.bashrc
Install Homebrew on Ubuntu 24.04 g

The second command is to set the necessary environment variables for Homebrew to function properly on the system, which is given below:

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Install Homebrew on Ubuntu 24.04 h

Step 4: Confirm Homebrew Installation

After you done the changes mentioned above, close and reopen the terminal, then run the below-given command to confirm Homebrew is successfully installed on Ubuntu:

brew --version
Install Homebrew on Ubuntu 24.04 i

Or, you can use the brew doctor command to ensure Homebrew is successfully running on Ubuntu:

brew doctor
Install Homebrew on Ubuntu 24.04 j

How to Use Homebrew on Ubuntu 24.04

You can use Homebrew to install packages on Ubuntu using the following syntax:

brew install package_name

Here, replace package_name with the name of the package you want to install on Ubuntu through Homebrew. As an example, we are installing gcc compiler on Ubuntu 24.04 through brew using the following command:

brew install gcc
Install Homebrew on Ubuntu 24.04 p

Once completing the gcc installation through brew on Ubuntu, use the following command to confirm the installation:

gcc --version
Install Homebrew on Ubuntu 24.04 q

You can also update the application or package version through brew using the following syntax:

brew upgrade application or package_name

Here, the following command will upgrade the gcc package thorough brew if there is any update available:

brew upgrade gcc
Install Homebrew on Ubuntu 24.04 r

You can also remove an application or package from brew on Ubuntu using the below-given command:

brew uninstall application or package_name

The following command will uninstall the gcc package from brew on Ubuntu:

brew uninstall gcc
Install Homebrew on Ubuntu 24.04 s

Additional Method: How to Install Homebrew on Ubuntu 24.04 from Git Clone 

You can also install Homebrew on Ubuntu 24.04 by cloning the Git repository, it can be done using the following steps:

Step 1: Clone Homebrew Git Repository

First, download the Homebrew Git repository on Ubuntu using the following command:

git clone https://github.com/Homebrew/brew homebrew
Install Homebrew on Ubuntu 24.04 t

Step 2: Add Homebrew Cloned Directory to System PATH

Then execute the below-given command to clone the Homebrew directory to the system path:

eval "$(homebrew/bin/brew shellenv)"
Install Homebrew on Ubuntu 24.04 v

Step 3:Confirm Homebrew Installation

To confirm Homebrew is successfully installation on Ubuntu, use the below-given command:

brew --version
Install Homebrew on Ubuntu 24.04 w

Step 4: Set Permission for Homebrew 

Ensure to add write permission to the specified directory on Ubuntu so that brew will save the data, it can be done using the following command:

chmod -R go-w "$(brew --prefix)/share/zsh"
Install Homebrew on Ubuntu 24.04 aa

How to Update Homebrew on Ubuntu 24.04

Updating the Homebrew version on Ubuntu is pretty simple and can be done using the brew update command provided below:

brew update
Install Homebrew on Ubuntu 24.04 bb

The brew update command will search for the update and if available, it will update the Homebrew to the latest version.

How to Remove Homebrew from Ubuntu 24.04

If you have installed Homebrew on Ubuntu 24.04 from the curl method, then first download the uninstallation script using the following command:

curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
Install Homebrew on Ubuntu 24.04 cc

Then run the script using bash command followed by the script name:

bash uninstall.sh
Install Homebrew on Ubuntu 24.04 dd

Reply with y to uninstall Homebrew from Ubuntu:

Install Homebrew on Ubuntu 24.04 qq

Then open the .bashrc file using nano editor through the following command, remove the highlighted Homebrew PATH line and save the file:

sudo nano .bashrc
Install Homebrew on Ubuntu 24.04 ww

This completes the uninstallation of Homebrew on Ubuntu 24.04.

Note: We have removed the PATH from the .bashrc file so that the system will not be able to detect the removed PATH.

If you have installed Homebrew from Git clone method, simply remove the Homebrew folder from the system using the rm command to complete the Homebrew uninstallation:

sudo rm -rf homebrew
Install Homebrew on Ubuntu 24.04 gg

Conclusion

Homebrew is a powerful package manager used in Mac systems, however it can also be installed on Linux systems, including Ubuntu 24.04. This guide has covered two methods to install Homebrew on Ubuntu 24.04. The first method is using the curl utility to download and run the Homebrew installation script on Ubuntu. The other method is to clone the Git repository and execute the eval command to add Homebrew cloned folder to system path. You will also find methods to use, update and remove Homebrew from Ubuntu, making it easier for you to work with it.