How to install Homebrew on Ubuntu 24.04
You install Homebrew on Ubuntu 24.04 by running a single command in your terminal.
Homebrew is a popular package manager, originally from macOS, that simplifies installing and managing software on Linux. It allows you to easily get the latest versions of tools and applications.
On Ubuntu 24.04, Homebrew installs packages into your user’s home directory, like `/home/yourusername/.brew`, avoiding conflicts with the system’s `apt` package manager. This makes it perfect for developers needing specific or newer versions of software.
Before you begin, ensure you have `curl` and `git` installed by running: `sudo apt install curl git`.
Install Homebrew on Ubuntu 24.04 by running the official installation script: `/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”`. Follow the on-screen prompts, then add Homebrew to your PATH by running `eval “$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)”`.
Install Brew
Installing Homebrew on Ubuntu 24.04 is straightforward using the official setup script. You’ll download and run a single command that handles the entire installation process for you, making it easy to get started.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
When prompted during the script, hit Enter to install Homebrew to your home directory on Ubuntu.
After completing the Homebrew installation script, you’ll be prompted to run several commands on your terminal.
These commands are crucial for setting up Homebrew on Ubuntu and configuring your system. Use the first command to establish Homebrew in your `.bashrc` profile, replacing ‘richard‘ with your actual username.
Run this command to set up Homebrew in your `.bashrc` profile. Remember to replace ‘richard’ with your actual username.
Run this command in your terminal to add Homebrew to your PATH:
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/richard/.bashrc
To ensure that Homebrew functions correctly on your system, you need to set specific environment variables.
Run the command below to do that.
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Once Homebrew is installed and configured, you can check its version by running the command below.
brew --version
Run the brew doctor utility to ensure everything was set up correctly.
brew doctor
Before proceeding with the Git method, ensure you have Homebrew’s dependencies installed if you have `sudo` access:
sudo apt-get install build-essential
How to Install Homebrew with Git
You can also install Homebrew on Ubuntu using its source code straight from Git if you like. This method involves cloning the Homebrew Git repository and then setting it up so your system can find it.
To do that, download the Homebrew Git repository to your Ubuntu machine by running the command below.
git clone https://github.com/Homebrew/brew homebrew
Then, run the command below to add Homebrew into your system’s command-line environment.
eval "$(homebrew/bin/brew shellenv)"
Check the installed Homebrew version by running the command below.
brew --version
chmod -R go-w "$(brew --prefix)/share/zsh"
Use Homebrew
After you’ve successfully installed Homebrew on Ubuntu, using it to manage software is simple. You can install new programs with a single command, and it’s just as easy to update or remove them later.
brew install package_name
For example, to install the GCC package, run the command below.
brew install gcc
Replace install with upgrade to upgrade a package.
brew upgrade gcc
To uninstall a package, use the uninstall option with a command similar to the one below.
brew uninstall gcc
How to Remove Homebrew
Removing Homebrew from your Ubuntu machine is simple with its dedicated uninstall script. You just need to download the script and run it, and it will take care of removing Homebrew and cleaning up your system.
curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
Then, execute the script by running the command below.
bash uninstall.sh
When prompted, enter y for yes.
You’ll also want to remove the relevant line from your `.bashrc` file.
sudo nano .bashrc
Finally, delete the Homebrew folder.
sudo rm -rf homebrew
That should do it!
Conclusion:
In summary, installing Homebrew on Ubuntu can significantly enhance your development experience. Here are key points to remember:
- User-Friendly: Homebrew simplifies package management and offers a consistent user experience across macOS and Linux.
- Installing software in your home directory prevents conflicts with system-managed packages.
- Up-to-date Software: Access newer software versions that may not be available through the default Ubuntu package manager.
- Flexible Installation: Provides multiple methods of installation (curl or Git) to suit your preference.
- Simple Package Commands: Easily install, upgrade, and uninstall packages with straightforward commands.
- Easy Uninstallation: Homebrew comes with an uninstall script, making it simple to remove when needed.
Using Homebrew can streamline your workflows and keep your system organized while providing access to a broader range of software options.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!