118

After installing Yosemite, I was unable to run brew or ruby.

I was getting this error on brew update:

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

getting this error on irb:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in mkdir': Permission denied - /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14 (Errno::EACCES) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:infu_mkdir'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:219:in block (2 levels) in mkdir_p' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:inreverse_each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:in block in mkdir_p' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:ineach'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:in mkdir_p' from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:210:inwrite_gem_make_out'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:132:in build_error' from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:171:inrescue in build_extension'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:156:in build_extension' from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:198:inblock in build_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:195:in each' from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:195:inbuild_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1436:in block in build_extensions' from /Library/Ruby/Site/2.0.0/rubygems/user_interaction.rb:45:inuse_ui'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1434:in build_extensions' from /Library/Ruby/Site/2.0.0/rubygems/stub_specification.rb:60:inbuild_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/basic_specification.rb:56:in contains_requirable_file?' from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:925:inblock in find_inactive_by_path'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in each' from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:infind'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in find_inactive_by_path' from /Library/Ruby/Site/2.0.0/rubygems.rb:185:intry_activate'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:150:in block in search_file' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:158:inblock in each_localized_path'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:167:in each_sublocale' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:157:ineach_localized_path'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:145:in search_file' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:124:infind'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:108:in load' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:32:ininitialize'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/init.rb:114:in new' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/init.rb:114:ininit_config'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/init.rb:16:in setup' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb.rb:380:instart'
from /usr/bin/irb:12:in `'
eden
  • 1,979
  • 3
  • 16
  • 13

11 Answers11

281

This error can easily be fixed in the following steps:

1) Open terminal

2) Type nano /usr/local/Library/brew.rb

3) In the first line change “1.8″ to “Current”, so it should look like this:

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0

via http://blog.ic3man.gr/2014/06/homebrew-ruby-bad-interpreter-no-such-file-or-directory/

NuSkooler
  • 5,391
  • 1
  • 34
  • 58
raz0r
  • 3,372
  • 1
  • 12
  • 11
  • 14
    when I make this change, I get the error "Homebrew requires Leopard or higher. For Tiger support, see: https://github.com/mistydemeo/tigerbrew" even though I'm running yosemite – scientiffic Oct 21 '14 at 14:20
  • 4
    this gives a `Please, commit your changes or stash them before you can merge.` error when you try to `brew update` unfortunately. – Naoise Golden Oct 23 '14 at 18:37
  • 10
    "C" must be capitalized for Current `#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0` – Diablo Nov 24 '14 at 07:32
  • @Diablo I believe this was updated in 10.10.1. In earlier version the "C" was not capitalised. Thanks. – raz0r Nov 24 '14 at 08:52
  • I just tried this on 10.10 (not.10.10.1) and it was not working with "current" but when i changed it to "Current" it worked OK :) .... anyway your answer solved it for me :D – Diablo Nov 24 '14 at 09:29
  • It's also capital C for me on 10.10. (not 10.10.1) – LeEnno Nov 25 '14 at 08:32
  • This answer just make it more complicated :( I prefer doing fresh install. – GusDeCooL Dec 20 '14 at 03:28
  • This is not clean, feels like hacking – ericn Jan 11 '15 at 00:27
  • 1
    I also got the `Homebrew requires Leopard or higher` - I followed the answer below install xcode command line tools and it now works: http://stackoverflow.com/a/24225960/1062936 – greg Feb 04 '15 at 23:59
  • i get `$ sudo ln -s Current 1.8 $ brew update /usr/local/Library/brew.rb:18:in `': undefined method `help?’ for [“update”]:Array (NoMethodError) I just get this…(no matter what command just switch out “update” with the command)` – abc123 Feb 27 '15 at 08:10
  • You cannot "just commit" since that will lead to merge conflict and you still won't be able to update. The answer that works even for updates is actually the one from Otto, further down: http://stackoverflow.com/a/26553294/784635 – irakli Mar 10 '15 at 23:26
39

I updated to Yosemite and later found out brew was broken.

/usr/local/bin/brew: /usr/local/Library/brew.rb: 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory /usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

If you haven't made any changes to brew yet, here is what I recommend. Otherwise read further below.

  1. cd /System/Library/Frameworks/Ruby.framework/Versions/
  2. sudo ln -s Current 1.8
  3. brew update
  4. sudo unlink 1.8

Already made changes to brew files and stuck in a git mess?

I tried to edit /usr/local/Library/brew.rb but the local change to my git repo was preventing brew update from pulling down updates. I tried some other solutions mentioned on this page and from other sites and I ended up with a git mess and all I wanted to do was undo everything I had done to brew.

I committed my change but it made things worse. Eventually I had to undo my commits and git reset --hard HEAD~1 until I was at the right commit-ish. I had a mess of unversioned files too (I changed files permissions in /usr/Local) so I did a git clean -f -d which removed all unversioned files and directories and got me back to where I started before I made any changes.

Jason R
  • 2,085
  • 20
  • 12
  • 3
    This answer worked (including undoing git mess) where as the top voted answer left me with git problem. – Steve M Dec 23 '14 at 02:22
  • Very useful after upgrading your system! Thanks – coding addicted Feb 11 '15 at 14:41
  • This fails in El Capitan with "ln: operation not permitted" because of the rootless mode. You can find a workaround here: http://apple.stackexchange.com/questions/196224/unix-ln-s-command-not-permitted-in-osx-el-capitan-beta3 – Jorge Ortiz Feb 16 '16 at 10:17
36

Steps to fix it:

  1. Install command line tools for Xcode 6

  2. Reinstall brew:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  3. Once brew is installed, rvm will work:

    rvm install ruby
    

Worked for me, yahoo!

eden
  • 1,979
  • 3
  • 16
  • 13
  • i got ruby up and running, but this is still not working for me: http://stackoverflow.com/questions/24113251/ruby-gem-installation-error-after-osx-yosemite-and-xcode-6-installation – eden Jun 16 '14 at 02:16
  • I removed rvm and nginx completely and reinstalled them after installing Xcode 6 developer tools. Now it's working like a charm. – wout Oct 19 '14 at 08:29
  • 1
    This worked for me too, just wanted to clarify to run this command for step 1: xcode-select --install – James Toomey Dec 30 '14 at 16:03
33

Editing the script means brew update won't work; there are local edits to tracked files which causes the git pull to fail.

I did this, which I suspect is cleaner:

cd /usr/local/Library
git pull -q origin refs/heads/master:refs/remotes/origin/master

There are no complaints from brew doctor.

Otto
  • 18,761
  • 15
  • 56
  • 62
  • When I do this, I get an error about untracked files which must be moved before the merge. These are all files in Library/Formula/. – septerr Dec 08 '14 at 00:48
  • Assuming you haven't edited anything, when that happens to me it means I need to run `brew doctor` and follow some instructions. The issue being that `brew doctor` probably doesn't work for you, if you're here. You may just be able to `git stash` and carry on. – Otto Dec 08 '14 at 16:43
7

This is a conglomeration from answers from other people's posts as well as a bit of digging on Google, but I figured I'd put it up so a complete answer is in one place. Specifically this gets things to work now, but also lets you do brew updates as normal and gets everything clean again.

  1. Open /usr/local/Library/brew.rb (emacs/vi/nano/whatever)
  2. Change the first line to read: #!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0. You're just changing the "1.8" that was in that line to "Current" (make sure you keep the capital "C" otherwise git will get confused later).
  3. cd $(brew --repository)
  4. git add Library/brew.rb
  5. git commit -m "upgrading to ruby 2.0"
  6. brew update (or sudo brew update if your brew is setup to only do system changes with sudo)

Credit: a lot of this came from here, though I really recommend against doing git commit -am in your /usr/local folder.

Eli
  • 36,793
  • 40
  • 144
  • 207
  • This is the only solution that worked for me. It is because of the frequent super ugly messes like this that I'm moving away from Ruby and Rails for my next app. – Deborah Feb 02 '15 at 19:40
3

Like the one before said: 1) Change to current 2) install xcode 6

If you now have further problems with brew and ruby this should help: Somehow brew needs ruby on version 1.8, so create the folder:

sudo mkdir -p /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin

and make a symlink:

sudo ln -s /usr/bin/ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
2

Take a look at this tutorial here: http://ryantvenge.com/2014/09/ruby-homebrea-yosemite/

It worked for me!

user790999
  • 1,414
  • 3
  • 11
  • 9
  • While this link may answer the question, it is better to include the essential parts of the answer [here](http://meta.stackoverflow.com/a/8259) and provide the link for reference. Link-only answers can become invalid if the linked page changes. – bummi Jan 22 '15 at 22:33
1

I fixed this as follows:

  1. sudo chown -R $(whoami):admin /usr/local
  2. cd $(brew --prefix) && git fetch origin && git reset --hard origin/master
m00am
  • 5,910
  • 11
  • 53
  • 69
Alex Lin
  • 11
  • 1
0

brew update error can be fixed with this:

sudo chown -R $USER:admin /usr/local
cd /usr/local
git reset --hard origin/master
brew update

https://github.com/Homebrew/homebrew/issues/19140

gogasca
  • 9,283
  • 6
  • 80
  • 125
0

Note: Only do the below if you end up in a completely failed state, as this is very DANGEROUS

As an example I kept getting

$ sudo ln -s Current 1.8

$ brew update

/usr/local/Library/brew.rb:18:in ': undefined method help?’ for [“update”]:Array (NoMethodError)

I just get this…(no matter what command just switch out “update” with the command) I solved the problem by asking for a buddies /usr/local folder. I then made a backup of my /usr/local folder.

sudo mv /usr/local /usr/local.orig

I then moved his /usr/local to mine

sudo mv ~/Downloads/local /usr/local

Note: You will likely lose some data so make sure to make a backup.

Community
  • 1
  • 1
abc123
  • 17,855
  • 7
  • 52
  • 82
-1

I had problems trying to install Ruby using package managers. In fairness to these programs, I admit to having little experience with them and did not make the effort to dig deeper as most of the other responders did. I'm lazy and prefer to use a binary installer available for most opsys choices and many packages. Unfortunately, Ruby doesn't seem to supply one.

I found ruby-build easy to install (stand alone - not the plugin), and it built Ruby from sources without error and placed it where I wanted it.

Bingo - easy:) This looks like a good alternative for those of us of the package manager challenged persuasion.

Charlie