使用 rbenv 或 rvm 在 Mojave OSX 上安装 Ruby 2.3.1

Installing Ruby 2.3.1 on Mojave OSX with rbenv or rvm

首先,我使用的是 OSX Mojave 10.14,我之前已将其从 10.13 升级。我是用 10.13 新买的。

我正在尝试学习本教程:

https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one

我想确保使用相同版本的 rails 和 ruby.

进行相同的环境设置

当我尝试使用 rbenv 将我的 ruby 版本(当前为 2.6.1)更改为 2.3.1 时,我使用以下命令:

rbenv install 2.3.1

我收到以下错误:

file.c:23:10: fatal error: 'CoreFoundation/CFString.h' file not found

我尝试在互联网上查找 CFString.h 可能所在的位置,并且我发现了这个有用的命令来列出 clang 搜索的目录:

echo "#include <CoreFoundation/CFString.h>" | clang -v -x c -

这是输出:

$ echo "#include <CoreFoundation/CFString.h>" | clang -v -x c -
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
 "/usr/local/Cellar/llvm/8.0.0/bin/clang-8" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 409.12 -v -resource-dir /usr/local/Cellar/llvm/8.0.0/lib/clang/8.0.0 -fdebug-compilation-dir /Users/nfgallimore/Code/todos-api -ferror-limit 19 -fmessage-length 121 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/p6/pttqjn_s20g97kv6jxzwdl2m0000gn/T/--65bd40.o -x c -
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-apple-darwin18.0.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/Cellar/llvm/8.0.0/lib/clang/8.0.0/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
<stdin>:1:10: fatal error: 'CoreFoundation/CFString.h' file not found
#include <CoreFoundation/CFString.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

另外我不确定是用clang还是gcc。这是 gcc 输出:

$ echo "#include <CoreFoundation/CFString.h>" | gcc -v -x c -
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 409.12 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0 -fdebug-compilation-dir /Users/nfgallimore/Code/todos-api -ferror-limit 19 -fmessage-length 121 -stack-protector 1 -fblocks -fencode-extended-block-signature -fobjc-runtime=macosx-10.14.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/p6/pttqjn_s20g97kv6jxzwdl2m0000gn/T/--9ee343.o -x c -
clang -cc1 version 10.0.0 (clang-1000.11.45.5) default target x86_64-apple-darwin18.0.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
<stdin>:1:10: fatal error: 'CoreFoundation/CFString.h' file not found
#include <CoreFoundation/CFString.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

我已尝试使用此命令重新安装 xcode 命令行工具:

xcode-select --install

我也尝试过使用 rvm 安装 ruby 的旧版本 (2.3.1)。 我按照本教程在 osx 上安装 rvm 的步骤进行操作:

https://usabilityetc.com/articles/ruby-on-mac-os-x-with-rvm/

我安装了 pgp 密钥并执行 curl 命令来安装它:

\curl -sSL https://get.rvm.io | bash -s stable --ruby

但我收到以下错误:

emacs: standard input is not a tty
curl: (23) Failed writing body (0 != 2759)

所以总而言之,我正在寻找有助于使用 rbenv 或 rvm 安装 ruby 2.3.1 的答案。考虑到 rvm 不会安装并且 rbenv 找不到包含文件。

我似乎可以使用新版本的 ruby 作为教程,但我想完成教程,我担心使用新版本的 [=71] 可能有些事情不会顺利进行=].

安装Xcode 安装 brew 和 openssl(或更新它)

brew install openssl 

然后重试

rvm install 2.3.1 --with-openssl-dir=`brew --prefix openssl`

重新安装头文件:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg