Running the same CLI workflow across macOS and Linux is easier when you install Homebrew on Ubuntu. Homebrew gives you a separate package tree for newer developer tools and utilities without replacing Ubuntu’s APT-managed system packages.
Homebrew works on Ubuntu, but Ubuntu does not ship it as an apt install brew package. Older tutorials may still call it Linuxbrew, but the project now uses the Homebrew name on Linux as well. On Ubuntu, Homebrew uses the supported prefix /home/linuxbrew/.linuxbrew and only needs sudo for the initial setup. After that, package installs, upgrades, and removals run as your regular user.
Install Homebrew on Ubuntu
The official installer uses the same supported prefix and shell setup flow on Ubuntu 26.04, 24.04, and 22.04, so the commands below stay the same across all three LTS releases.
These steps cover Ubuntu 26.04, 24.04, and 22.04. Homebrew uses the same default prefix on all three releases, so the installation and shell setup commands stay the same.
Update Ubuntu and install Homebrew prerequisites
Homebrew’s Linux requirements still list build-essential, procps, curl, file, and git for Debian and Ubuntu systems. These commands work the same on Ubuntu Server and desktop installs. On minimal Ubuntu images, this step matters because the installer cannot start cleanly if tools like curl or git are missing.
sudo apt update
This guide uses
sudofor commands that need root privileges. If your user account is not in the sudoers file yet, add it first with the guide on how to add a new user to sudoers on Ubuntu.
Install the documented prerequisite packages:
sudo apt install -y build-essential procps curl file git
If some of these packages are already present, APT reports that they are already the newest version. That is normal on fuller desktop or developer images.
This prerequisite set gives you the compiler toolchain Homebrew expects, plus the download and repository tools the installer relies on. The guides for the curl command in Linux, installing or upgrading Git on Ubuntu, and installing GCC on Ubuntu cover those pieces in more depth.
Run the Homebrew installer
Run the supported installer from brew.sh. If your system Ruby is missing or too old, the script downloads Homebrew’s portable Ruby automatically.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
When the installer finishes, the tail of the output should look similar to this:
==> Installation successful!
==> Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
echo >> /home/linuxcapable/.bashrc
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> /home/linuxcapable/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
- Install Homebrew's dependencies if you have sudo access:
sudo apt-get install build-essential
- We recommend that you install GCC:
brew install gcc
The rcfile path in that output reflects your Ubuntu username, so it will differ from /home/linuxcapable/.bashrc on your system. The important part is the brew shellenv command that the installer prints.
Add Homebrew to your PATH
Use the same shellenv commands the installer prints so new terminals can find brew immediately.
For Bash (the Ubuntu default shell):
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> ~/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
For Zsh:
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv zsh)"' >> ~/.zshrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv zsh)"
If you rerun the installer later and the shellenv line already exists in your rc file, Homebrew may only tell you to run the eval command for the current shell.
Verify the Homebrew installation
Check the version first, then ask Homebrew to run its built-in diagnostics:
brew --version
brew doctor
Homebrew 5.0.16 Your system is ready to brew.
The exact version number will change as Homebrew ships new releases, but the healthy brew doctor message should match.
Install a test formula with Homebrew
A quick hello install confirms that Homebrew can download a bottle, place it under the prefix, and run the resulting command:
brew install hello
hello
==> Pouring hello--2.12.2.x86_64_linux.bottle.tar.gz Hello, world!
Remove the test formula when you are done:
brew uninstall hello
Uninstalling /home/linuxbrew/.linuxbrew/Cellar/hello/2.12.2... (57 files, 737.9KB)
Manage Homebrew Packages on Ubuntu
Once Homebrew is working, these are the commands you will use most often for day-to-day package management.
Search, inspect, and install formulas
Replace hello with the formula you actually want to install:
brew search hello
brew info hello
brew install hello
Good next package ideas include installing Node.js on Ubuntu, installing Go on Ubuntu, installing Neovim on Ubuntu, and installing GitHub CLI on Ubuntu. Installing GCC on Ubuntu is also useful when you want Homebrew’s recommended compiler path on both Ubuntu and macOS.
Update and clean up Homebrew
Use Homebrew’s own update and cleanup commands to keep formulas current and remove old downloads when they are no longer needed:
brew update
brew upgrade
brew outdated
brew cleanup --dry-run
brew cleanup
Use brew outdated before upgrading if you want to see what will change. The dry run keeps cleanup safe by listing old downloads and bottles before anything is deleted.
Troubleshoot Homebrew on Ubuntu
Most install problems come from PATH setup or from ownership changes after someone runs brew with sudo. Start with these checks before reinstalling Homebrew.
Fix brew: command not found after installation
Load Homebrew into the current Bash session first, then use grep to confirm the shellenv line is already stored in ~/.bashrc.
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
brew --version
grep -q "brew shellenv bash" ~/.bashrc && echo "Found in .bashrc" || echo "Not in .bashrc"
Homebrew 5.0.16 Not in .bashrc
If the last line says Not in .bashrc, append the Bash entry now:
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> ~/.bashrc
Zsh users should write the matching shellenv zsh line to ~/.zshrc instead.
Fix Homebrew permission errors
A healthy install keeps the parent directory root-owned while the writable Homebrew prefix belongs to your user. Check that layout before changing permissions:
ls -ld /home/linuxbrew /home/linuxbrew/.linuxbrew
drwxr-xr-x 3 root root 4096 Mar 7 11:22 /home/linuxbrew drwxr-xr-x 14 linuxcapable linuxcapable 4096 Mar 7 11:22 /home/linuxbrew/.linuxbrew
If the second line is owned by root or another user, repair the writable prefix ownership:
sudo chown -R "$(whoami)":"$(id -gn)" /home/linuxbrew/.linuxbrew
Never run
brewcommands withsudo. The installer uses elevated privileges only for the shared prefix setup under/home/linuxbrew.
Remove Homebrew from Ubuntu
Start with the official Homebrew uninstaller so formulae, taps, and the default cache paths are removed in the supported order.
Run the official Homebrew uninstaller
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
On a clean Ubuntu 24.04 removal test, the official script ended like this:
==> Homebrew uninstalled! The following possible Homebrew files were not deleted: /home/linuxbrew/.linuxbrew/lib/ /home/linuxbrew/.linuxbrew/share/ You may wish to remove them yourself.
That uninstall removed brew itself and cleared ~/.cache/Homebrew, but it still left files under /home/linuxbrew/.linuxbrew/lib/ld.so and /home/linuxbrew/.linuxbrew/share/info.
Remove leftover Homebrew files
Only run the next cleanup step after the official uninstaller finishes and you have confirmed that you no longer need any Homebrew-managed files.
Finish the cleanup with the verified commands below, then remove the shellenv line from ~/.bashrc or ~/.zshrc if you added it earlier.
sudo rm -rf /home/linuxbrew/.linuxbrew
sudo rmdir /home/linuxbrew
Confirm the prefix is gone:
ls -ld /home/linuxbrew /home/linuxbrew/.linuxbrew 2>/dev/null || echo "removed"
removed
The default install did not create separate Homebrew data under ~/.config, ~/.local/share, or ~/.var/app during this validation. The main paths to remove are the shared prefix and the shell initialization line.
Frequently Asked Questions
Yes. Homebrew supports Ubuntu and uses the default prefix /home/linuxbrew/.linuxbrew on current Ubuntu LTS releases. After the initial setup, package management runs as your regular user instead of through sudo.
No. Ubuntu does not ship Homebrew as an apt install brew package. The supported method is the official installer from brew.sh, after installing Homebrew’s documented prerequisite packages with APT.
That usually means the installer finished but your shell has not loaded Homebrew’s shellenv line yet. Run eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)" for Bash or the Zsh variant, then save the same line in ~/.bashrc or ~/.zshrc so new terminals can find brew.
No. Homebrew only needs elevated privileges while the installer prepares the shared prefix under /home/linuxbrew. After installation, running brew with sudo can break ownership inside /home/linuxbrew/.linuxbrew and cause permission errors later.
Not with the supported default install. Homebrew’s supported Linux prefix is /home/linuxbrew/.linuxbrew, so the initial setup needs elevated privileges. If you do not have admin access, Homebrew’s own Linux documentation recommends asking an administrator to create the /home/linuxbrew role account and prefix for you. Alternative installs outside the default prefix are unsupported and usually force more formulas to build from source.
Conclusion
Homebrew is installed on Ubuntu with brew available in your shell and the shared prefix isolated from APT-managed packages. From here, practical next steps are installing Node.js on Ubuntu, installing GitHub CLI on Ubuntu, or pulling in any other formula you want to keep aligned across Ubuntu and macOS.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>