尝试加载gem“uglifier”时发生错误。 (捆扎机:: GemRequireError)

为什么我得到这个错误?

shibly@mybox:~/blog$ rails server /home/shibly/.gem/ruby/2.2.4/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) from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require' from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each' from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require' from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each' from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require' from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler.rb:99:in `require' from /home/shibly/blog/config/application.rb:7:in `<top (required)>' from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `require' from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `block in server' from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap' from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server' from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>' from bin/rails:9:in `require' from bin/rails:9:in `<main> 

您应该运行以下命令在Ubuntu中安装NodeJS

 sudo apt-get install nodejs 

或者运行这个OSX

 brew install nodejs 

Uglifier是一个JS包装,它需要一个JS运行时运行或JS解释器。 我会select安装NodeJS。

在默认的Rails Gemfile中,gem'therubyracer'的行被注释掉了。 如果你取消注释,你会得到那个gem,它应该工作。

从“ 开始使用Rails ”:

编译CoffeeScript和JavaScript资产压缩需要您的系统上有可用的JavaScript运行时,如果没有运行时,您将在资产编译期间看到execjs错误。 通常Mac OS X和Windows都会安装一个JavaScript运行库。 Rails将生成的Gemfile中的therubyracer gem添加到新应用程序的注释行中,如果需要,可以取消注释。 therubyrhino是JRuby用户的推荐运行时间,默认添加到JRuby下生成的应用程序的Gemfile中。 您可以调查ExecJS上的所有受支持的运行时。

我认为它需要JS运行时。 尝试安装nodejs 。

创build数据库时出错。

问题是Node.js试图在脚本中没有sudo的情况下安装:

 sudo apt-get install nodejs