Can I install Homebrew without sudo privileges?

28

9

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?

BenjaminGolder

Posted 2013-07-14T00:22:54.737

Reputation: 467

Answers

12

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.

David Hoelzer

Posted 2013-07-14T00:22:54.737

Reputation: 414

3This is just wrong, or at least you definition of "significant surgery" is very different then mine. I've been running brew with a prefix set to my home directory for 5 plus years and I've encounter 1 or 2 broken packages in that time. – James McMahon – 2017-09-12T02:22:39.613

However, also there is also this, which is hard to get around: Error: You have not agreed to the Xcode license. Please resolve this by running: sudo xcodebuild -license accept – Albert – 2019-01-16T17:47:12.630

Thanks, but I think you missed my question. I know how & where it installs packages, but I want to install Homebrew without admin or sudo. – BenjaminGolder – 2013-07-14T01:17:11.847

I didn't miss your question. The answer was "No".. I just said "Yes" accidentally. You cannot easily do what you are asking and even if you forced it by editing the Homebrew installer to put things into a branch off of your home directory, more than likely lots of brews would fail after installation. – David Hoelzer – 2013-07-14T01:18:38.727

okay, thanks. I was confused by the previous "Yes". – BenjaminGolder – 2013-07-14T01:25:19.753

18

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

Posted 2013-07-14T00:22:54.737

Reputation: 331

1In the install script I had to add #{YOUR_HOME} prefix to the HOMEBREW_CACHE variable as well. That, and because the system admin already had homebrew installed, I had to add export PATH=/path/to/home/usr/local/bin:$PATH to .bash_profile as well. But with all that, it seems to work great. – golmschenk – 2015-06-26T19:31:52.200

3Just went through the process again, and I just wanted to mention you also have to make a usr directory in your home directory before the script will run. Additionally, when you add #{YOUR_HOME} to the HOMEBREW_CACHE variable, it seems you need to change the single quotes to double quotes for it to work. So there are a few steps, but it's definitely worth it to get the power of Homebrew. – golmschenk – 2015-07-20T17:01:53.967

@golmschenk double quotes are required for ruby's string formatting to kick in, I believe. – Skylar Saveland – 2015-07-24T20:14:23.790

1That's a nice adjustment. You really ought to submit a pull request to the home-brew project. – David Hoelzer – 2015-12-05T19:48:40.273

1I tried this from a non-admin account on macOS Sierra (10.12.3) and it didn't work because it needed to do a chgrp admin /usr/local, and a non-admin account isn't a member of the admin group, so it can't change anything to that group. It would be great if this could be made to work for a normal non-admin account (not just for admin accounts that have for some strange reason been locked out of sudo). – Spiff – 2017-02-06T18:13:32.040

1

To install homebrew without sudo.

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

Restart terminal and run

brew --version

Astik Anand

Posted 2013-07-14T00:22:54.737

Reputation: 111

0

Yes.

The brew system appears bootstrappable

#!/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

Posted 2013-07-14T00:22:54.737

Reputation: 280

0

Brew moved their git repo which is why the above doesn't work anymore.

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

pwaterz

Posted 2013-07-14T00:22:54.737

Reputation: 101

1

By 'the above' do you mean Astik Anand's answer? It won't always be 'above' your answer. If something in their answer should be changed, edit it yourself.

– nekomatic – 2019-09-12T14:36:47.213