初心者エンジニアがrailsチュートリアルでつまずいたので書いとく

第1章目からつまずく

railsチュートリアル(Ruby on Rails チュートリアル:実例を使って Rails を学ぼう)ではクラウドIDE(Cloud9など)で開発を進めることをオススメしてくる。

けど、僕はローカル環境で開発したい!

そう思ってローカル環境の構築からググりながら進めてきたHomebrew、rbenvのインストールの導入まで終わった。

Bundle installで失敗する

Gemfileでチュートリアル通りgemのバージョンを指定して

bundle installを実行すると以下のエラーがでた。

MacBook-Pro-2:hello_app $ bundle install

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.

Fetching gem metadata from https://rubygems.org/..........

Fetching gem metadata from https://rubygems.org/.

Resolving dependencies...

Bundler could not find compatible versions for gem "ruby":

  In Gemfile:

    ruby

 

    listen (= 3.1.5) was resolved to 3.1.5, which depends on

      ruby (>= 2.2.3)

 

    puma was resolved to 3.11.2, which depends on

      ruby (>= 1.9.3)

 

    rails (= 5.1.4) was resolved to 5.1.4, which depends on

      ruby (>= 2.2.2)

 なんかよく分からないので...

Bundler could not find compatible versions for gem "ruby":

をググってみる!

似たようなエラーは出てくるけど、根本的な解決策が見つからない・・・

 

問題 :Rubyのバージョン

エラー文をよく見ると

ruby (>= 2.2.3)

rubyが2.2.3以上でないといけない的なことが書かれてる

 

もしやrubyのバージョン変更すればいけるんじゃ・・・

まずは

ruby-v

 で今のrubyのバージョンを確認

MacBook-Pro-2:hello_app $ ruby -v

ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin16]

 どうやら今のバージョンは2.2.0みたい

ってことで今インストールされてるrubyのバージョンを確認してみる↓

MacBook-Pro-2:hello_app $ rbenv versions

  system

  2.2.0

* 2.2.2 (set by /Users/.rbenv/version)

2.2.3がインストールされてないので、インストールを試みてみる

rbenv install 2.2.3

今度はrubyインストールでエラーが出る・・・ はぁ。。。

MacBook-Pro-2:hello_app $ rbenv install 2.2.3

Downloading ruby-2.2.3.tar.bz2...

-> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.bz2

Installing ruby-2.2.3...

 

BUILD FAILED (OS X 10.13.3 using ruby-build 20170112)

 

Inspect or clean up the working tree at /var/folders/_r/cb29xhhd2ljbv7m6ggzvgypc0000gn/T/ruby-build.20180228235626.25229

Results logged to /var/folders/_r/cb29xhhd2ljbv7m6ggzvgypc0000gn/T/ruby-build.20180228235626.25229.log

 

Last 10 log lines:

installing rdoc:              /Users/.rbenv/versions/2.2.3/share/ri/2.2.0/system

installing capi-docs:         /Users/.rbenv/versions/2.2.3/share/doc/ruby

The Ruby openssl extension was not compiled.

ERROR: Ruby install aborted due to missing extensions

Configure options used:

  --prefix=/Users/.rbenv/versions/2.2.3

  CC=clang

  CFLAGS= -O3 -Wno-error=shorten-64-to-32

  LDFLAGS=-L/Users/.rbenv/versions/2.2.3/lib

  CPPFLAGS=-I/Users/.rbenv/versions/2.2.3/include

 ググってみたら↓こんなの見つける

qiita.com

どうやらこれを実行すれば良いらしい

CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 2.2.3

よく分からんけど、実行してみる 

でけた!!

あとは

rbenv local 2.2.3

 で2.2.3にrubyのバージョンを切り替える

bundle installも無事実行できやっと次に進める!

 

*2.2.3に切り替えてbundle installを実行できない場合はbundlerのgemがインストールされてない可能性があるので、以下を試してみると良いかもです!

gem install bundler