Installing Javascript Runtime

In this chapter we will install NodeJS using NodeJS Moonshine Plugin. We will also see an alternative to NodeJS.

Why Javascript Runtime?

Rails apps need a javascript runtime to compile Coffeescript to javascript, compress and minify javascript.

Steps

Step 1

plugger install git://github.com/iros/moonshine_nodejs.git

Step 2

Add:

recipe :nodejs

to the application_manifest.rb. This will fail gloriously.

Step 3

Install it on the server manually by:

apt-get install python-software-properties
apt-add-repository ppa:chris-lea/node.js
apt-get update
apt-get install nodejs

Check the NodeJS version:

node -v

should show:

v0.10.20

Alternative to NodeJS

Uninstall the manually installed nodejs on Ubuntu. Since the server is managed by Moonshine, manual installation is a bad idea.

Steps

Step 1

sudo apt-get remove nodejs

Step 2

Add:

gem 'execjs'
gem 'therubyracer'

to the Gemfile. Run bundle install. This will install libv8, ref and therubyracer gems.

Step 3

Deploy using Capistrano.

Summary

In this chapter, you learned how to install a Javascript runtime such as NodeJS or ExecJS on the server.

References

NodeJS installation on Ubuntu 12.04
ExecJS