How to Install Homebrew on Ubuntu (26.04, 24.04, 22.04)

Homebrew is a package manager originally created for macOS that now works natively on Linux. It provides access to thousands of command-line tools, libraries, and development utilities that may not be available in Ubuntu’s default repositories or where you need newer versions than APT provides.

Common use cases include installing development tools like Node.js version managers, CLI utilities, language toolchains, and software that receives faster updates through Homebrew than through distribution repositories. By the end of this guide, you will have Homebrew installed on Ubuntu, configured in your shell environment, and ready to install packages.

How Homebrew Works on Linux

Homebrew on Linux installs packages to /home/linuxbrew/.linuxbrew rather than system directories like /usr or /usr/local. This isolation means Homebrew packages do not interfere with APT-managed software, and you can remove Homebrew entirely without affecting your system.

The installer requires elevated privileges to create the initial directory structure, but subsequent package management runs as your regular user without sudo. Homebrew maintains its own versions of core dependencies like GCC and glibc, allowing packages to work consistently regardless of your Ubuntu release.

These steps cover Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. Homebrew manages its own dependencies and works identically across all supported Ubuntu releases. Commands shown work the same on all versions.

System Requirements

Before installing Homebrew, verify your system meets these requirements:

  • Operating System: Ubuntu 22.04 or newer (64-bit x86_64 or ARM64)
  • Disk Space: Approximately 15 GB for Homebrew and typical packages
  • RAM: 2 GB minimum (4 GB recommended for compiling packages)
  • Internet: Active connection required for downloading packages
  • Shell: Bash or Zsh (both fully supported)

Homebrew requires several build tools that may not be present on minimal Ubuntu installations.

Install Build Dependencies

Homebrew requires development tools to compile packages from source when pre-built bottles are not available. Install the required dependencies:

sudo apt update
sudo apt install build-essential procps curl file git -y

This installs:

  • build-essential: GCC compiler, make, and core development libraries
  • procps: Process utilities that Homebrew uses for system checks
  • curl: Downloads the installation script and packages
  • file: Determines file types during package installation
  • git: Clones Homebrew’s package repositories

Install Homebrew

Download and run the official Homebrew installer script:

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

The script explains each action and prompts for confirmation before making changes. When prompted, enter your password to allow the installer to create the /home/linuxbrew/.linuxbrew directory structure.

The installer downloads Homebrew’s core files and sets up the directory structure. When complete, you should see output ending with instructions to add Homebrew to your PATH:

==> Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

Configure Shell Environment

Homebrew installs to a non-standard location, so you must add it to your PATH. Run these commands to configure your shell:

For Bash users (Ubuntu default):

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

For Zsh users:

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.zshrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

The first command adds Homebrew to your PATH permanently by writing to your shell configuration file. The second command activates Homebrew in your current terminal session without requiring a restart.

Verify Installation

Confirm Homebrew installed correctly:

brew --version

Expected output showing the installed version:

Homebrew 5.x.x

Run the diagnostic command to check your installation health:

brew doctor

A healthy installation displays:

Your system is ready to brew.

If brew doctor reports warnings, read each message carefully. Most warnings are informational and do not prevent Homebrew from functioning.

Test Package Installation

Install a test package to confirm everything works:

brew install hello

Run the installed program:

hello
Hello, world!

Remove the test package after verification:

brew uninstall hello

Install Recommended GCC

Homebrew recommends installing its own GCC compiler for building packages that require compilation. This provides a consistent toolchain regardless of your system’s GCC version:

brew install gcc

This step is optional but recommended if you plan to install packages that need to compile from source.

Basic Homebrew Commands

Homebrew uses simple commands for package management. These commands work the same on Linux as on macOS.

Search and Install Packages

# Search for packages
brew search 

# View package information
brew info 

# Install a package
brew install 

# Install multiple packages
brew install package1 package2 package3

List and Manage Installed Packages

# List all installed packages
brew list

# Check which packages are outdated
brew outdated

# Show package dependencies
brew deps 

# Remove a package
brew uninstall 

# Remove unused dependencies left behind after uninstalling packages
brew autoremove

Common Packages for Linux

Popular packages available through Homebrew on Linux include:

PackageDescriptionInstall Command
gccGNU Compiler Collection (newer than system version)brew install gcc
nodeNode.js JavaScript runtimebrew install node
pythonPython interpreter (latest version)brew install python
goGo programming languagebrew install go
neovimModern Vim-based text editorbrew install neovim
treeDirectory listing in tree formatbrew install tree
jqJSON processor for command linebrew install jq
ghGitHub CLIbrew install gh

Update Homebrew

Keep Homebrew and its packages current with regular updates.

Update Homebrew Itself

Fetch the latest package definitions and Homebrew version:

brew update

Upgrade Installed Packages

Upgrade all installed packages to their latest versions:

brew upgrade

Upgrade a specific package:

brew upgrade 

Clean Up Old Versions

Remove old versions and clear the download cache to free disk space:

brew cleanup

Preview what would be removed without deleting:

brew cleanup --dry-run

Troubleshooting

Command Not Found After Installation

If brew returns “command not found” after installation, your current session does not have Homebrew in its PATH.

Apply the PATH configuration immediately:

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

If this works, verify your shell configuration file contains the Homebrew initialization line:

grep -q "linuxbrew" ~/.bashrc && echo "Found in .bashrc" || echo "Not in .bashrc"

If missing, add it:

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

Permission Errors

If you encounter permission errors when installing packages, verify ownership of the Homebrew directory:

ls -la /home/linuxbrew/.linuxbrew

Your user should own this directory. If not, fix the ownership:

sudo chown -R $(whoami) /home/linuxbrew/.linuxbrew

Never run brew commands with sudo. Homebrew is designed to operate without root privileges after initial installation. Using sudo can create permission problems that are difficult to resolve.

Running as Root User

Homebrew refuses to run as the root user. If you see an error like “Don’t run this as root!” when running brew commands, switch to a regular user account:

su - yourusername

This security measure prevents accidental system-wide changes and ensures packages install to user-accessible locations.

Slow Package Installation

Homebrew downloads pre-compiled binaries (bottles) when available. If packages compile from source instead, installation takes significantly longer.

Check if bottles are available for your system:

brew info 

Look for lines showing available bottles for your architecture. If the output does not list your system, Homebrew compiles from source automatically.

Run Diagnostics

The doctor command identifies common problems:

brew doctor

Address any warnings marked as errors. Informational warnings (like PATH order suggestions) typically do not affect functionality.

Remove Homebrew

To completely remove Homebrew and all installed packages, run the official uninstall script:

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

The script prompts for confirmation before removing files. After completion, remove the PATH configuration from your shell configuration file.

For Bash users, edit ~/.bashrc and remove the line containing linuxbrew:

nano ~/.bashrc

Find and delete this line:

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

Save the file and reload your shell configuration:

source ~/.bashrc

Verify removal:

brew --version
bash: brew: command not found

Conclusion

Homebrew provides access to a large collection of development tools and utilities on Ubuntu, supplementing APT with packages that may be newer or unavailable in default repositories. The isolated installation in /home/linuxbrew/.linuxbrew keeps Homebrew packages separate from system software, allowing both package managers to coexist.

For routine maintenance, run brew update followed by brew upgrade periodically to keep packages current. Use brew cleanup occasionally to recover disk space from old package versions. If you encounter issues, brew doctor diagnoses most common problems and suggests fixes.

Leave a Comment

Let us know you are human: