Installing Ruby 2.3.1 on Mojave OSX with rbenv or

2019-08-02 13:25发布

First off I am on OSX Mojave 10.14, I have previously upgraded it from 10.13. I bought it new with 10.13.

I am trying to follow this tutorial:

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

I want to make sure that I have the same environment setup using the same version of rails and ruby.

When I try to use rbenv to change my version of ruby (currently 2.6.1) to 2.3.1 I use the following command:

rbenv install 2.3.1

And I get the following error:

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

I have tried looking on the internet where CFString.h might be, and I have found this useful command to list the directories where clang searches:

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

This is the output:

$ 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.

Also I am not sure if it is using clang or gcc. Here's the gcc output:

$ 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.

I have tried reinstalling xcode command line tools with this command:

xcode-select --install

I have also tried to use rvm to install the older version (2.3.1) of ruby. I follow the steps for installing rvm on osx using this tutorial:

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

I installed the pgp key and do the curl command to install it:

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

but I get the following error:

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

So in summary, I am seeking answers that that help with installing ruby 2.3.1 using rbenv or rvm. Considering that rvm will not install and rbenv fails to find the include files.

I seem to be fine using the new version of ruby for the tutorial but I want to complete the tutorial, and I am worried that maybe something will not go smoothly using the newer version of ruby.

2条回答
▲ chillily
2楼-- · 2019-08-02 13:52

install Xcode install brew and openssl (or update it)

brew install openssl 

and then try again

rvm install 2.3.1 --with-openssl-dir=`brew --prefix openssl`
查看更多
时光不老,我们不散
3楼-- · 2019-08-02 13:59

Reinstall the header files with:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
查看更多
登录 后发表回答