rake db:create - 找不到JavaScript运行时

时间:2021-01-05 17:07:20

Here is the error I get:

这是我得到的错误:

sergio@sergio-VirtualBox:~/blog$ rake db:create
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

(See full trace by running task with --trace)

sergio@sergio-VirtualBox:~/blog$ 

So after some searching it seems I need to install a Javascript runtime for Ruby.

所以经过一些搜索后,似乎我需要为Ruby安装一个Javascript运行时。

Is there a difference between the many different options? It seems Node.js is the easiest to install, will this come back to bite me or is this choice OK?

许多不同的选择之间有区别吗?似乎Node.js最容易安装,这会回来咬我还是这个选择好吗?

This answer, seems to be what I'm looking for but I don't know how to make use of it. Where do I find this "gemfile" and is it a per rails project file or a global ruby file? I'm very confused and can't seem to get my bearings and multiple answers contradict each other and don't solve the issue.

这个答案,似乎是我正在寻找的,但我不知道如何利用它。我在哪里可以找到这个“gemfile”,它是每个rails项目文件还是全局ruby文件?我很困惑,似乎无法得到我的方位和多个答案相互矛盾,并没有解决问题。

Add this to your Gemfile

将其添加到您的Gemfile中

gem 'therubyracer', require: "v8"

gem'therubyracer',要求:“v8”

and run

并运行

bundle install

捆绑安装

6 个解决方案

#1


52  

Ruby itself doesn't require a JS runtime, but a default new Rails application does.

Ruby本身不需要JS运行时,但是默认的新Rails应用程序也需要。

There's a file called Gemfile in your main application directory (i.e. per Rails project) which is a list of gems required for your project that you can install using bundle install.

在您的主应用程序目录(即每个Rails项目)中有一个名为Gemfile的文件,它是您可以使用bundle install安装的项目所需的gem列表。

Adding the line gem 'therubyracer' and then bundle install will install the ruby racer JS runtime, which I've found to be the simplest if you're on a 64bit OS.

添加行gem'therubyracer'然后捆绑安装将安装ruby racer JS运行时,如果你使用的是64位操作系统,我发现它是最简单的。

You can find more information about your Gemfile at the Bundler site.

您可以在Bundler站点上找到有关Gemfile的更多信息。

#2


6  

Have you installed Node.js on your computer yet? It needs to be installed on your computer as well.

你在计算机上安装了Node.js了吗?它也需要安装在您的计算机上。

here is the link to download, http://nodejs.org/#download

这是下载的链接,http://nodejs.org/#download

#3


1  

There are several fairly similar options such rubytheracer, node and execjs.

有几个相当类似的选项,如rubytheracer,node和execjs。

rubytheracer has fallen out of favor due to its code size. Vendors such as Heroku (for rails) actively discourage it.

由于代码大小,rubytheracer已经失宠了。 Heroku(铁路)等供应商积极劝阻它。

I currently recommend node.js

我目前推荐node.js

More info at Rails - Could not find a JavaScript runtime?

更多信息在Rails - 找不到JavaScript运行时?

#4


0  

insert gem 'therubyracer' in Gemfile in a new line 1. run

在Gemfile中将gem'therubyracer'插入新行1.运行

gem install therubyracer -v '0.11.4'

宝石安装therubyracer -v'0.11.4'

  1. run

bundle install

捆绑安装

This will work

这会奏效

#5


0  

I had the same error, but then I reinstalled Ruby193 with all the checkboxes (Tc/Tk, associate rb, and add to PATH).

我有同样的错误,但后来我重新安装了带有所有复选框的Ruby193(Tc / Tk,关联rb,并添加到PATH)。

And then deleted the GEMFile.lock

然后删除了GEMFile.lock

Edited the Gemfile whereever I saw gem therubyracer, I changed it to: gem therubyracer, :platform => :ruby

编辑了Gemfile,无论我看到gem gemubyracer,我把它更改为:gem therubyracer,:platform =>:ruby

  • Then bundle install

    然后捆绑安装

  • Then rake db:drop

    然后rake db:drop

  • Then rake db:create

    然后rake db:create

  • Then rake db:migrate

    然后rake db:migrate

and so on

等等

#6


-1  

Just gem install "therubyracer" and it just works.

只需宝石安装“therubyracer”,它就可以了。

#1


52  

Ruby itself doesn't require a JS runtime, but a default new Rails application does.

Ruby本身不需要JS运行时,但是默认的新Rails应用程序也需要。

There's a file called Gemfile in your main application directory (i.e. per Rails project) which is a list of gems required for your project that you can install using bundle install.

在您的主应用程序目录(即每个Rails项目)中有一个名为Gemfile的文件,它是您可以使用bundle install安装的项目所需的gem列表。

Adding the line gem 'therubyracer' and then bundle install will install the ruby racer JS runtime, which I've found to be the simplest if you're on a 64bit OS.

添加行gem'therubyracer'然后捆绑安装将安装ruby racer JS运行时,如果你使用的是64位操作系统,我发现它是最简单的。

You can find more information about your Gemfile at the Bundler site.

您可以在Bundler站点上找到有关Gemfile的更多信息。

#2


6  

Have you installed Node.js on your computer yet? It needs to be installed on your computer as well.

你在计算机上安装了Node.js了吗?它也需要安装在您的计算机上。

here is the link to download, http://nodejs.org/#download

这是下载的链接,http://nodejs.org/#download

#3


1  

There are several fairly similar options such rubytheracer, node and execjs.

有几个相当类似的选项,如rubytheracer,node和execjs。

rubytheracer has fallen out of favor due to its code size. Vendors such as Heroku (for rails) actively discourage it.

由于代码大小,rubytheracer已经失宠了。 Heroku(铁路)等供应商积极劝阻它。

I currently recommend node.js

我目前推荐node.js

More info at Rails - Could not find a JavaScript runtime?

更多信息在Rails - 找不到JavaScript运行时?

#4


0  

insert gem 'therubyracer' in Gemfile in a new line 1. run

在Gemfile中将gem'therubyracer'插入新行1.运行

gem install therubyracer -v '0.11.4'

宝石安装therubyracer -v'0.11.4'

  1. run

bundle install

捆绑安装

This will work

这会奏效

#5


0  

I had the same error, but then I reinstalled Ruby193 with all the checkboxes (Tc/Tk, associate rb, and add to PATH).

我有同样的错误,但后来我重新安装了带有所有复选框的Ruby193(Tc / Tk,关联rb,并添加到PATH)。

And then deleted the GEMFile.lock

然后删除了GEMFile.lock

Edited the Gemfile whereever I saw gem therubyracer, I changed it to: gem therubyracer, :platform => :ruby

编辑了Gemfile,无论我看到gem gemubyracer,我把它更改为:gem therubyracer,:platform =>:ruby

  • Then bundle install

    然后捆绑安装

  • Then rake db:drop

    然后rake db:drop

  • Then rake db:create

    然后rake db:create

  • Then rake db:migrate

    然后rake db:migrate

and so on

等等

#6


-1  

Just gem install "therubyracer" and it just works.

只需宝石安装“therubyracer”,它就可以了。