Installing Homebrew without sudo

Nelson Aloysio
2 min readOct 14, 2023

--

Figure: Homebrew for MacOS and Linux.

Homebrew is an open-source software package manager generally used on MacOS systems, but also available for Linux — and it is quite useful for vendor-locked machines or accounts with limited privileges, i.e., no sudo.

Although not officially supported, this guide presents a way to install the software limited to the user space, which may be handy for some use cases.

Install brew

First obtain the package and extract its contents to your home folder with:

mkdir -p ~/.local/Homebrew &&
curl -L https://github.com/Homebrew/brew/tarball/master |
tar xz --strip 1 -C ~/.local/Homebrew

Then simply link the binary to your preferred path, e.g. ~/.local/bin:

mkdir -p ~/.local/bin &&
ln -s ~/.local/Homebrew/bin/brew ~/.local/bin

Restart your shell and give it a test. If the brew command is not found, ensure the folder with the binary link is indeed in your $PATH variable:

cat << 'EOF' >> ~/.bashrc # or ~/.zshrc
[ -d "$HOME/.local/bin" ] &&
export PATH="$PATH:$HOME/.local/bin" # or "$HOME/.local/bin:$PATH" [1]
EOF

[1] You may leave $PATH at the end to prioritize local binaries (insecure).

Alternatively, you may add ~/.local/Homebrew/bin to $PATH instead.

Binary vs source

When Homebrew is installed to a prefix other the (system) default, some install commands will try to build the binary from source — which might be a tad time consuming and might result in an error sometimes.

This behavior may be avoided by passing the following argument…

brew install <package> --force-bottle

…so Homebrew avoids building packages with a binary (bottle) available.

Note that you might have to install a required package's dependencies by using this argument instead, as it is not propagated (e.g. xz for rclone).

Configure brew

Although the program "just works", you may choose to set some additional environment variables in ~/.bashrc (or ~/.zshrc), commented out below:

if [ -n $(command -v brew) ]; then
PREFIX="${HOME}/.local"
export HOMEBREW_PREFIX="$PREFIX"
export HOMEBREW_CELLAR="$PREFIX/Cellar"
export HOMEBREW_REPOSITORY="$PREFIX/Homebrew"
export HOMEBREW_CASK_OPTS='${HOME}/Applications'
export PATH="$PREFIX/bin:$PREFIX/sbin${PATH+:$PATH}"
export MANPATH="$PREFIX/share/man${MANPATH+:$MANPATH}:"
export INFOPATH="$PREFIX/share/info:${INFOPATH:-}"
# export HOMEBREW_NO_ANALYTICS=1
# export HOMEBREW_NO_ENV_HINTS=1
fi

Most settings are ignored if modified and are listed here for completeness only.
Thanks to Casey Morton for the tip regarding $HOMEBREW_CASK_OPTS!

Simple and straightforward.

--

--