ruby-on-rails - 使用 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 可能会出现一些问题。
解决方案
安装 Xcode 安装 brew 和 openssl (或更新它)
brew install openssl
然后再试一次
rvm install 2.3.1 --with-openssl-dir=`brew --prefix openssl`
推荐阅读
- c# - 使用实体框架单击按钮后解决 Datagridview 重新加载?
- javascript - 使用 html 和 javascript 创建一个阅读更多按钮
- sql - 如何在 SQL Server 中根据百分比获取表数据?
- ios - 点击注销时 SwiftUI 将应用程序重置为登录屏幕
- arrays - 使用 powershell 将 Azure DevOps 变量设置为 int 而不是 string
- android - 在模块 jetified-com.google.zxing.client.android.captureactivity.jar 和 jetified-core-3.3.3.jar 中发现重复的类 com.google.zxing.Binarizer
- javascript - 我在反应中使用 for of 循环,但这给了我一个错误“x 未定义”。我可以使用简单的 for 循环,但使用 for of 循环会更干净
- php - 我想更改 Woocommerce 中的特定字符串
- javascript - ReactJS - 使用 setInterval 减少计时器
- c++ - Qml 上下文对象在应用程序关闭时为空