需要帮助建立ruby on rails javascript运行时环境

时间:2020-12-31 23:31:45

I'm having trouble setting up ruby on rails on my machine. I've been following the book "Agile Web Development with Rails" and up until now everything has been going fine.

我在机器上安装ruby on rails时遇到了麻烦。我一直在阅读《Rails的敏捷Web开发》这本书,到目前为止,一切都很顺利。

The problem I'm having is that when I type

我的问题是当我打字的时候。

rails server

I get the following error:

我得到以下错误:

/home/myname/.gem/ruby/1.9.1/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /home/myname/.gem/ruby/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/myname/.gem/ruby/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:4:in `<top (required)>'
from /usr/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
from /usr/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
from /usr/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
from /usr/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
from /usr/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
from /usr/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
from /home/myname/.gem/ruby/1.9.1/gems/bundler-1.1.0/lib/bundler/runtime.rb:68:in `require'
from /home/myname/.gem/ruby/1.9.1/gems/bundler-1.1.0/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /home/myname/.gem/ruby/1.9.1/gems/bundler-1.1.0/lib/bundler/runtime.rb:66:in `each'
from /home/myname/.gem/ruby/1.9.1/gems/bundler-1.1.0/lib/bundler/runtime.rb:66:in `block in require'
from /home/myname/.gem/ruby/1.9.1/gems/bundler-1.1.0/lib/bundler/runtime.rb:55:in `each'
from /home/myname/.gem/ruby/1.9.1/gems/bundler-1.1.0/lib/bundler/runtime.rb:55:in `require'
from /home/myname/.gem/ruby/1.9.1/gems/bundler-1.1.0/lib/bundler.rb:118:in `require'
from /home/myname/Programming/Learning/Learning_Rails/demo/config/application.rb:7:in `<top (required)>'
from /home/myname/.gem/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:53:in `require'
from /home/myname/.gem/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:53:in `block in <top (required)>'
from /home/myname/.gem/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:50:in `tap'
from /home/myname/.gem/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

It's saying that it can't find a javascript runtime environment. I went to the website that the error message recommended and I did some googling and I read that execjs would be a good choice to install. I installed execjs with the following commands:

它说它找不到javascript运行时环境。我去了一个错误信息推荐的网站,我做了一些谷歌搜索,我读到execjs是一个很好的安装选择。我安装了execjs与以下命令:

sudo gem install execjs
sudo gem update

When I run 'gem list' I get the following output:

当我运行“gem list”时,得到如下输出:

*** LOCAL GEMS ***

actionmailer (3.2.2)
actionpack (3.2.2)
activemodel (3.2.2)
activerecord (3.2.2)
activeresource (3.2.2)
activesupport (3.2.2)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.0)
bundler (1.1.0)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.2.0)
erubis (2.7.0)
execjs (1.3.0 ruby)
hike (1.2.1)
i18n (0.6.0)
io-console (0.3)
journey (1.0.3)
jquery-rails (2.0.1)
json (1.6.5, 1.5.4)
mail (2.4.3)
mime-types (1.17.2)
minitest (2.11.3, 2.5.1)
multi_json (1.1.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.2)
railties (3.2.2)
rake (0.9.2.2)
rdoc (3.12, 3.9.4)
sass (3.1.15)
sass-rails (3.2.4)
sprockets (2.3.1, 2.1.2)
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.32)
uglifier (1.2.3)

From the output above it looks to me like execjs is installed. What's going on here and why am I getting this error?

从上面的输出中,我觉得好像安装了execjs。这里发生了什么,为什么会出现这个错误?

If it's helpful at all,

如果有帮助的话,

My OS is Arch Linux.

我的操作系统是Arch Linux。

ruby -v: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]

ruby -v: ruby 1.9.3p125(2012-02-16修订版34643)[x86_64-linux]

rails -v: Rails 3.2.2

rails - v:rails 3.2.2

Any help would be appreciated.

如有任何帮助,我们将不胜感激。

6 个解决方案

#1


11  

Your Gemfile should contain BOTH of the following lines:

你的Gemfile应该包含以下两行:

gem 'execjs'
gem 'therubyracer'

Then run bundle install and try again.

然后运行bundle install并再次尝试。

#2


5  

If you will add therubyracer gem , may be your problem woould be solved

如果你要加入热比赛珍珠,可能是你的问题需要解决。

Code

代码

gem 'therubyracer'
gem 'execjs'

then just do a bundle install

然后进行捆绑安装

#3


3  

Try this:

试试这个:

$ sudo apt-get install nodejs

#4


1  

I think you need a runtime like rubyracer. Try

我认为你需要一个像rubyracer这样的运行时。试一试

sudo gem install therubyracer

#5


1  

If you're using Pacman packet manager you should use:

如果你使用Pacman信息包管理器,你应该使用:

# pacman -S nodejs 

or

$ sudo pacman -S nodejs

#6


0  

I'd installed Node.js before Rails. Now its using Node.js as the javascript runtime by itself.

我安装的节点。在Rails js。现在使用的节点。js作为javascript运行时本身。

JavaScript Runtime  Node.js (V8)

#1


11  

Your Gemfile should contain BOTH of the following lines:

你的Gemfile应该包含以下两行:

gem 'execjs'
gem 'therubyracer'

Then run bundle install and try again.

然后运行bundle install并再次尝试。

#2


5  

If you will add therubyracer gem , may be your problem woould be solved

如果你要加入热比赛珍珠,可能是你的问题需要解决。

Code

代码

gem 'therubyracer'
gem 'execjs'

then just do a bundle install

然后进行捆绑安装

#3


3  

Try this:

试试这个:

$ sudo apt-get install nodejs

#4


1  

I think you need a runtime like rubyracer. Try

我认为你需要一个像rubyracer这样的运行时。试一试

sudo gem install therubyracer

#5


1  

If you're using Pacman packet manager you should use:

如果你使用Pacman信息包管理器,你应该使用:

# pacman -S nodejs 

or

$ sudo pacman -S nodejs

#6


0  

I'd installed Node.js before Rails. Now its using Node.js as the javascript runtime by itself.

我安装的节点。在Rails js。现在使用的节点。js作为javascript运行时本身。

JavaScript Runtime  Node.js (V8)