Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Installs Homebrew to /usr/local so you don't need sudo to `brew install`

ecin commented Apr 21, 2010

Script doesn't work with ruby 1.9, as #getc on line 108 returns '' instead of 13.

mxcl says: Thanks to mattetti for the fix.

curl -o /tmp/install_homebrew.rb
ruby /tmp/install_homebrew.rb

mxcl says: Even simpler: ruby -e "$(curl"

Frungi commented Apr 26, 2010

$ sudo ruby /tmp/install_homebrew.rb
Don't run this as root!

Frungi commented Apr 26, 2010

@kennethreitz, I don’t know why the script gives that output. Line 77:
abort "Don't run this as root!" if Process.uid == 0

@Frungi, weird. works fine for me. I want my packaging system to be installed the core.

@mxcl, Advise?

mxcl says: this script installs Homebrew as recommended in the Installation Guide. Which means, it will be installed with your user credentials. So we need to know your user id. If you want it installed as root see the Installation Guide.

@kennethreitz See this page, about 2/3 down under the heading "Sudo".

Summary: You didn't sudo chown -R root /Applications/, so why should you sudo chown root wget ?

All better :)

brookr commented May 4, 2010

Looks like GH changed the URLs for raw access? This works for me, at the moment:

curl -o /tmp/install_homebrew.rb
ruby /tmp/install_homebrew.rb

@kennethreitz, you may want to update? Thanks for the shortcut.

@brookr, the /raw/HEAD/ url is a new undocumented gist feature. If the script is updated, that url will alway fetch the latest.

Yours will always reference that particular commit.

mxcl says: Apparently the HEAD bit was removed, I amended the relevant URLs.

zackd commented May 12, 2010

i needed chown first.. so

sudo chown -R $USER /usr/local
curl -o /tmp/install_homebrew.rb
ruby /tmp/install_homebrew.rb

Frungi commented May 14, 2010

No, this is a shell script that installs Homebrew, a package manager. Here's the main page about it:

ned21 commented May 16, 2010

I noticed that on a fresh install of 10.6 no one is a member of the staff group. It appears that all Administrator users are members of the admin group though, and since it seems to only allow admins to change the machine's homebrew install, I forked this gist and replaced all the instances of staff with admin.

Would creating an issue at be the right way to submit this upstream?

mxcl says: I wrote this script on a fresh install of 10.6, my user was in the staff group.

adamv commented May 19, 2010

Pull request:
Use /bin/stty explicitly (in case someone has a fink stty in the path ahead of /bin)

mxcl says: Pulled!

For this script to work, I had to create the following directories and give my non root user write access:

sudo mkdir -p /usr/local/Library/Homebrew
sudo mkdir -p /usr/local/Library/Formula
sudo mkdir -p /usr/local/Library/Contributions
sudo chmod 777 /usr/local/Library/Homebrew
sudo chmod 777 /usr/local/Library/Formula
sudo chmod 777 /usr/local/Library/Contributions


mxcl commented May 27, 2010

@andygoundry thanks, but we can't fix it without error messages.

rbl00 commented Jun 4, 2010

I had to do the same thing that andygoundry said, create a few directories and change permissions on them.

I got hundreds of error messages about not being able to create directories. Examples below:

Library/Formula/virtualenvwrapper.rb: Failed to create dir 'Library/Formula': No such file or directory
Can't create 'Library/Formula/virtualenvwrapper.rb': No such file or directory

Library/Homebrew/hardware.rb: Failed to create dir 'Library/Homebrew': No such file or directory
Can't create 'Library/Homebrew/hardware.rb': No such file or directory

(these are only two random lines from hundreds)

adamv commented Jun 4, 2010

@andygoundry @rbl00 What would be interesting for us would be to know the permissions set on /usr/local when this failed; a stock OS X install comes a certain way, but of course various .pkgs and whatnot installed later can change these permissions around quite a bit.

rbl00 commented Jun 4, 2010

No problem, below is my output for local when I run a ls -l in /usr

drwxrwxr-x 17 root staff 578 Jun 4 15:43 local

I've run this script about 3 times now on a completely fresh Snow Leopard installation without any problem at all.

rbl00 commented Jun 4, 2010

Its quite possible that my permissions are not the default permissions for /usr/local i have several other things installed in there before i installed homebrew.

How about showing us what the permissions are on one of those clean installs for /usr/local?

adamv commented Jun 5, 2010

@mxcl - pull request - use "getc" instead of "getbyte" on STDIN, as "getbyte" is 1.8.7 (10.6) only.


mxcl commented Jun 5, 2010

@adamv getc returns something else for Ruby 1.9 apparently. So I committed a fix that depends on RUBY_VERSION.


mxcl commented Jun 5, 2010

These errors make no sense. The permissions are fine. Then tar says it can't create directories. Is tar getting run as some other user somehow?

I've got also some permission errors since I've already had some code in /usr/local. Maybe check /usr/local for permissions itself and also check Library (don't know but I had /usr/local/Library/Perl in there...)


mxcl commented Jun 15, 2010

It's true we aren't checking the permissions on Library. Not sure how I didn't notice that. Fixed.


ghost commented Jun 16, 2010

I got:
Library/Contributions/: Can't create 'Library/Contributions': Permission denied

So, I did: ls -al /usr/local/ and saw that the script did not change my permissions for Library (or google_appengine, or libexec)

Please fix. Thanks!


adamv commented Jun 16, 2010

Press enter to continue
stty: stdin isn't a terminal
Failed during…

Should probably pipe explicitly to /usr/bin/ruby


mxcl commented Jun 16, 2010

The pipe means STDIN is not a terminal so it's logical that it broke. I'm a dumbo for not testing the change properly. I only tested up to the error "/usr/local/.git/" exists! Because I assumed if that worked then the whole thing would. Reverted.

I was seduced by the simplicity of the piped approach, and hadn't considered it when devising the one-liner originally. I don't think it's possible to grab user input from the originating terminal from inside a pipe. But whatever, for now it's reverted.

Oooh, that would be awesome.

adamv commented Jun 28, 2010

@mxcl: Bug fix: explicitly add share/man/man1 since we now have a manpage:


mxcl commented Jul 2, 2010

@adamv thanks, pushed.


adamv commented Aug 16, 2010

Update: full path to "sudo":

Probably not needed, just being pedantic.

adamv commented Aug 16, 2010


Add all of man1-8 to the chgrp line. Git for instance installs a man7 page that can fail if share/man/man7 isn't group owned.

This weekend I reinstalled snow leopard and got everything setup properly, and finally installed homebrew without sudo. I am shocked at the elegance and how wrong i've been approaching everything the past year.

Anyway, I think that not using sudo should be extremely stressed on install. Extremely.


mxcl commented Sep 11, 2010

@adamv pushed

@kennethreitz Heh, I'm not sure I could stress it more. But glad to hear that not using sudo was to your taste in the end.

if sudo: 


I don't know if anybody noticed but we are having a problem with aclocal.

Please pull Everything is explained there

hced commented Dec 7, 2010

Trouble: I have just reformated my Mac and installed a pristine OS X 10.6.3, then updated to 10.6.5.

Prior to downloading/installing homebrew, I did sudo mkdir /usr/local (since /usr/local doesn't exist by default, and creating it requires root permission).

I also did sudo chown -R $USER /usr/local before attempting to install homebrew:

Attempting to install homebrew, I tried both mxcl's one-liner and
curl -o /tmp/install_homebrew.rb && ruby /tmp/install_homebrew.rb

… but received the following error:

picture alt

(Note: I had to post a picture of the error message since I couldn't figure out how to stop github's flavored markdown from stripping the html tags.)

As for homebrew, am I missing something embarrassingly obvious?


mxcl commented Dec 7, 2010

Yes, you have successfully downloaded a 301 redirect. Which would be obvious if you'd looked at the file you downloaded. I don't know where you are getting your command from but you need to download the https version. A few weeks ago github fucked all of us over in a massive fit of impracticality and arrogance by forcing all connections to the site to be https rather than http. The result is your problem.

hced commented Dec 7, 2010

@mxcl: My apologies for missing the obvious. As for where I got the command, I used what was in this comment above (while I should've used your oneliner on the main page).

Anyway, installation worked out fine using https:// and now I'm excited to get going with homebrew. Thanks. :)


mxcl commented Dec 7, 2010

I've edited all the comments, thanks.

Frungi commented Dec 7, 2010

Can’t you use &lt; and &gt; entities in these comments if you’re trying to show HTML code? For example, &lt;html&gt; renders as <html>

@mxcl: It strikes me that homebrew's installation instructions are fragile (sourcing a literal URL) and insecure (what if the contents of that URL get hacked to be something a user wouldn't want to run?). Blaming github -- a free and useful service -- in such stark terms when your fragile installation instructions fail is uncalled for.

*mxcl says: I deleted the following flamewar.

@Frungi: You misunderstand me. I don't have any complaints about homebrew's installation process, only neutral observations. Anyone using command-line tools can make the process work for them in one way or another. My complaint is about the bile (mis)directed at github. But here's a possible suggestion: if the installation depends on a URL, make it a URL that you control.


Frungi commented Jan 12, 2011

@DieLaughing: I thought line 76 prevented you from using sudo. Or is this comment in the wrong place? Because I have no idea what those errors mean.


mxcl commented Jan 12, 2011

I installed Homebrew on a brand new Macbook Air just two weeks ago. No problems.

Regarding the line that may or may not require sudo, I'm not changing it, I have no idea what it does, the original (in the distant past) suggestion to add that line was provided to me without much explanation or concourse. But I added it in the hope that people would be able to take the suggestion and solve their (edge case) problem with it.

I'm not going to recommend people call sudo on a command I don't fully understand to solve a bug that I don't fully understand. It's irresponsible.


mxcl commented Jan 12, 2011

I don't understand the bug or the solution. It seems like a very sensible decision to me not to fuck with it. Call it self-importance if you like (like Jesus, is that how you are with people?) but in my mind I am protecting the project because I care about it.


mxcl commented Jan 12, 2011

I already admitted to ignorance. And it's pretty obvious you have never been part of a big open source project if you think it is irrational fear.

I’m gonna have to side with Max’s last comment here. It’s not irrational; it’s sensible to leave it alone until you have the time to fully grok it. Don’t change things without knowledge.


mxcl commented Jan 12, 2011

@mikbe we don't recursively change the permissions because this can break other already existing installations. Which directories were causing you trouble? As we'll add them to the script.

Frungi commented Jan 13, 2011

@mxcl: That dscl command adds the current user to the staff group (see here, for instance). So yes, it would require sudo, as that’s obviously not something that non-admin users should be able to do. But why did you add that line in the first place if you’re so uncertain about it?

dbmikus commented Jan 15, 2011

I'm getting the following error during installation:

Downloading and Installing Homebrew...

curl: (22) The requested URL returned error: 502
Failed during: /bin/bash -o pipefail -c '/usr/bin/curl -sSfL | /usr/bin/tar xz -m --strip 1'


mxcl commented Jan 15, 2011

GitHub is failing to provide the tarball. If it continues to happen, report the bug to GitHub.

dbmikus commented Jan 15, 2011

Alright, thanks. I'll keep trying it. I was just confused because the url downloaded when I copied it into my web browser.

The tarball is still unreachable

GitHub have fixed the problem with their downloads and the install script works well.

Hello everyone!

I need to perform the next steps:

  1. Install nodeJS to run the included nodeServer.js server:
    Or run:
    ruby -e "$(curl -fsSLk"
    brew install node

  2. Start the server from the SDK directory:
    cd SDK
    make server

The first problem is that I work on "Windows 7" and using Cygwin to "Get that Linux feeling - on Windows!" :-)
I've installed nodeJS according to this: Probably nodeJS is really installed because there were no errors reported.
The 2nd problem is when I try to make this: "ruby -e "$(curl -fsSLk"" then I've got error from this script:

This script requires the user Vladimir_BL to be in the staff group. If this sucks for you then you can install Homebrew in your home directory or however you please; please refer to the website. If you still want to use this script the following command should work:

dscl /Local/Default -append /Groups/staff GroupMembership $USER

There is no "dscl" in Cygwin (at least I can't find it during setup process). So I can't use this "dscl".
Is there way to perform this script under Cygwin? Or maybe there is a way to install "brew" without this script?
I almost don't know *nix systems... I need to start this server in anyway (Windows7+Cygwin).
If someone may and wants to help me then write exact commands that I should type.

Also there are a lot of mentions some "sudo" but I can't find it in Cygwin installer :-(


@VladimirBL: Homebrew is a package manager for OS X. See:

You're going to have trouble running it on Windows, Cygwin or not :)

@bobthecow: I see that I have trouble and because of that I'm here :-).
Is there way to make something in Cygwin or is it 100% impossible?

Frungi commented Feb 24, 2011

@VladimirBL: It's specifically a Mac product, so I imagine you'd have trouble using it under any kind of genuine Linux, let alone Cygwin. You'd probably be better off looking for a Linux package manager.

Frungi commented Feb 24, 2011

Ah. Well, there you go then, Vlad!

Thanks to all. I've forced nodeJS to work under Windows7 + Cygwin. It allows to connect to nodeJS from Windows7 through "localhost" and JavaScript works but my final task is to connect from Android emulator. And it doesn't happen. Looks like it is really impossible with Cygwin but anyway I can live with that.
Thanks again to all.


mxcl commented Feb 25, 2011

I guess we should add a check for OS X at the script's beginning.

adamv commented Apr 5, 2011

"var/log" might also need to be chowned, see:


mxcl commented Apr 13, 2011


Did the one-liner on my 10.5.8 system, but after authenticating and the initial steps, I got this:

==> Downloading and Installing Homebrew...
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

I downloaded this script and edited it to add the -k switch on the curl command (to ignore the SSL error) and then it worked fine, but I guess there's some kind of cert problem somewhere that needs to be looked at?


mxcl commented Jun 10, 2011

So, should I add -k? Presumably we can always trust that URL. Seems bad practice, and bad for possible clones that don’t remove the -k switch.

@mxcl, you're correct: it would be bad practice to permanently ignore that certificate's a temporary workaround for people that don't care about the SSL protection, not a permanent solution. The permanent solution is to get with whoever maintains the server at that default installation URL ( or one of the redirects downwind from it) and figure out why the certificate verification is failing.

adamv commented Jun 10, 2011

I opened a support request w/ GitHub; got this same issue doing a curl-based install of Resty off of github.

Likely the cert is no longer valid after the change of the raw gist subdomain name.

This doesn't seem to work for me on a fresh install of OS X (with no /usr/local/). I get this error:

jubjub:~ patricka$ ruby -e "$(curl -fsSL"
==> This script will install:

Press enter to continue
==> /usr/bin/sudo ["/bin/mkdir /usr/local"]
sudo: [/bin/mkdir /usr/local]: command not found
Failed during: /usr/bin/sudo ["/bin/mkdir /usr/local"]

I've fixed it in my fork:


mxcl commented Jun 13, 2011

@oldpatricka I just tested on a new install of Snow Leopard and it’s fine. What OS X version are you using?

@mxcl 10.6.7, with ruby:
jubjub:~ patricka$ ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]


mxcl commented Jun 13, 2011

@oldpatricka OK so you forcibly upgraded the system Ruby to 1.9.2. You can't do this without expecting some stuff to break.

However we're happy to try and support this in the installation script. Though Homebrew itself does not actually support it. And you'll find an awful lot of other stuff breaks mysteriously too. So you may want to personally reconsider this.

However as said, happy to make this script work. But I'd rather fix the sudo function to work with ruby 1.9 and the existing way it is called, as is accepted usage and it'll just break again somewhere. And right now I haven't the time to fix that.

@mxcl Huh. Yeah, I totally forgot that I was using a newer Ruby through rvm. Sorry about the confusion.


mxcl commented Jun 13, 2011

@oldpatricka rvm can replace /usr/bin/ruby? As our script uses the absolute path.

@mxcl No, it doesn't replace /usr/bin/ruby, but your copy and paste install from the readme says to just run the ruby in your path:

ruby -e "$(curl -fsSL"

So running that used my rvm installed ruby, rather than system ruby.

For reference:

jubjub:~ patricka$ /usr/bin/ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
jubjub:~ patricka$ ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]

mxcl commented Jun 13, 2011

@oldpatricka ah! Yes. Thanks. I should fix that.

adamv commented Jun 13, 2011

Fixed in 5fe6f259f91a83a9dcf811622dc0f8d957484a69

ninj commented Jun 18, 2011

I used the following to install:

ruby -e "$(curl"

@mxcl have you considered adding the command to run your script at the top of the code in a comment. That would make it much easier to find :)


mxcl commented Jun 19, 2011

@ninj it is detailed in the Installation instructions and the README. I used to have it here too, but then I had three places to update whenever the installation one-liner needed to be changed. Several times I forgot to update one of the three which lead to people making mistakes which were my fault.

So ignoring the fact that it is not DRY, I am still not putting it at the top of the script. For two reasons:

  1. If people can't figure out how to download and run a script then there is no hope for them.
  2. There is no reason they should come here first. There are two entry points for Homebrew, which are the Homepage, (that directs to the Installation instructions) and the GitHub Homebrew landing page (which has the README on it).

How did you end up coming here first?

ninj commented Jun 19, 2011

Doh, yes it is on the install page on the wiki. Sadly I managed to read all the way down the install page, and then decided to scroll upwards from the bottom. After coming to "This script is the recommended way to install..." I clicked on the link and wound looking up at the github page for this file.

Probably nothing you can (or should) do about this.

@JohnDCCIU: Thanks for the tip. However, I've been trying to put in the flag and it still doesn't seem to work at all!

Currently, I'm entering:

ruby -e "$(curl -fksSL"

Oh gosh. That was the easiest install EVER!!! One line and my password install a program is a first.

JoshTheGeek =D


mxcl commented Aug 23, 2011

Yes there's a ticket for this. I'll revert the change for now. You can fix it quite easily by just changing the permissions on /usr/local. Update: script is updated. Including a fix for the curl SSL certificate.

when I "brew install git" i get this:

curl: (22) The requested URL returned error: 503
Error: Failure while executing: /usr/bin/curl -f#LA Homebrew\ 0.8\ (Ruby\ 1.8.6-369;\ Mac\ OS\ X\ 10.5.8) -o /Users/josephgutman/Library/Caches/Homebrew/git- --insecure

Most likely due to the fact that is returning a 503 error when you try to download git...

... kinda like it says in the error message :)

ah yes, realizing that kernel is down

When I tried to brew install mysql it gave me an error that it couldn't find /usr/local/Cellar. I had to mkdir /usr/local/Cellar to get it working. Should Cellar be created with this script or in one of the formulas?

jazzido commented Oct 26, 2011

Got an error during install: /usr/local exists in the machine, but it doesn't contains all the subdirectories listed in chmods. That causes the sudo in line 113 to fail.

Hi Max,

Please change abort unless getc == 13 to abort unless gets == "\n"

So that the install will work via fabric, etc!


mxcl commented Jan 17, 2012

@halcyonCorsair What's fabric? Why won't it work? What's etc?


mxcl commented Jan 17, 2012

@jazzido it checks if the directories exist on line 94. Error messages are more useful than inaccurate analysis. Thanks.

Frungi commented Jan 17, 2012

@mxcl “Etc.” means “et cetera”, “and so on”, means things other than Fabric, whatever that is.

adamv commented Jan 17, 2012

Fabric is a Python-based ssh automation thingy:


mxcl commented Jan 17, 2012

I wonder if there is any good reason I didn't use gets in the first place. I imagine there must be. It's not the kind of thing I'd do otherwise. Shame I didn't have the foresight to comment it :P


mxcl commented Jan 17, 2012

Aah. It's because of UX. if you press any other key it should immediately exit. gets requires you to press enter, which makes ineffective for the exit option for the instruction "Press enter to continue".

Ok. In my quick tests, I'm getting

>> STDIN.getbyte

=> 10
>> 10.chr
=> "\n"
>> 13.chr
=> "\r"

Can we change the line to be:

i = getc
abort unless i == 13 or i == 13

Or am I off my rocker here?


mxcl commented Jan 18, 2012

Can we get an explanation of why it doesn't work so we can fix it more effectively?

Oops, 2am typo there, what I meant was...

i = getc
abort unless i == 10 or i == 13

I have no idea why \r is getting sent instead of \n for me.


mxcl commented Jan 18, 2012

Modified. Thanks.

Pull request:
Changed shebang to #!/usr/bin/env ruby so other rubies can be used (in case user has removed the default system ruby)

nhooey commented Feb 21, 2012

Ideally instead of saying "use su", this script should say "su to a non-root admin user". It got me confused when it said to just use su, and then said "don't run this as root".


mxcl commented Feb 21, 2012

I'll remove the su, bit. Since apparently people don't realise what it means. Nobody understands unix anymore.

nhooey commented Feb 21, 2012

I understand Unix and it confused me.

The script says:

If you still want to use this script set your user to be an Administrator in System Preferences or `su'.

It should be more specific and say to su as an administrator user. I figured that root was effectively an administrator, because I'm new to MacOS. The language just isn't precise.


mxcl commented Feb 21, 2012

I have amended it as you suggested. Thanks.

duksis commented Jan 4, 2013

Link to wrong url -> new url

ruby -e "$(curl -fsSkL"

Broken link D:

Broken link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment