9

I know there are a few silimar issues to this one, but I cannot find one that matches my issue.

I cannot install any version of ruby with either rvm nor rbenv. Both result in the same error. For example, here's an extract for the logs when installing ruby 2.5.3:

compiling loadpath.c
making srcs under enc
linking static-library libruby.2.5.3-static.a
make[1]: Nothing to be done for `srcs'.
generating transdb.h
/opt/local/bin/ranlib: object: libruby.2.5.3-static.a(dln.o) malformed object (unknown load command 1)
ar: internal ranlib command failed
make: *** [libruby.2.5.3-static.a] Error 1
make: *** Waiting for unfinished jobs....
transdb.h updated

The issue seems to be here:

/opt/local/bin/ranlib: object: libruby.2.5.3-static.a(dln.o) malformed object (unknown load command 1)
ar: internal ranlib command failed
make: *** [libruby.2.5.3-static.a] Error 1

What I've tried

  • Installing, reinstalling, uninstalling rvm, rbenv.
  • Updating, reinstalling XCode.
  • Deleting, installing, XCode command line tools.

What is causing this?

Update

gcc --version returns:

gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
andy
  • 8,775
  • 13
  • 77
  • 122
  • 1
    Is this a fresh installation of Mojave or did you upgrade from (High) Sierra? – Stefan Jan 25 '19 at 10:43
  • 1
    IIRC, `/opt/local` is the default prefix for MacPorts. Maybe you have a faulty gcc installation? What does `gcc --version` say? BTW, I'm running the default gcc which came with macOS / XCode and rbenv installation worked just fine. – Stefan Jan 25 '19 at 10:53
  • Hey Stefan, thanks. So it was an upgrade from Sierra. I updated the question with the `version` result. Interestingly, when I tried to install something today using macports (which I don't usually use) it thinks I don't have XCode installed... – andy Jan 25 '19 at 11:15
  • 1
    My `gcc --version` shows `/Applications/Xcode.app/Contents/Developer` instead of `/Library/Developer/CommandLineTools`. That's also what `xcode-select -p` prints. I also have slightly higher versions, i.e. `clang-1000.11.45.5` and `x86_64-apple-darwin18.2.0`. Maybe you're running an outdated (or Sierra specific) version? Have you tried installing XCode from scratch? – Stefan Jan 25 '19 at 11:56
  • 1
    BTW, have you tried to reinstall (or remove) MacPort's ranlib? (or the package it came from) – Stefan Jan 25 '19 at 12:00
  • hey @Stefan thanks! Yeah I'll try Xcode, good idea. In terms of ranlib, it's not in my macports list and I honestly don't know where it is coming from. In fact macport list shows 0 (I don't remember ever having used macports explicitly, I usually use brew for everything) – andy Jan 28 '19 at 15:01
  • 2
    In that case, try [uninstalling MacPorts](https://guide.macports.org/chunked/installing.macports.uninstalling.html), so `/opt/local/bin/ranlib` isn't used anymore. – Stefan Jan 28 '19 at 15:06
  • @Stefan thanks again! Ok I'll need to wait until XCode downloads/installs again so lemme get back to you in 4 years... – andy Jan 28 '19 at 16:32

3 Answers3

9

For anyone else who steps on the same landmine, for me it was that there was an incompatible copy of ranlib from homebrew via the cctools package. To fix it, I just uninstalled it:

brew uninstall cctools

Chris Conover
  • 8,889
  • 5
  • 52
  • 68
  • Thank you for the solution! After attempting so many suggestions, this is what finally got rvm to again install new Ruby versions on my Mac. – sutch Mar 12 '19 at 12:09
  • Thank you very much for sharing this. It seems to be a rare situation, but that only makes fiendishly hard to sort out. – Paolo Perrotta Mar 16 '19 at 16:39
  • I had the same issue with rbenv and have been looking for the solution for days, and this finally solved the issue! Thank you so much! – tg_so Mar 05 '20 at 08:51
3

For those who find this and aren't helped by the above solution...

I ran into this issue as well. In my case it was due to MacPorts being outdated after I upgraded to (MacOS) Mojave.

I followed the steps listed on MacPorts' migration guide here: https://trac.macports.org/wiki/Migration

Closed and reopened Terminal (just b/c)

ran rvm install ruby and got Install of ruby-2.6.0 - #complete, hooray!

Ryan Crews
  • 3,015
  • 1
  • 32
  • 28
0

So, I think the fix to this was running:

$ sudo xcodebuild -runFirstLaunch

Why? I'm not sure. My suspicion is I tried to build ruby before updating XCode. But once I had updated XCode I suspect the wrong/older command line tool was still being referenced somehow.

I don't know exactly what fixed this but I completely deleted XCode and ruby still didn't install.

Then I completely deleted command line tools and ruby still didn't install.

Then I reinstalled just the command line tools without XCode and ruby still didn't install.

Then I ran this runFirstLaunch command and ruby installed.

andy
  • 8,775
  • 13
  • 77
  • 122