mac brew update 报错
环境为mac, 总共报了三种错误。
对应三种不同的解法。
1. 第一种如下, 提示 1.8 的版本找不到
$ brew update /usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory /usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
这种比较简单。 原因是mac 升级到 某一个版本之后, ruby版本升级到2.0 了, 但是 brew.rb 中的版本号是 写死了1.8 , 需要修改下。
先检查一下自己 ruby版本 $ cd /System/Library/Frameworks/Ruby.framework/Versions/
一般来说, 都是 2.0
之后 $ vi /usr/local/Library/brew.rb 将第一行的 1.8 , 修改成 2.0 即可。
详细见: http://stackoverflow.com/questions/24225959/how-to-get-ruby-homebrew-rvm-to-work-on-yosemite
2. 第二种情况, 错误提示如下。
$ brew update /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:89:in `run': ERROR: Failed to build gem native extension. (Gem::Ext::BuildError) /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb checking for rb_thread_blocking_region()... yes checking for sys/select.h... yes checking for poll.h... yes checking for sys/epoll.h... no checking for sys/event.h... yes checking for sys/queue.h... yes checking for port.h... no checking for sys/resource.h... yes creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling monitor.c In file included from monitor.c:6: In file included from ./nio4r.h:10: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward/rubyio.h:2:2: warning: use "ruby/io.h" instead of "rubyio.h" [-W#warnings] #warning use "ruby/io.h" instead of "rubyio.h" ^ 1 warning generated. In file included from monitor.c:6: In file included from ./nio4r.h:10: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward/rubyio.h:2:2: warning: use "ruby/io.h" instead of "rubyio.h" [-W#warnings] #warning use "ruby/io.h" instead of "rubyio.h" ^ 1 warning generated. compiling nio4r_ext.c In file included from nio4r_ext.c:6: In file included from ./nio4r.h:10: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward/rubyio.h:2:2: warning: use "ruby/io.h" instead of "rubyio.h" [-W#warnings] #warning use "ruby/io.h" instead of "rubyio.h" ^ In file included from nio4r_ext.c:7: ./../libev/ev.c:481:48: warning: '/*' within block comment [-Wcomment] /*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ ^ ./../libev/ev.c:974:42: error: '_Noreturn' keyword must precede function declarator ecb_inline void ecb_unreachable (void) ecb_noreturn; ^~~~~~~~~~~~ _Noreturn ./../libev/ev.c:777:26: note: expanded from macro 'ecb_noreturn' #define ecb_noreturn _Noreturn ^ ./../libev/ev.c:1535:31: warning: 'extern' variable has an initializer [-Wextern-initializer] EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */
make failed, exit code 2
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nio4r-1.0.0 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-16/2.0.0/nio4r-1.0.0/gem_make.out
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:51:in `block in make'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:43:in `each'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:43:in `make'
from /Library/Ruby/Site/2.0.0/rubygems/ext/ext_conf_builder.rb:43:in `block in build'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tempfile.rb:324:in `open'
from /Library/Ruby/Site/2.0.0/rubygems/ext/ext_conf_builder.rb:17:in `build'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:161:in `block (2 levels) in build_extension'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:160:in `chdir'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:160:in `block in build_extension'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:159:in `synchronize'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:159:in `build_extension'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:198:in `block in build_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:195:in `each'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:195:in `build_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1436:in `block in build_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/user_interaction.rb:45:in `use_ui'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1434:in `build_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/stub_specification.rb:60:in `build_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/basic_specification.rb:56:in `contains_requirable_file?'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:925:in `block in find_inactive_by_path'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in `each'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in `find'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in `find_inactive_by_path'
from /Library/Ruby/Site/2.0.0/rubygems.rb:185:in `try_activate'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:132:in `rescue in require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from /usr/local/Library/Homebrew/extend/pathname.rb:2:in `<top (required)>'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Library/Homebrew/global.rb:3:in `<top (required)>'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Library/brew.rb:17:in `<main>'
这种情况, 需要升级 gem 的版本。
一般来说是用 $ sudo gem update --system 来进行升级, 但是会报错。
$ sudo gem update --system Password: Sorry, try again. Password: ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
这种错误, 因为 gem源换了, 貌似原来的淘宝源不维护了。 具体见: https://ruby.taobao.org/ 。 需要跟换一下gem源
$ sudo gem update --system Password: Updating rubygems-update Fetching: rubygems-update-2.6.7.gem (100%) ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/update_rubygems
这种错误也没明白, 提示是 没有操作权限。 在网上查了一个方法, 修改命令成如下方式就可以了。
$ sudo gem update -n /usr/local/bin --system
执行完成之后, gem -v 可以看到 版本更新了。
这样, 第二个 gem update的错误,就快要解决了。
第三个问题, 继续 brew update, 出现如下错误。
$ brew update /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mach (LoadError) from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /usr/local/Library/Homebrew/extend/pathname.rb:2:in `<top (required)>' from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /usr/local/Library/Homebrew/global.rb:3:in `<top (required)>' from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /usr/local/Library/brew.rb:17:in `<main>'
根据 http://stackoverflow.com/questions/24652996/homebrew-not-working-on-osx 的最高票答案就可以解决。
$ sudo chown -R $(whoami):admin /usr/local
如果这个指令没有解决, 则采用下面的步骤。
1. open terminal 2. $ cd /usr/local/Homebrew , 这里的路径我是: /usr/local/Library/ 3. $ git reset --hard 4. $ git clean -df 5. $ brew update
至此, 这个问题解决了。