Can I install Homebrew without sudo privileges?
Matthew Harrington
Homebrew nicely allows package installations without sudo privileges, but it seems that I need admin privileges to install Homebrew itself.
I'd like to install Homebrew in a Mac environment where I don't have sudo or admin privileges. Is this possible?
17 Answers
In case somebody is still looking for this in 2020 and beyond, yes, this is possible without root privileges:
mkdir homebrew && curl -L | tar xz --strip 1 -C homebrewThe above allows you to install homebrew anywhere. Make sure that you add homebrew/bin to your $PATH.
More information about this alternative installation method (and source):
5Yes.
I modified the install script to not use sudo and to use a directory of your choice.
Download that, set YOUR_HOME in the script to the absolute path. chmod +x the script. Create the YOUR_HOME/usr/local directory. Then, execute the script.
./install.rbIn .bash_profile, I set (I'm not positive this is important, pretty sure):
export HOMEBREW_PREFIX=/The/path/to/YOUR_HOME/usr/localNow, I can:
brew install wgetMake sure the bin directory, YOUR_HOME + /usr/local/bin is on your $PATH.
which wget 9 No.. Unless you do significant surgery.
The reason is that Homebrew strongly insists on installing packages into /usr/local. In fact, even if you forced it to install somewhere else, you are likely to break dependencies when you use brew install to install packages. Most if not all of these packages are pre-compiled and linked expecting to live in /usr/local.
The reason for this insistence is that /usr/local is precisely where POSIX recommends that stuff like this gets installed. In order to create /usr/local Homebrew needs temporary admin credentials to create the directory and assign ownership.
This, in turn, is what allows you to install anything else without elevating credentials.
6To install homebrew without sudo.
git clone
echo 'export PATH="/path/to/cloned_folder/homebrew/bin:$PATH"' >> ~/.bash_profileRestart terminal and run
brew --version 1 Brew moved their git repo
git clone :Homebrew/brew.git
echo 'export PATH="/path/to/cloned_folder/homebrew/bin:$PATH"' >> ~/.bash_profile 4 Yes.
The brew system appears bootstrappable and can be installed in one own's home directory. According to a comment by @Adrian, this will take much longer because each package will be built from its source code.
#!/bin/bash
set -ex
export HOMEBREW_PREFIX=~/homebrew
# export HOMEBREW_NO_ANALYTICS=1
mkdir -p "${HOMEBREW_PREFIX}"
curl -fsSLk | tar xz --strip 1 -C "${HOMEBREW_PREFIX}"
ls -laR "${HOMEBREW_PREFIX}"
export PATH="${HOMEBREW_PREFIX}/bin:${PATH}"
type -a brew
type -a openssl || :
openssl version -a || :
type -a curl || :
curl -V || :
# Fails to lock a .git/config file.
##brew analytics off
# No "brew update" until installing the proper openssl and a curl that uses it.
# brew update
# brew remove openssl || :
brew install openssl
brew link --force openssl
# brew remove curl || :
brew install --with-openssl curl
brew link --force curl || :
curl -V
ls -la "${HOMEBREW_PREFIX}/opt"
ls -la "${HOMEBREW_PREFIX}/bin"
ls -laLR "${HOMEBREW_PREFIX}/opt/curl/" 9 The following script shows a way to install brew without root. Please do export environment variables HOMEBREW_PREFIX & PATH in your ~/.zshrc after installation to ensure the package will placed at a expected directory
download
cd ~
git clone homebrew
mkdir ~/usr/local
# installed packaged directory
echo "export HOMEBREW_PREFIX=~/usr/local" >> ~/.zshrc
echo "export PATH=$PATH:~/homebrew/bin:HOMEBREW_PREFIX/bin" >> ~/.zshrcupdate brew
brew update
# if error
brew update-reset 1