Install Ruby 2.2 on Mac OSX Catalina with ruby-install

时光总嘲笑我的痴心妄想 提交于 2021-02-05 02:41:08

问题


Here's what I get when I try to install Ruby 2.2:

$ ruby-install ruby 2.2.10
# ...
>>> Compiling ruby 2.2.10 ...
    CC = clang
    LD = ld
    LDSHARED = clang -dynamic -bundle
    CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens   -pipe
    XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE
    CPPFLAGS = -I/opt/X11/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/gdbm/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -I. -I.ext/include/x86_64-darwin19 -I./include -I.
    DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/gdbm/lib  -fstack-protector -Wl,-u,_objc_msgSend -Wl,-pie -framework CoreFoundation
    SOLIBS = -lgmp
Apple clang version 12.0.0 (clang-1200.0.31.1)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
translating probes probes.d
. ./vm_opts.h
file2lastrev.rb: does not seem to be under a vcs: .
make: [.revision.time] Error 1 (ignored)
./revision.h unchanged
compiling main.c
compiling dmydln.c
compiling miniinit.c
compiling miniprelude.c
compiling array.c
compiling bignum.c
compiling class.c
compiling compar.c
compiling complex.c
compiling dir.c
compiling dln_find.c
compiling encoding.c
encoding.c:825:2: error: implicit declaration of function 'rb_str_change_terminator_length' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        rb_str_change_terminator_length(obj, oldtermlen, termlen);
        ^
1 error generated.
make: *** [encoding.o] Error 1
!!! Compiling ruby 2.2.10 failed!
  • OS Version: 10.15.6
  • ruby-install version: 0.7.1

Any ideas on how to debug or fix this? I was previously able to install other versions of 2.2 before I upgraded my OS. I'm also able to install later versions like Ruby 2.7 with no problem


回答1:


After a lot of breaking my head and realizing that the error has to do with the compilation using GCC that is native to macOS, I decided to do a test.

Because older versions of Ruby need instructions that are no longer present in updated make, it is necessary to download an older version of Command Line Tools for Xcode.

First, remove your actual version with:

sudo rm -rf /Library/Developer/CommandLineTools

Ignore the error about missing git.

Proceed to https://developer.apple.com/download/more/ and download 11.x version of Command Line Tools for Xcode.

I downloaded version 11.5 and it worked. My return when running gcc -v

Configured with: --prefix = / Library / Developer / CommandLineTools / usr --with-gxx-include-dir = / Library / Developer / CommandLineTools / SDKs / MacOSX.sdk / usr / include / c ++ / 4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: / Library / Developer / CommandLineTools / usr / bin

To compare, with recent Command Lines, 12.x, you'll see something like:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin



回答2:


I'm on MacOS 10.15.6 and was able to get Ruby 2.2.10 to install via Rbenv (which uses ruby-build under the hood I believe).

I noticed your output includes 'openssl@1.1'. It might be worth checking your OpenSSL version. My 'global' OpenSSL version is 1.1.1g, but the recipe for Ruby 2.2.10 in the ruby-build repo specifies an older version - 1.0.2u (which was installed for me when running rbenv install 2.2.10): https://github.com/rbenv/ruby-build/blob/29d1749b2bbe4bb3e4ccb8cc05c42cad736f26b6/share/ruby-build/2.2.10#L1

There's a related issue regarding Ruby < 2.4 failing to install via ruby-install pointing the finger at OpenSSL versions: https://github.com/postmodern/ruby-install/issues/363#issuecomment-580699347




回答3:


I was able to install that version on Mac 10.15.7 using rvm.

I have openssl@1.1 installed with homebrew. If you run brew info openssl what do you see? I would try brew upgrade openssl first.

Try running export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" with the info brew returns. Then try rvm install 2.2.10. If that doesn't work I would try rvm install 2.2.10 --with-openssl-dir=/usr/local/opt/openssl --with-openssl-lib=/usr/local/opt/openssl/lib --with-openssl-include=/usr/local/opt/openssl/include just make sure those paths are correct for your system.

You may also need to run

export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"

export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

beforehand, which will be supplied by brew info.



来源:https://stackoverflow.com/questions/63926460/install-ruby-2-2-on-mac-osx-catalina-with-ruby-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!