Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claui/3fb9f66bc2cfdecd0c33c3f976cc6125 to your computer and use it in GitHub Desktop.
Save claui/3fb9f66bc2cfdecd0c33c3f976cc6125 to your computer and use it in GitHub Desktop.
[SOLVED] Please help me get Homebrew working again on the DTK

Update: SOLVED

Thanks to @indirect’s help, I’m back up and running. Turns out there’s that directory /Library/Ruby/Gems/2.6.0/specifications/default. It contains a couple of gemspecs you really can’t (and shouldn’t ever) delete.

With the default gemspecs back in place, I was able to apply the fiddle hack mentioned below, and got Homebrew working again.


Original issue

My DTK gives me the dreaded symbol '_ffi_prep_closure' not found error after I deleted /Library/Ruby.

The following workaround no longer has any effect for me:

cd "$(mktemp -d)" \
  && git clone https://github.com/ruby/fiddle \
  && cd fiddle \
  && bundle install --path vendor/bundle \
  && bundle exec rake build \
  && sudo gem install pkg/fiddle-1.0.1.gem

Would appreciate any pointers so I can avoid setting up the whole machine from scratch.

Am on Big Sur Beta 3, Xcode 12 Beta 3.

Output of /usr/bin/ruby -rfiddle -e '':

Traceback (most recent call last):
	4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	3: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	2: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/fiddle.rb:2:in `<top (required)>'
	1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': dlopen(/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/fiddle.bundle, 0x0009): symbol '_ffi_prep_closure' not found, expected in flat namespace by '/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/fiddle.bundle' - /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/fiddle.bundle (LoadError)
@whitehat007
Copy link

Can you describe the exact steps you took to solve the issue?

@claui
Copy link
Author

claui commented Nov 6, 2020

@whitehat007 I restored the /Library/Ruby/Gems/2.6.0/specifications/default directory from a known-good source.

If you already lost that directory and don’t want to reinstall macOS, try installing the exact gem versions specified in that directory (as of macOS 11.0.1, build 20B5022a but untested):

(
  set -x;

  sudo gem install bigdecimal --version 1.4.1
  sudo gem install bundler --version 1.17.2
  sudo gem install cmath --version 1.0.0
  sudo gem install csv --version 3.0.9
  sudo gem install date --version 2.0.0
  sudo gem install dbm --version 1.0.0
  sudo gem install e2mmap --version 0.1.0
  sudo gem install etc --version 1.0.1
  sudo gem install fcntl --version 1.0.0
  sudo gem install fiddle --version 1.0.0
  sudo gem install fileutils --version 1.1.0
  sudo gem install forwardable --version 1.2.0
  sudo gem install io-console --version 0.4.7
  sudo gem install ipaddr --version 1.2.2
  sudo gem install irb --version 1.0.0
  sudo gem install json --version 2.1.0
  sudo gem install logger --version 1.3.0
  sudo gem install matrix --version 0.1.0
  sudo gem install mutex_m --version 0.1.0
  sudo gem install openssl --version 2.1.2
  sudo gem install ostruct --version 0.1.0
  sudo gem install prime --version 0.1.0
  sudo gem install psych --version 3.1.0
  sudo gem install rdoc --version 6.1.0
  sudo gem install rexml --version 3.1.9
  sudo gem install rss --version 0.2.7
  sudo gem install scanf --version 1.0.0
  sudo gem install sdbm --version 1.0.0
  sudo gem install shell --version 0.7
  sudo gem install stringio --version 0.0.2
  sudo gem install strscan --version 1.0.0
  sudo gem install sync --version 0.5.0
  sudo gem install thwait --version 0.1.0
  sudo gem install tracer --version 0.1.0
  sudo gem install webrick --version 1.4.2
  sudo gem install zlib --version 1.0.0
)

To prevent messing up system Ruby in the future, I learned the following technique to clean up system Ruby properly:

sudo rm -rf \
  /Library/Ruby/Gems/2.6.0/{build_info,cache,doc,extensions,gems} \
  /Library/Ruby/Gems/2.6.0/specifications/*.gemspec \
  /Library/Ruby/Site

@johnryan16
Copy link

Thank you! Spent an hour finding this.

@claui
Copy link
Author

claui commented Feb 21, 2021

@johnryan16 Glad it worked for you!

@HeyJoplin
Copy link

Nice one, thanks for sharing!
I've also messed the standard /Library/Ruby instalation and at least in macOS 11.2.1 in M1, I could restore the original files fom:
/System/Library/Templates/Data/Library/Ruby/

Hopefully, Apple won't ship ruby as part of the OS anymore in the next releases...

@claui
Copy link
Author

claui commented Feb 24, 2021

Nice find @gianza!

@burditto
Copy link

gianza, thank you!

@vikivyas
Copy link

vikivyas commented Sep 28, 2021

Warning: CocoaPods is installed but broken. Skipping pod install.
You appear to have CocoaPods installed but it is not working.
This can happen if the version of Ruby that CocoaPods was installed with is different from
the one being used to invoke it.
This can usually be fixed by re-installing CocoaPods.
To re-install see https://guides.cocoapods.org/using/getting-started.html#installation for
instructions.

CocoaPods not installed or not in valid state.
Error launching application on iPhone 13.

@ahmetbostanciklioglu
Copy link

It's a life saver comment, thanks for it.

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