在 Ubuntu 上创建新的 Rails 项目返回错误

Posted

技术标签:

【中文标题】在 Ubuntu 上创建新的 Rails 项目返回错误【英文标题】:Creating new Rails project on Ubuntu returning error 【发布时间】:2017-03-14 12:58:27 【问题描述】:

我目前是 Linux 操作系统 (Ubuntu) 的新手。我曾经学习在 Windows 上开发 Rails 应用程序,但我发现最好在 Linux 上开发 Rails 应用程序,因为在 Windows 上存在一些限制。我双启动我的电脑,这样我就可以同时拥有 Linux 和 Windows。

所以我使用 RVM 安装了 Ruby 和 Rails(我遵循了这个设置:https://www.youtube.com/watch?v=hiPQynmnsiI)并创建了一个名为 web 的测试项目并将其放在我的桌面上。在创建项目之前没有错误,但是当我运行命令 rails s 时,它返回以下内容:

    /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler    /runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
    Gem Load Error is: Could not find a javascript runtime. See https://github.com/rails/execjs for a list of available runtimes.
    Backtrace for gem load error is:
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/execjs-2.7.0/lib/execjs.rb:5:in `<module:ExecJS>'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/execjs-2.7.0/lib/execjs.rb:4:in `<top (required)>'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/uglifier-3.0.3/lib/uglifier.rb:5:in `require'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/uglifier-3.0.3/lib/uglifier.rb:5:in `<top (required)>'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `require'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `block (2 levels) in require'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `each'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `block in require'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `each'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `require'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler.rb:106:in `require'
    /home/arjay/Desktop/web/config/application.rb:7:in `<top (required)>'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:88:in `require'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:88:in `block in server'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `tap'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `server'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
    /home/arjay/Desktop/web/bin/rails:9:in `require'
    /home/arjay/Desktop/web/bin/rails:9:in `<top (required)>'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `load'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `call'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/command.rb:7:in `call'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client.rb:30:in `run'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/bin/spring:49:in `<top (required)>'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `load'
    /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `<top (required)>'
    /home/arjay/Desktop/web/bin/spring:14:in `require'
    /home/arjay/Desktop/web/bin/spring:14:in `<top (required)>'
    bin/rails:3:in `load'
    bin/rails:3:in `<main>'
    Bundler Error Backtrace:
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:90:in `block (2 levels) in require'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `each'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `block in require'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `each'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `require'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/bundler-1.13.6/lib/bundler.rb:106:in `require'
      from /home/arjay/Desktop/web/config/application.rb:7:in `<top (required)>'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:88:in `require'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:88:in `block in server'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `tap'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `server'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
      from /home/arjay/Desktop/web/bin/rails:9:in `require'
      from /home/arjay/Desktop/web/bin/rails:9:in `<top (required)>'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `load'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `call'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client/command.rb:7:in `call'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/client.rb:30:in `run'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/bin/spring:49:in `<top (required)>'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `load'
      from /home/arjay/.rvm/gems/ruby-2.3.0/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `<top (required)>'
      from /home/arjay/Desktop/web/bin/spring:14:in `require'
      from /home/arjay/Desktop/web/bin/spring:14:in `<top (required)>'
      from bin/rails:3:in `load'
      from bin/rails:3:in `<main>'

感谢任何可以帮助我的人!

【问题讨论】:

也许这会有所帮助? ***.com/questions/34420554/… 成功了!谢啦。目前被 Linux 压得喘不过气来。 【参考方案1】:

找不到 JavaScript 运行时。

您需要 javascript 运行时。

解决方案一:运行以下命令安装nodejs

sudo apt-get install nodejs

解决方案 2: 在您的 Gemfile 中添加 therubyracer gem

gem 'therubyracer'

这将解决问题

【讨论】:

【参考方案2】:

你应该跑

sudo apt-get install nodejs

参考网址 click here

【讨论】:

以上是关于在 Ubuntu 上创建新的 Rails 项目返回错误的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu下创建第一个rails应用程序

Ruby on Rails全栈课程5.2 项目上线--在云服务器上配置Ruby On Rails环境

XAMPP:作曲家返回错误而不是创建新的laravel项目

如何在 Rails 5 上禁用咖啡脚本

突然,rails scaffold delete / destroy方法对于任何rails应用程序都不起作用(旧的,新创建的)

在创建新的 Rails 应用程序时