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

久しぶりにRailsなんて触っちゃってみる

sudo gem install rails

こんなエラーが出るかもしれない。

Installing ri documentation for rails-3.1.3...
File not found: lib

Rdocを新しいやついれれば解決。

sudo gem install rdoc

プロジェクト作成&サーバー起動!

rails new hogehoge
cd hogehoge
rails server

こんなエラーが出るかもしれない。

/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
	from /usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.2.9/lib/execjs.rb:5:in `<module:ExecJS>'
	from /usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.2.9/lib/execjs.rb:4:in `<top (required)>'
	from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
	from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
	from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `<top (required)>'
	from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
	from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
	from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
	from /hogehoge/config/application.rb:7:in `<top (required)>'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:52:in `require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:52:in `block in <top (required)>'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:49:in `tap'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:49:in `<top (required)>'
	from script/rails:6:in `require'
	from script/rails:6:in `<main>'

https://github.com/sstephenson/execjs

のリストにあるJSエンジン入れろと言っているので

sudo apt-get install nodejs

再度実行!

rails server

=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-29 22:04:02] INFO  WEBrick 1.3.1
[2011-11-29 22:04:02] INFO  ruby 1.9.3 (2011-10-30) [i686-linux]
[2011-11-29 22:04:02] INFO  WEBrick::HTTPServer#start: pid=23096 port=3000

でとりあえず起動できたよ。