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

问题描述 投票:1回答:2

首先,我在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作为教程,但我想完成教程,我担心使用更新版本的ruby可能会出现问题。

ruby-on-rails ruby rvm rbenv macos-mojave
2个回答
2
投票

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

brew install openssl 

然后再试一次

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

0
投票

使用以下命令重新安装头文件:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
© www.soinside.com 2019 - 2024. All rights reserved.