Rails服务器无法启动->找不到JavaScript运行时 [英] Rails server does not start -> Could not find a JavaScript runtime
问题描述
我在问题"文件夹中创建了一个新的Rails应用程序,当我想对红宝石"进行操作时,出现了错误.任何帮助将不胜感激
I created a new rails app in folder 'issues' and when I wanted to 'ruby s' I got an error. Any help will be much appreciated
[thiago@netbox issues]$ rails s
/home/thiago/.rvm/gems/ruby-1.9.3-p429/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/thiago/.rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /home/thiago/Documents/wdi/rails_practice/issues/config/application.rb:7:in `<top (required)>'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我将'therubyracer'宝石添加到我的Gemfile中,然后'$ bundle install'起作用了!
I added 'therubyracer' gem into my Gemfile and then '$ bundle install' Works!
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'therubyracer' # added
推荐答案
一月份我开始在Rails上工作时,在Windows和Ubuntu上都遇到了相同的错误.该错误非常简单.您需要一个JavaScript运行时环境才能启动服务器.
I had the same error both for Windows and Ubuntu when I started working on Rails in January. The error is pretty straightforward. You need a JavaScript runtime environment for the server to start.
有很多解决方案.我在Ubuntu上使用的是安装NodeJS.
There are a number of solutions to this. The one I use on Ubuntu is to install NodeJS.
在Ubuntu上,您将运行以下内容来安装NodeJS:
On Ubuntu you'd run something like the following to install NodeJS:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get -y update
sudo apt-get -y install nodejs
这些是我用来执行的命令,因为它将安装最新版本的NodeJS稳定版本,但是您可以运行 sudo apt-get -y install nodejs
即可.
Those are the commands I use to do it as it will install the latest stable version of NodeJS, but you can just run sudo apt-get -y install nodejs
and be fine.
在Windows上,我使用的答案(可能还有其他答案)是编辑Gemfile以安装therubyracer.我现在在Rails 4.0 RC1应用程序上工作,它们都在刚刚注释掉的Gemfile中已经有 gem'therubyracer',平台::ruby
.
On Windows, the answer I used, and there may be others, was to edit your Gemfile to install therubyracer. I work on Rails 4.0 RC1 apps right now and they all have gem 'therubyracer', platform: :ruby
already in the Gemfile just commented out.
如果您在Windows上运行,只需在Gemfile中添加 gem'therubyracer'
,我敢打赌.然后运行捆绑安装
.
You can just go add gem 'therubyracer'
in your Gemfile if you're running on Windows and that will get you running I'd bet. Then run bundle install
.
这篇关于Rails服务器无法启动->找不到JavaScript运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!