public
Last active

Installs Homebrew to /usr/local so you don't need sudo to `brew install`

  • Download Gist

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 https://gist.github.com/raw/323731/install_homebrew.rb -o /tmp/install_homebrew.rb
ruby /tmp/install_homebrew.rb

mxcl says: Even simpler: ruby -e "$(curl https://gist.github.com/raw/323731/install_homebrew.rb)"

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

@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/TextMate.app, so why should you sudo chown root wget ?

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

curl https://gist.github.com/raw/323731/25f99360c7de3f72027d8fd07cb369b1c8756ea6/install_homebrew.rb -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.

i needed chown first.. so

sudo chown -R $USER /usr/local
curl https://gist.github.com/raw/323731/install_homebrew.rb -o /tmp/install_homebrew.rb
ruby /tmp/install_homebrew.rb

No, this is a shell script that installs Homebrew, a package manager. Here's the main page about it: http://mxcl.github.com/homebrew/

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. http://gist.github.com/403175

Would creating an issue at http://github.com/mxcl/homebrew/issues 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.

Pull request: http://gist.github.com/406696
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

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

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)

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

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.

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?

@mxcl - pull request - http://gist.github.com/426187 use "getc" instead of "getbyte" on STDIN, as "getbyte" is 1.8.7 (10.6) only.

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

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

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

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!

Matt

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

Should probably pipe explicitly to /usr/bin/ruby

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.

@mxcl: Bug fix: explicitly add share/man/man1 since we now have a manpage: http://gist.github.com/456062

@adamv thanks, pushed.

Update: full path to "sudo": http://gist.github.com/526211

Probably not needed, just being pedantic.

Updated: http://gist.github.com/526211

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.

@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: 
    sys.segfault()

:)

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

Please pull https://gist.github.com/675200 Everything is explained there

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 http://gist.github.com/raw/323731/install_homebrew.rb -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?

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.

@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. :)

I've edited all the comments, thanks.

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.

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

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.

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.

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.

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

@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?

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 https://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1'

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

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:
See: http://wiki.github.com/mxcl/homebrew/installation
Or run:
ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
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: https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-(Windows). 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 https://gist.github.com/raw/323731/install_homebrew.rb)"" 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 :-(

Thanks

@VladimirBL: Homebrew is a package manager for OS X. See: http://mxcl.github.com/homebrew/

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?

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

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.

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

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?

lol bodo makasi dah kirim stupitttttttttttttttttt

--- Pada Kam, 9/6/11, JohnDCCIU reply@reply.github.com menulis:

Dari: JohnDCCIU reply@reply.github.com
Judul: Re: gist gist: 323731
Kepada: rsattriawan@yahoo.com
Tanggal: Kamis, 9 Juni, 2011, 9:35 AM

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

Reply to this email directly or view it on GitHub:
https://gist.github.com/323731

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 problem....it'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 (https://github.com/mxcl/homebrew/tarball/master or one of the redirects downwind from it) and figure out why the certificate verification is failing.

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 https://raw.github.com/gist/323731/39fc1416e34b9f6db201b4a026181f4ceb7cfa74)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/Formula/...
/usr/local/Library/Homebrew/...

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:
https://gist.github.com/1022907

@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]

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

@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 https://raw.github.com/gist/323731/39fc1416e34b9f6db201b4a026181f4ceb7cfa74)"

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]

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

Fixed in 5fe6f259f91a83a9dcf811622dc0f8d957484a69

I used the following to install:

ruby -e "$(curl https://raw.github.com/gist/323731/install_homebrew.rb)"

@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 :)

@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?

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 https://raw.github.com/gist/323731)"

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

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) http://kernel.org/pub/software/scm/git/git-1.7.6.1.tar.bz2 -o /Users/josephgutman/Library/Caches/Homebrew/git-1.7.6.1.tar.bz2 --insecure

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

http://kernel.org/pub/software/scm/git/git-1.7.6.1.tar.bz2

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

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!

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

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

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

Fabric is a Python-based ssh automation thingy: https://github.com/fabric/fabric

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

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?

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.

Modified. Thanks.

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

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

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

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.

I have amended it as you suggested. Thanks.

Link to wrong url -> new url raw.github.com/mxcl/homebrew/go

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.