Ruby rails 4.0 建立项目默认缺少 2 个 gem,导致启动失败。

fishinhouse · 2013年07月13日 · 最后由 fishinhouse 回复于 2013年07月13日 · 4377 次阅读

Rails 4.0.0

$rails new webapp 项目建立成功。 cd webapp 修改 Gemfile 的源:source 'http://ruby.taobao.org' $bundle install 启动 $rails s /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/execjs-1.4.0/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/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/execjs-1.4.0/lib/execjs.rb:5:inmodule:ExecJS' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/execjs-1.4.0/lib/execjs.rb:4:in <top (required)>' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/uglifier-2.1.1/lib/uglifier.rb:3:inrequire' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/uglifier-2.1.1/lib/uglifier.rb:3:in <top (required)>' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:inrequire' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in block (2 levels) in require' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:ineach' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in block in require' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:ineach' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in require' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler.rb:132:inrequire' from /home/wangliang/ruby-china/config/application.rb:7:in <top (required)>' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:76:inrequire' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:76:in block in <top (required)>' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:73:intap' from /home/wangliang/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:73:in <top (required)>' from bin/rails:4:inrequire'

from bin/rails:4:in `'

解决办法: vim Gemfile 添加 gem 'execjs' gem 'therubyracer' $bundle install $rails s => Booting WEBrick => Rails 4.0.0 application starting in development on http://0.0.0.0:3000 => Run rails server -h for more startup options => Ctrl-C to shutdown server [2013-07-13 00:11:52] INFO WEBrick 1.3.1 [2013-07-13 00:11:52] INFO ruby 2.0.0 (2013-06-27) [x86_64-linux] [2013-07-13 00:11:52] INFO WEBrick::HTTPServer#start: pid=28681 port=3000

你这里缺少的是 javascript 的运行环境,这里说的还是比较清楚的,直接装上 Node.js 或是使用的therubyracergem 等都可以解决。

谢谢,支持。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号