Cocoapods安装失败,无法更改ruby本地版本

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

MacBook Pro、macOS Catalina 10.15.7

尝试安装 cocoapods 时有两个主要问题,第一个是我在尝试将 ruby 版本更改为 2.7.5 时收到错误,因为我能够更改全局但不能更改本地:

user@MacBook-Pro-de-User / % rbenv versions      
  system
* 2.7.5 (set by /Users/user/.rbenv/version)
  mruby-3.0.0

user@MacBook-Pro-de-User / % ruby -v                   
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

user@MacBook-Pro-de-User / % sudo rbenv local 2.7.5    
Password:
/usr/local/Cellar/rbenv/1.2.0/libexec/rbenv-version-file-write: line 19: .ruby-version: Read-only file system

我遇到的第二个问题是尝试安装 cocoapods 时:

user@MacBook-Pro-de-User / % sudo gem install cocoapods
Password:
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.3/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20240111-988-w3p1cs.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
    --with-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --enable-debug
    --disable-debug
    --enable-system-libffi
    --disable-system-libffi
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
    from extconf.rb:9:in `system_libffi_usable?'
    from extconf.rb:46:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.16.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.3 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.16.3/gem_make.out

mkmf.log:

"pkg-config --exists libffi"
| pkg-config --libs libffi
=> "-lffi\n"
"xcrun clang -o conftest -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib   -arch x86_64   -lruby.2.6   "
In file included from conftest.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks')
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

还尝试执行brew install cocoapods,但它卡在 llvm cmake --build .,如果我尝试仅安装 llvm:

user@MacBook-Pro-de-User /usr % brew install llvm
    Warning: You are using macOS 10.15.
    We (and Apple) do not provide support for this old version.
    It is expected behaviour that some formulae will fail to build in this old version.
    It is expected behaviour that Homebrew will be buggy and slow.
    Do not create any issues about this on Homebrew's GitHub repositories.
    Do not create any issues even if you think this message is unrelated.
    Any opened issues will be immediately closed without response.
    Do not ask for help from Homebrew or its maintainers on social media.
    You may ask for help in Homebrew's discussions but are unlikely to receive a response.
    Try to figure out the problem yourself and submit a fix as a pull request.
    We will review it but may or may not accept it.
    
    ==> Fetching llvm
    ==> Downloading https://raw.githubusercontent.com/Homebrew/homebrew-core/a656e8d
    ######################################################################### 100.0%
    ==> Downloading https://github.com/llvm/llvm-project/releases/download/llvmorg-1
    Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/0f45ee25df06c0fb1fa6d0d6df4677a9487c4b95f1020855dc61f95b532eb9c0--llvm-project-17.0.6.src.tar.xz
    ==> cmake -G Ninja .. -DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;lld;lldb;ml
    ==> cmake --build . 
ruby cocoapods llvm
2个回答
0
投票

所以我在这里找到了解决问题的方法:Ruby 安装。 cocoapods 安装的问题是因为旧的 ruby 版本 (2.6.3),并且无法在本地更改为其他版本,可能是因为即使安装了该版本,我在安装中也遇到了错误。有关安装的问题是因为 openssl 版本,它使用的是 3.0 而不是 1.1,这似乎是正确的安装版本。只需安装 1.1 openssl 版本并使用该 openssl 版本安装 ruby 版本即可。

brew install [email protected]
rvm install ruby-3.3.0 --with-openssl-dir=$(brew --prefix [email protected])

0
投票

MacBook Air M1 2020 - MacOS Sonoma 14.4.1 - Ruby 3.3.0(使用 RVM)

我找到了基于@Jono 的答案的解决方案。

brew install [email protected]
rvm install ruby-3.3.0 --with-openssl-dir=$(brew --prefix [email protected])
rvm --default use 3.3.0
sudo gem install -n /usr/local/bin cocoapods
© www.soinside.com 2019 - 2024. All rights reserved.