Homebrew更新:
brew update && brew upgrade
当出现错误:
fatal: couldn't find remote ref refs/heads/master
执行:
brew tap --repair
Ruby安装:
1、查看当前Homebrew版本:
brew --version
2、查看当前Ruby版本:
ruby --version
3、安装Ruby
brew install ruby
感谢大佬:Mac环境下安装Ruby
Cocoapods安装:
sudo xcrun gem install cocoapods
安装报错:
Building native extensions. This could take a while...
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/ext/builder.rb:76: warning: Insecure world writable dir /opt/homebrew/bin in PATH, mode 040777
ERROR: Error installing cocoapods:ERROR: Failed to build gem native extension.current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/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 ./siteconf20220606-94797-1ua745k.rb extconf.rb
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1565: warning: Insecure world writable dir /opt/homebrew/bin in PATH, mode 040777
checking for ffi.h... *** 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-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:585:in `block in try_compile'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'from extconf.rb:10:in `system_libffi_usable?'from extconf.rb:42: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-20/2.6.0/ffi-1.15.5/mkmf.logextconf failed, exit code 1Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/gem_make.out
根据提示:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/mkmf.log
打开这个文件看一下:
package configuration for libffi is not found
"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-darwin20 -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 */
报错原因:
ccl@cclMacBookPro ruby-2.6.0 % cd $(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0ccl@cclMacBookPro ruby-2.6.0 % ls
ruby ruby.h universal-darwin21
发我这个目录下确实没有 universal-darwin20
解决
sudo ln -sf universal-darwin21 universal-darwin20
然后在ls 一下,发现已经有了 universal-darwin20
ruby ruby.h universal-darwin20 universal-darwin21
继续执行, 就可以正常安装了
sudo xcrun gem install cocoapods
感谢大佬:解决sudo xcrun gem install cocoapods 时报错 ‘ruby/config.h‘ file not found
报错集合:
1、brew install报错"fatal: not in a git directory"
在macbook
上使用brew
安装软件时,可能会遇到问题,报错如下:
fatal: not in a git directory
Error: Command failed with exit 128: git
解决方法:
使用brew -v
,仔细看,可以发现有两个fatal
(致命错误)提示:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-coregit config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
这里注意:原博主说使用这两行进行解决,但我直接复制使用并没有解决,仔细看了一下是因为每个人的地址有出入,但是返回的提示里边有你的环境相对应的代码,直接复制出来执行就行了。
完成之后,再次执行brew -v
查看,没有报错了:
再次使用brew install
安装软件,即可成功。
感谢大佬:MacBook使用笔记:brew install报错"fatal: not in a git directory"解决