In my first rails project (using mysql) I tried to execute the rake db:create command, but it outputted the following error:
Could not find a JavaScript runtime. See
https://github.com/sstephenson/execjs for a list of available
runtimes.
So I included gem 'therubyracer', require: "v8" on my Gemfile and executed a bundle install. The problem is solved, but it left some doubts.
Could somebody give me an explanation about why a javascript runtime is needed for this kind of task? I’m new to Ruby and RoR so this seems quite strange to me, why do RoR use javascript for creating a database?
You need a javascript runtime because now Rails uses an asset pipeline. Rails doesn’t need it to run your migrations but when you run
rake db:migrate, the rake task loads your rails application that needs a javascript runtime to start. Practically, there is no relation between the migrations and the javascript runtime but your app won’t load without it.