久しぶりにRailsを勉強しようとしたら開始直後にハマりまくった

bundler で各種gemをインストールしようとすると失敗する

$ bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/..........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.2.2
Using i18n 0.6.9
Using minitest 4.7.5
Using multi_json 1.9.2
Using thread_safe 0.3.3
Using tzinfo 0.3.39
Using activesupport 4.0.2
Using builder 3.1.4
Using erubis 2.7.0
Using rack 1.5.2
Using rack-test 0.6.2
Using actionpack 4.0.2
Using mime-types 1.25.1
Using polyglot 0.3.4
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 4.0.2
Using activemodel 4.0.2
Using activerecord-deprecated_finders 1.0.3
Using arel 4.0.2
Using activerecord 4.0.2
Using bundler 1.6.0.pre.2
Using coffee-script-source 1.7.0
Using execjs 2.0.2
Using coffee-script 2.2.0
Using thor 0.19.1
Using railties 4.0.2
Using coffee-rails 4.0.1
Using hike 1.2.3
Using jbuilder 1.5.3
Using jquery-rails 3.1.0

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

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling generator.c
linking shared-object json/ext/generator.bundle
clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make: *** [generator.bundle] Error 1

make failed, exit code 2


Gem files will remain installed in /Users/ihiro81/app_name/vendor/bundle/ruby/2.0.0/gems/json-1.8.1 for inspection.
Results logged to /Users/ihiro81/app_name/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-13/2.0.0/json-1.8.1/gem_make.out
An error occurred while installing json (1.8.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.1'` succeeds before bundling.

すでにインストールされてるのに、gem install jsonを実行するようにいってきます。

bundleとかgemに関する問題かと思いそっち方面で調べるけどことごとく失敗。

ふと、実行結果を見なおしてるとエラーメッセージでてた。(気づくの遅い

clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]

これでググってみると以下のサイトがヒット
https://langui.sh/2014/03/10/wunused-command-line-argument-hard-error-in-future-is-a-harsh-mistress/

どうやらxcodeコマンドラインツールがosアップデートの際に、clang っていうのが更新されたのが原因とのこと。

以下のコマンドを実行する。

export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"

ただし、こちらの方法でも将来的に動作しなくなるとのことなので注意が必要みたい。

もう一度コマンドを実行

$ bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/..........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.2.2
Using i18n 0.6.9
Using minitest 4.7.5
Using multi_json 1.9.2
Using thread_safe 0.3.3
Using tzinfo 0.3.39
Using activesupport 4.0.2
Using builder 3.1.4
Using erubis 2.7.0
Using rack 1.5.2
Using rack-test 0.6.2
Using actionpack 4.0.2
Using mime-types 1.25.1
Using polyglot 0.3.4
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 4.0.2
Using activemodel 4.0.2
Using activerecord-deprecated_finders 1.0.3
Using arel 4.0.2
Using activerecord 4.0.2
Using bundler 1.6.0.pre.2
Using coffee-script-source 1.7.0
Using execjs 2.0.2
Using coffee-script 2.2.0
Using thor 0.19.1
Using railties 4.0.2
Using coffee-rails 4.0.1
Using hike 1.2.3
Using jbuilder 1.5.3
Using jquery-rails 3.1.0
Installing json 1.8.1
Installing tilt 1.4.1
Installing sprockets 2.11.0
Installing sprockets-rails 2.0.1
Installing rails 4.0.2
Installing rdoc 4.1.1
Installing sass 3.2.19
Installing sass-rails 4.0.3
Installing sdoc 0.4.0
Installing sqlite3 1.3.9
Installing turbolinks 2.2.2
Installing uglifier 2.5.0
Your bundle is complete!
It was installed into ./vendor/bundle
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

成功しました!

rake を実行すると失敗する

しかし、喜んだのもつかの間すぐにまたハマるorz

rake db:migrate
Could not find rake-10.2.2 in any of the sources
Run `bundle install` to install missing gems.

rakeがインストールされているにもかかわらずまたもエラーに。
bundle exec を付けると、プロジェクトのライブラリ保存場所から読みだせという意味になるとのことなので実行してみた。

$ bundle exec rake db:migrate
Could not find rake-10.2.2 in any of the sources
Run `bundle install` to install missing gems.

こちらでもダメでした。

最終的に成功したのはこちらの記事
http://altarf.net/computer/rails/1814

HOMEにある.gemを削除でいけるとのこと。
HOMEに.gemなんて普通作らないよね。ッて書いてありましたが、なぜか自分のところにもありましたw

rm -rf ~/.gem

うーん、また失敗。同じエラーに。

同じページにやったけどダメだったっていうのもあったので一応やってみたらこっちでビンゴでした。

ここ↓

Could not find rake with bundle exec

これを見ると、 .bundle/config の
BUNDLE_DISABLE_SHARED_GEMS: ’1′
の行を消せ! と書いてある。
※これはさっきbundle install の先を変えた際にconfigへ追加される行のひとつ

それで動く、 と。。。
え、けどこれって共通のgemを見なくする設定だよね。
さっきbundle install でvender/bundler にわざわざインストールしてるんですが。。
まぁいいや、消してみよ。

消した ⇒ ダメ

というわけで、BUNDLE_DISABLE_SHARED_GEMS: ’1′ を消して実行

$ bundle exec rake db:migrate
/Users/ihiro81/app_name/vendor/bundle/ruby/2.0.0/gems/sqlite3-1.3.9/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault at 0x00000000000418
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]


長いので省略

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Abort trap: 6

.gem は削除する必要があったのかなかったのかわかりませんが、成功しました!

ここまでやったのはいいけど

vagrant使ったほうがあとあとも楽なんじゃないかと気づき、さっそく試してみたら何も問題なくできました。

最近だとmacに直接インストールしてやる必要ないですねー。

逆に特有の問題でハマります。

vagrant最高!!