89

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?

7 Answers7

124

In case somebody is still looking for this in 2020 and beyond, yes, this is possible without root privileges:

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

The above allows you to install homebrew anywhere. Make sure that you add homebrew/bin to your $PATH.

More information about this alternative installation method is available in Brew's installation instructions.

judepereira
  • 1,356
25

Yes.

I modified the install script to not use sudo and to use a directory of your choice. https://gist.github.com/skyl/36563a5be809e54dc139

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.rb

In .bash_profile, I set (I'm not positive this is important, pretty sure):

export HOMEBREW_PREFIX=/The/path/to/YOUR_HOME/usr/local

Now, I can:

brew install wget

Make sure the bin directory, YOUR_HOME + /usr/local/bin is on your $PATH.

which wget
Skylar Saveland
  • 391
  • 1
  • 5
  • 5
17

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.

2

To install homebrew without sudo.

git clone https://github.com/Homebrew/brew.git
echo 'export PATH="/path/to/cloned_folder/homebrew/bin:$PATH"' >> ~/.bash_profile

Restart terminal and run

brew --version
1

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 https://github.com/Homebrew/brew/tarball/master | 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/"

eel ghEEz
  • 318
1

Brew moved their git repo

git clone git@github.com:Homebrew/brew.git
echo 'export PATH="/path/to/cloned_folder/homebrew/bin:$PATH"' >> ~/.bash_profile
pwaterz
  • 111
1

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 https://github.com/Homebrew/brew homebrew
mkdir ~/usr/local
# installed packaged directory
echo "export HOMEBREW_PREFIX=~/usr/local" >> ~/.zshrc
echo "export PATH=$PATH:~/homebrew/bin:HOMEBREW_PREFIX/bin" >> ~/.zshrc

update brew

brew update
# if error
brew update-reset
Alpha
  • 111