読者です 読者をやめる 読者になる 読者になる

TakayukiKoyama Geek Blog

Create, Entertain, Experience

YosemiteにアップデートしたらGemが動かないときは

今日、MacbookProをYosemiteにアップデートしました。

rails sをやろうとしたら失敗

$ rails s
Ignoring json-1.8.1 because its extensions are not built.  Try: gem pristine json-1.8.1
Ignoring atomic-1.1.14 because its extensions are not built.  Try: gem pristine atomic-1.1.14
Ignoring atomic-1.1.16 because its extensions are not built.  Try: gem pristine atomic-1.1.16
Ignoring atomic-1.1.16 because its extensions are not built.  Try: gem pristine atomic-1.1.16
Ignoring atomic-1.1.14 because its extensions are not built.  Try: gem pristine atomic-1.1.14
Ignoring bcrypt-3.1.7 because its extensions are not built.  Try: gem pristine bcrypt-3.1.7
Ignoring bcrypt-ruby-3.0.1 because its extensions are not built.  Try: gem pristine bcrypt-ruby-3.0.1
Ignoring bigdecimal-1.2.5 because its extensions are not built.  Try: gem pristine bigdecimal-1.2.5
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
Could not find libv8-3.16.14.3 in any of the sources
Run `bundle install` to install missing gems.

bundle installしても解決しない

$ bundle install
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20141113-1000-17h6k9f.rb extconf.rb

mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/folders/yz/1rw90x2s49d1dy1w_1pr0qlh0000gn/T/bundler20141113-1000-rp0fhx/libv8-3.16.14.3/gems/libv8-3.16.14.3 for inspection.
Results logged to /var/folders/yz/1rw90x2s49d1dy1w_1pr0qlh0000gn/T/bundler20141113-1000-rp0fhx/libv8-3.16.14.3/extensions/universal-darwin-14/2.0.0/libv8-3.16.14.3/gem_make.out
An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundling.

stackoverflowを調べてみる。

ruby - Gem not working after update to OS X 10.10 Yosemite Beta - Stack Overflow

 上記のサイトによると下記のコマンドで解決できるらしい。一旦、Gemを削除してアップデートする。

railsのgemも削除されるので注意

$ sudo rm -rf /Library/Ruby/Gems/*;
$ sudo gem update --system

bundle install できないときは

$ bundle install
/Library/Ruby/Site/2.0.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 5 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/koyamatakayuki/.gem/ruby/2.0.0:/Library/Ruby/Gems/2.0.0:/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0', execute `gem env` for more information
    from /Library/Ruby/Site/2.0.0/rubygems/dependency.rb:324:in `to_spec'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_gem.rb:58:in `gem'
    from /usr/bin/bundle:22:in `<main>'

$ sudo gem install bundler
Fetching: bundler-1.7.6.gem (100%)
Successfully installed bundler-1.7.6
Parsing documentation for bundler-1.7.6
Installing ri documentation for bundler-1.7.6
1 gem installed

 bundlerをインストールしただけでは解決しなかった。

そもそもgem installにsudoが必要ということは

 管理者用のrubyはあるけど、ユーザ用のrubyがない。rvmコマンドを叩いてみると、なくなってた。

 なので、rvmでrubyを入れなおす。

$ curl -L get.rvm.io | bash -s stable
$ [ -s ${HOME}/.rvm/scripts/rvm ] && source ${HOME}/.rvm/scripts/rvm
$ rvm get head
$ rvm get latest
$ source ~/.bash_profile
$ source ~/.profile
$ rvm install 2.0.0
$ gem install rails
$ bundle install

 bundle installで以下のエラーが出る場合

$ bundle install
(中略)
An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundling.

 言われたとおり、gem install libv8 -v '3.16.14.3'とやってもうまくいかないときがあるので、そのときは下記のオプションを付けて下さい。古いlibv8があるとtherubyracerに影響する可能性があるので、アンインストールします。

$ gem uninstall libv8
$ gem install libv8 -v '3.16.14.3' -- --with-system-v8

 therubyracerで以下のエラーが出る場合

$ bundle install
(中略)
An error occurred while installing therubyracer (0.12.0), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.0'` succeeds before bundling.

 となるなら、Gemfileのtherubyracerを以下のように書き換えます。参考:Stackoverflow

$ vim Gemfile
gem "therubyracer", "~> 0.12"

$ bundle install

 これでrails sしたら、動いた!

広告を非表示にする