试图加载 gem‘ ugfier’时出现错误。(Bundler: : GemRequreError)

为什么我会得到这个错误?

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>
78048 次浏览

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

sudo apt-get install nodejs

or run this for OSX

brew install nodejs

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

In the default Rails Gemfile, the line for the gem 'therubyracer' is commented out. If you uncomment it, you'll get that gem and it should work.

来自 开始使用 Rails:

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

创建数据库时出错。

The problem is that the Node.js tried to install without sudo in the script:

sudo apt-get install nodejs