问题
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
回答1:
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
回答2:
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!
回答3:
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.
来源:https://stackoverflow.com/questions/54363030/cannot-install-any-version-of-ruby-on-mojave-internal-ranlib-command-failed