首页 > 解决方案 > 使用 rbenv 或 rvm 在 Mojave OSX 上安装 Ruby 2.3.1

问题描述

首先,我使用的是 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 安装旧版本(2.3.1)的 ruby​​。我按照使用本教程在 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​​ 没问题,但我想完成教程,我担心使用新版本的 ruby​​ 可能会出现一些问题。

标签: ruby-on-railsrubyrvmrbenvmacos-mojave

解决方案


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

brew install openssl 

然后再试一次

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

推荐阅读