Rails

rails server で There was an error while trying to load the gem 'uglifier'.と言われる解決方法。

More than 1 year has passed since last update.

rails new したばかりのプロジェクトを rails new できない問題の解決方法です。


rails serverが失敗する


serverが立ち上がらない

bundle exec rails s -b 0.0.0.0

/home/vagrant/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)


Vagrant 内なので -b オプションをつけています。


therubyracer のコメントを外す


Gemfileを編集

vi Gemfile

gem 'therubyracer', platforms: :ruby


therubyracer を有効にします。


bundle install

いくつか gem が入ります。

Installing libv8 3.16.14.13

Installing ref 2.0.0
Installing therubyracer 0.12.2 with native extensions


再度rails s

bundle exec rails s -b 0.0.0.0 -p 8888

=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://0.0.0.0:8888
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-12-16 23:58:36] INFO WEBrick 1.3.1
[2015-12-16 23:58:36] INFO ruby 2.2.4 (2015-12-16) [x86_64-linux]
[2015-12-16 23:58:36] INFO WEBrick::HTTPServer#start: pid=16358 port=8888

今度はうまくいきました(☝ ՞ਊ ՞)