Dependencies

This section includes all software a basic Ruby on Rails application would require in order to run: databases, datastores, web servers, app servers, libraries, and more.

The list of packages or software projects described in this section was gathered from my experience working in different RoR projects. It might be very useful for several scenarios or might lack other packages for other, but regardless, it works as a good starting point.

Remember # and $ symbols

The # symbol denotes the commands are run as root user, not as a system user. In the other hand, the $ symbol denotes the commands are run as a system user.

Examples

Command run as root

1 # adduser peter-griffin

Command run as system user

1 $ sudo service nginx status

Library Essentials

This installation makes sure the machine has the basic software the rest of the programs you’re going to install need. They provide libraries, commands or modules to those software.

What are they for?

Some of them are standard libraries the software that you install in your machine is going to need to work correctly.

Others are just useful software that should be installed because some guides tells you to use them or because sooner or later you’d be needing them.

How to install them?

Create a file $ nano install_basic_dependencies.sh and add the following content:

 1 #!/bin/bash
 2 
 3 apt-get update
 4 apt-get -y install \
 5   build-essential \
 6   curl \
 7   git-core \
 8   python-software-properties \
 9   htop \
10   vim \
11   libfontconfig1 \
12   libgmp-dev \
13   zlib1g-dev \
14   libssl-dev \
15   libreadline6-dev \
16   libyaml-dev \
17   libncurses5-dev \
18   libxml2-dev \
19   libxslt-dev \
20   libsqlite3-dev

To save the file press CTRL + O and then to exit press CTRL + X.

and run it

1 $ sudo bash install_basic_dependencies.sh

NOTE The list of packages to install is splited with continuation lines for readability.

-y flag is for accepting the prompt without needing the user to type y/N

Docs

See man pages for apt-get command $ man apt-get or online

Database Systems and Datastores

A database is:

A database management system (DBMS) is a computer software application that interacts with the user, other applications, and the database itself to capture and analyze data.

Wikipedia

A datastore is:

A data store is a repository for persistently storing and managing collections of data which include not just repositories like databases, but also simpler store types such as simple files, emails etc.

Wikipedia

PostgreSQL

PostgreSQL is a ORDBMS(Object-Relational Database Management System).

What is this for?

Storing and accessing data through the Structured Query Language(SQL).

How to install it?

Create a file $ nano install_postgresql.sh and add the following content:

1 #!/bin/bash
2 
3 apt-get update
4 apt-get -y install libpq-dev postgresql

To save the file press CTRL + O and then to exit press CTRL + X.

Then run it

1 $ sudo bash install_postgresql.sh
Verify

You can check PostgreSQL is up and running by issuing $ sudo service postgresql status command in your terminal. It should return the version and port the database server is working.

Docs

A full list of PostgreSQL manuals can be found their official site.

MySQL

MySQL is a RDBMS(Relation Database Management System).

What is this for?

Storing and accessing data through the Structured Query Language(SQL).

How to install it?

Create a file $ nano install_mysql.sh and add the following content:

1 #!/bin/bash
2 
3 apt-get update
4 apt-get -y install libmysqlclient-dev mysql-server-5.5
5 apt-get -f install mysql-server

To save the file press CTRL + O and then to exit press CTRL + X.

Run the script

1 $ sudo bash install_mysql.sh
Docs

All MySQL documentation and manuals can be found in their official page.

Redis

Redis is an in-memory data structure store that can be used as a database, cache and/or message broker.

What is this for?

Regarding Ruby on Rails applications, Redis can be used as a database for storing background jobs data. Sidekiq is a popular gem that leverages Redis to work.

You can also use a Redis as a cache or message broker, however, solutions like RabbitMQ are better suited for this job as there have been issues about Redis losing data.

How to Install Redis

There packages available for many operating systems that make it easy to install Redis with just a couple of commands.

Ubuntu 14.04+

Run the following commands:

1 $ apt-get update
2 $ apt-get install -y redis-server
MacOS

If you Homebrew installed just run:

1 $ brew install redi
From Source

Create a file $ nano install_redis.hs and add the following content:

 1 #!/bin/bash
 2 
 3 apt-get update
 4 apt-get -y install tcl8.5
 5 curl -sSL http://download.redis.io/releases/redis-stable.tar.gz -o /tmp/redis.tar.gz
 6 mkdir -p /tmp/redis
 7 tar -xzf /tmp/redis.tar.gz -C /tmp/redis --strip-components=1
 8 make -C /tmp/redis
 9 make -C /tmp/redis install
10 echo -n | /tmp/redis/utils/install_server.sh
11 rm -rf /tmp/redis*
12 sysctl vm.overcommit_memory=1
13 sed -ie 's/# bind 127.0.0.1/bind 127.0.0.1/g' /etc/redis/6379.conf
14 service redis_6379 restart

To save the file press CTRL + O and then to exit press CTRL + X, then run the instructions in the file

1 $ sudo bash install_redis.sh

and wait for redis to be installed on your machine.

NOTE this way of install is called from source and the main difference between this and installing from apt-get is getting up to date packages. Sometimes the apt packages are really outdated.

Verify Installation

Check redis is running with sudo service redis_6379 status. It should output something like Redis is running (PORT NUMBER).

Docs

You can find all redis documentation in its official page.

Read more about Redis feautures.

About installing redis:

Web Servers and App Servers

A web server is:

A web server is a computer system that processes requests via HTTP, the basic network protocol used to distribute information on the World Wide Web.

Wikipedia

An application server is:

An application server is a software framework that provides both facilities to create web applications and a server environment to run them.

Wikipedia

Nginx Web Server

Nginx is a web server that happens to be as well a reverse proxy, load balancer, and HTTP cache.

What is this for?

Using nginx you can have many things that otherwise would require you to install individual pieces of software to have a great architecture for your app:

  • You can use nginx as a web server in a client-server architecture
  • Also works as a reverse proxy, meaning that nginx can work as first layer and send requests, according to predefined rules, to one or more backend services(Jenkins, Apache, etc)
  • Similar to what a reverse proxy would do, you can use nginx to work as a load balancer and distribute request to other web servers throught redirects
  • Nginx can also be used as a cache and you would not need to install things like Varnish, Redis or Memcache
How to install it?

Create a file $ nano install_nginx.sh and add the following content:

1 #!/bin/bash
2 
3 apt-get update
4 apt-get -y install nginx

To save the file press CTRL + O and then to exit press CTRL + X.

Finally, run the script to install it:

1 $ sudo bash install_nginx.sh
Verify Installation

If you need to verify Nginx is up, you can do it with $ sudo service nginx status.

Docs

Nginx documentation can be found here.

Phusion Passenger

Passenger is an application server that allows you to securely operate web apps, microservices & APIs with outstanding reliability, performance and control. By acting as a process manager, reverse proxy and by providing operations tools, Passenger enables you to quickly launch and easily maintain Ruby, Node.js, Python and Meteor apps.

Phussion Passenger

What is this for?

Let’s try to define first what is an application server.

In one side we have web servers which are normally used for serving static content via the HTTP protocol.

In the other side, we got applications servers which can also do the job of a web server and do more things. The main difference(when both use no extra plugins) is that app servers can server dynamic content via the HTTP protocol or others.

In the case of Passenger, its job is to handle business logic in applications coded in the supported languages.

How to install it?

Create a file $ nano install_passenger.sh and add the following content:

 1 #!/bin/bash
 2 
 3 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
 4 apt-get install -y apt-transport-https ca-certificates
 5 
 6 sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main \
 7 > /etc/apt/sources.list.d/passenger.list'
 8 apt-get update
 9 
10 apt-get install -y nginx-extras passenger

save the file by pressing CTRL + O and then press CTRL + X to exit it.

Now, run the script:

1 $ sudo bash install_passenger.sh

Depending on the version of passenger you installed you either need to:

A) uncomment lines passenger_root and passenger_ruby in /etc/nginx/nginx.conf file and then restart nginx with sudo service nginx restart.

B) Edit /etc/nginx/nginx.conf and uncomment include /etc/nginx/passenger.conf; by removing the # character in the beginning of the line and then restart nginx with sudo service nginx restart.

Verify Installation

One of the ways to verify Passenger is working is by taking a look to the processes list and check one called watchdog is available.

Docs

See Phussion Passenger extensive documentation for more help.

Libraries

This section covers installation of some specific dependencies, libraries, software or stuff that some application might need.

  • WKHTMLTOPDF for generating PDF files from HTML pages
  • Image Magick for manipulating image files
  • Jenkins for continuous integration
  • RVM(Ruby Version Manager) for managing Ruby versions
  • NVM(Node Version Manager) for managing Node versions

NodeJS

NodeJS is an open source and cross platform JavaScript runtime environment for developing server tools and/or web applications.

Although Node.js is not a JavaScript framework, many of its basic modules are written in JavaScript, and developers can write new modules in JavaScript.

Wikipedia

What is this for?

Because of it non-blocking and event-driven architecture real time communication applications, browser games and web applications that demand high throughput, scalability and concurrence can be designed and develop using nodejs.

How to install it?

Create a file $ nano install_nodejs.sh and add the following content:

1 #!/bin/bash
2 
3 apt-add-repository ppa:chris-lea/node.js
4 apt-get update
5 apt-get -y install nodejs

To save the file press CTRL + O and then to exit press CTRL + X.

Run its instructions:

1 $ sudo bash install_nodejs.sh
Verify Installation

You can verify Node is installed with either $ node -v or $ node --version. The output should return a number which is the current Node version in your system.

Additionally, you can check the installation path with $ which node or $ command -v node.

Docs

NodeJS documentation can be found in the official site

NVM - Node Version Manager

By using NVM you can manage(install, uninstall, use) different NodeJS versions just a few commands away.

What is this for?

Imagine you work in three projects where NodeJS is being used. Now, in your system you have installed Node version 8.11.1. Good, you can work all of your projects with no problem with that version… Until a dependency/colleague updates something and your current version is no longer supported.

Now, of course you could uninstall it and install a newer one but, What if one of those projects can’t work with an updated version(greater than 8.11, in this example)?

You could either use virtual environments with VirtualBox or Vagrant or you can use NVM to easily install and handle different NodeJS versions in your computer with not much trouble.

How to install it?

Create a file $ nano install_nvm.sh and add the following content:

1 #!/bin/bash
2 
3 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

To save the file press CTRL + O and then to exit press CTRL + X, then run the file:

1 $ bash install_nvm.sh
Verify Install

You can verify NVM is installed with command -v nvm or nvm or nvm --version.

Docs

See NVM GitHub project’s page for more details.

RVM

Easy, manage(install, uninstall, use) different ruby versions just a few commands away.

What is this for?

With RVM you can manage several Ruby versions easily. Without a solution like RVM(rbenv, for example) you might need to uninstall a previous Ruby version to install a differente one. Forget about it with RVM.

Besides, you can handle gemsets to have customized and context specific ruby gems. This context can be different projects or environments.

Most important thing about RVM is that rubies and gemsets are isolated from each other.

How to install it?

Create a file $ nano install_rvm.sh and add the following content:

NOTE: do not run as sudo

1 #!/bin/bash
2 
3 gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39\
4 DC0E3
5 \curl -sSL https://get.rvm.io | bash -s stable

To save the file press CTRL + O and then to exit press CTRL + X nano editor.

Now you can run the instructions:

1 $ bash install_rvm.sh

and wait for RVM to be installed.

Bonus: install ruby

After installing RVM, you can proceed to install ruby:

NOTE: you should change the version of ruby for the desired one

You can run these commands one by one or place them in a file. Before create a file $ nano install_ruby.sh and add the following

 1 #!/bin/bash
 2 
 3 echo "Sourcing RVM and reloading shell"
 4 . /home/$(whoami)/.rvm/scripts/rvm
 5 
 6 echo "RVM requirements"
 7 rvm requirements
 8 
 9 echo "Installing ruby-2.4.1"
10 rvm install ruby-2.4.1
11 
12 echo "Setting ruby-2.4.1 as default"
13 rvm --default use ruby-2.4.1
14 
15 echo "Install bundler"
16 gem install bundler --no-document

run the instructions in the file

1 $ bash install_ruby.sh
Verify Installation

Check RVM is installed with $ rvm -v or $ rvm --version and the install path with $ which rvm.

Docs

Find everything about RVM in its official site

WKHTMLTOPDF

WKHTMLTOPDF is a command line tool for rendering HTML docs into PDF. This utility runs headless, meaning it needs no GUI to be operated or used.

What is this for?

Many web applications display useful information to their users. That info can be in the form of tables or well-crafted UIs, and though most of the data is not so important, there’s important info user might required in a portable format.

A good example of important info is invoices for payments or subscriptions. The customer might want to download them to enter the info in a system they own/use or for backup purposes. Whatever the case, they’d like to export that HTML view into something they can grasp. This is when tools such as WKHTMLTOPDF can prove themselves useful.

Be aware WKHTMLTOPDF makes sense to be used when the info is, mainly, generated from a backend because of its multiple implementations in programming languages such as Ruby.

How to install it?

Create a file $ nano install_wkhtmltopdf.sh and add the following content:

1 #!/bin/bash
2 
3 apt-get install -y openssl build-essential xorg libssl-dev xfonts-75dpi
4 
5 wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2/wkhtmltox-0.12.2_linux-trusty-a\
6 md64.deb
7 dpkg -i wkhtmltox-0.12.2_linux-trusty-amd64.deb

NOTE: this script installs an specific version for this library.

You can find more versions in the downloads page

Save the file press CTRL + O and then to exit press CTRL + X. Run the file:

1 $ sudo bash install_wkhtmltopdf.sh
Verify Installation

Test it is working

1 wkhtmltopdf http://www.google.com google.pdf

You should see a generated PDF file with the Google front page as content.

Docs

See complete WKHTMLTOPDF docs in the project page

Image Magick

Image magick is both a command line tool and a library to work and manipulate images.

What is this for?

When working with images in rails applications, you’re mostly going to work using carrierwave or paperclip gems. Whenever you need to crop or process images, you’re going to need to install image magick so those gems can do the processing.

How to install it?

Create a file $ nano install_image_magick.sh and add the following content:

 1 #!/bin/bash
 2 
 3 apt-get update
 4 apt-get -y install libpng12-dev libglib2.0-dev zlib1g-dev libbz2-dev libtiff4-dev li\
 5 bjpeg8-dev
 6 mkdir -p ~/image_magick_download
 7 cd ~/image_magick_download
 8 wget http://www.imagemagick.org/download/ImageMagick.tar.gz
 9 tar -xzf ImageMagick.tar.gz
10 cd ImageMagick-*
11 sudo ./configure
12 sudo make
13 sudo make install
14 sudo ldconfig /usr/local/lib

To save the file press CTRL + O and then to exit press CTRL + X.

Run the installation script

1 $ sudo bash install_image_magick.sh

NOTE: this is takes a lot of time to be completed. Be patient.

Docs

More documentation about image magick can be found the official site

Jenkins

Jenkins helps to automate the non-human part of the whole software development process, with now common things like continuous integration, but by further empowering teams to implement the technical part of a Continuous Delivery.

Wikipedia

What is this for?

As an automation tool, Jenkins is widely(but not only) for continuous integration. However, with a Jenkins basic install you can also run test suites, generate documents, and even deploy software to servers.

Also, Jenkins is not limited to any specific software or programming language.

Regarding RoR apps(which are the reason of this handbook), using Jenkins you could:

  • run test suite when commits are sent to repository(i.e, GitHub, Bitbucket)
  • email specified developers in case tests break
  • package source code to make it deployable
  • with plugins or its bash integration, define deployment rules or commands
  • run other tasks, email developers about deployment, and more.
How to install it?

Create a file nano install_jenkins.sh and add the following content:

1 #!/bin/bash
2 
3 wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
4 sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.\
5 d/jenkins.list'
6 apt-get update
7 apt-get -y install jenkins

To save the file press CTRL + O and then to exit press CTRL + X nano. Now you can run it:

1 $ sudo bash install_jenkins.sh

See more installation options in Jenkins docs.

Docs

See Jenkins documentation in the official web site.