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

Ruby on Rails チュートリアルの1章のメモ

これの1章をやる。

http://railstutorial.jp/book/ruby-on-rails-tutorial

 

もう一回やったんだが完全につまったので環境構築からやりなおす。

http://unkoburiburisuperfxxk.hatenablog.com/entry/2014/12/07/152728

 

OSはFedoraにした(最初に詰まったときはCentOS)。

なんかまたやりなおすはめになりそうなのでいちいちつまったところをメモっていく

 

$ rvm get stable

ではげしいエラー。

====================================================

Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found.
Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for '/home/dev/.rvm/archives/rvm-installer' - 'https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer.asc'!
try downloading the signatures:

gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3

or if it fails:

command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

the key can be compared with:

https://rvm.io/mpapis.asc
https://keybase.io/mpapis

====================================================

よくわかんねえからとりあえずググった。

$ gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3

$ rvm get stable

解決した。

(参考:http://qiita.com/uedatakeshi/items/8138d00a762225f01aa3

 

 

$ rvm requirements

またエラー。

====================================================

Error running 'requirements_centos_libs_install patch libyaml-devel libffi-devel autoconf gcc-c++ patch readline-devel zlib-devel openssl-devel automake libtool bison',
showing last 15 lines of /home/dev/.rvm/log/1417949409/package_install_patch_libyaml-devel_libffi-devel_autoconf_gcc-c++_patch_readline-devel_zlib-devel_openssl-devel_automake_libtool_bison.log

====================================================

 なんかsudo使えないって怒られてるオーラを感じたのでsudoを使えるようにしたら解決した。(参考:sudo による管理者権限の付与

 

$ rails new first_app

で、エラー。

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

/home/dev/.rvm/rubies/ruby-2.0.0-p598/bin/ruby -r ./siteconf20141207-55705-u76bj5.rb extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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=/home/dev/.rvm/rubies/ruby-2.0.0-p598/bin/ruby
--with-sqlite3-dir
--without-sqlite3-dir
--with-sqlite3-include
--without-sqlite3-include=${sqlite3-dir}/include
--with-sqlite3-lib
--without-sqlite3-lib=${sqlite3-dir}/

extconf failed, exit code 1

Gem files will remain installed in /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/sqlite3-1.3.10 for inspection.
Results logged to /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/extensions/x86_64-linux/2.0.0/sqlite3-1.3.10/gem_make.out
An error occurred while installing sqlite3 (1.3.10), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.10'` succeeds before bundling.

 

sqliteがないよー><みたいな感じ・・・?

チュートリアルにのってる以下を実行してみる

$ sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev # Linuxのみ

 sudo: apt-get: command not found

アプトゲットない><

 

sudo yum install libxslt-dev libxml2-dev libsqlite3-dev

Loaded plugins: langpacks, refresh-packagekit
No package libxslt-dev available.
No package libxml2-dev available.
No package libsqlite3-dev available.
Error: Nothing to do

yumで実行したらこんなんなんった。

 

なんか駄目くせえので調べたら出てきたコマンドをとりあえず入力。

sudo yum install sqlite-devel
参考:http://stackoverflow.com/questions/5789432/how-to-install-sqlite3-gem-on-ec2

 もっかい

rails new first_app

 Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

できたー!

 

rails server

/home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/execjs-2.2.2/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/execjs-2.2.2/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/execjs-2.2.2/lib/execjs.rb:4:in `<top (required)>'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/uglifier-2.1.1/lib/uglifier.rb:3:in `require'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/uglifier-2.1.1/lib/uglifier.rb:3:in `<top (required)>'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@global/gems/bundler-1.7.8/lib/bundler/runtime.rb:76:in `require'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@global/gems/bundler-1.7.8/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@global/gems/bundler-1.7.8/lib/bundler/runtime.rb:72:in `each'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@global/gems/bundler-1.7.8/lib/bundler/runtime.rb:72:in `block in require'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@global/gems/bundler-1.7.8/lib/bundler/runtime.rb:61:in `each'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@global/gems/bundler-1.7.8/lib/bundler/runtime.rb:61:in `require'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@global/gems/bundler-1.7.8/lib/bundler.rb:134:in `require'
from /home/dev/rails_projects/first_app/config/application.rb:7:in `<top (required)>'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/railties-4.0.5/lib/rails/commands.rb:74:in `require'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/railties-4.0.5/lib/rails/commands.rb:74:in `block in <top (required)>'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/railties-4.0.5/lib/rails/commands.rb:71:in `tap'
from /home/dev/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/railties-4.0.5/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

Javascriptがらみのなんかがないよー!的なニュアンス?

Gemfileのケツに以下を追加。

gem 'therubyracer'

参考:Ruby:Rails4 で Could not find a JavaScript runtime エラー | サイト運営の私的メモ

$ bundle install

$ bundle update

$ rails server

=> Booting WEBrick
=> Rails 4.0.5 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-12-07 04:07:18] INFO WEBrick 1.3.1
[2014-12-07 04:07:18] INFO ruby 2.0.0 (2014-11-13) [x86_64-linux]
[2014-12-07 04:07:18] INFO WEBrick::HTTPServer#start: pid=56354 port=3000

できた!

 

このウェブページにアクセスできません

なんで!

ポートが開いてないからかなと思って開いたらアクセスできた。

# sudo firewall-cmd --zone=public --add-port=3000/tcp

参考:Firewalld: Persistently Open a Port | The Blog

Foderaはiptablesじゃないのね。

 

$ bundle exec guard init rspec
05:28:16 - INFO - Writing new Guardfile to /home/dev/rails_projects/sample_app/Guardfile
05:28:16 - ERROR - Could not load 'guard/rspec' or '~/.guard/templates/rspec' or find class Guard::Rspec

おんなじじゃねえか!!!!!!!!!

全然わかんねえ!!!!!!!!!!!!!!!!

うううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううううう

 

もはや自分が何をしているのかわからないままsudoで実行してみる。

sudo bundle exec guard init rspec
[sudo] password for dev:
sudo: bundle: command not found

これが駄目な理由がわからないのはlinuxの知識がないからなのかbundlerの知識がないからなのかすらわからん。

 

試してみる価値があるのかどうかすらわからないままrbenvをためしてみる。

 

mac買って最初から構築しなおしても同じエラー出て笑う。

Could not load 'guard/rspec' or '~/.guard/templates/rspec' or find class Guard::Rspec

なんか違うとこで間違ってるパターンだわ・・・。

 

〜追記〜

解決したのかどうか若干あやしいけどとりあえず解決したのでメモ。

参考:http://ruby-rails.hatenadiary.com/entry/20141021/1413819783

 

 

解決した時のGemfile

source 'https://rubygems.org'

ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.5'

group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.14.2'
# gem 'guard-rspec', '2.6.0'
gem 'guard-rspec', require: false # guardでrspecを動かす
end

group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'

# Uncomment this line on OS X.
# gem 'growl', '1.0.3'

# Uncomment these lines on Linux.
# gem 'libnotify', '0.8.0'

# Uncomment these lines on Windows.
# gem 'rb-notifu', '0.0.4'
# gem 'win32console', '1.3.2'
end

gem 'sass-rails', '4.0.5'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
gem 'sdoc', '0.3.20', require: false
end

group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end

 

guard-rspecのバージョンの問題なのかどうかわからんけどこの状態で

guard-rspec

$ guard init rspec

これでGuardfileができた。

23:27:08 - INFO - rspec guard added to Guardfile, feel free to edit it

 

ボーナスでmac mini買ったからそれで環境構築したらなんか解決しました!っていう糞みたいな結論出そうと思ってたんだけど環境変えても同じ状況に陥るとは思わなかったわ・・・。

なんかチュートリアルの内容飛ばしてたりするのかな・・・?

同じ手順でやって毎回発生するとは思えないくらい同じことしてるやつがいねー・・・。