Could not find a JavaScript runtime.

ubunturailsをインストールして、

$ bundle exec rails serverした時に

/home/ubuntu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/runtime.rb:85: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:

というエラー

やったこと

$ sudo apt-get install nodejs

Gemfilesに追加

gem 'libv8'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
$bundle install

次に

/home/ubuntu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/natto-1.1.1/lib/natto/binding.rb:58:in `rescue in find_library': Please set MECAB_PATH to the full path to libmecab.so (LoadError)

のエラー

$ sudo apt-get install -y mecab mecab-ipadic-utf8 libmecab-dev

で解消した。