Installation of Chef and Ruby with RVM on a Ubuntu VPS

Introduction


Ruby based Chef is an open source  framework & tool which allows great automation of your server management, as well as quick installation of preconfigured VPS without the need for you to remember precisely how to configure them.

This is very important as it is now commonplace to have different testing, database, production and development servers with each possessing its own configurations and resources.

Deployment, configuration, updation, and maintenance of a distinct VPS is a repetitive and time consuming task. Chef enables you to easily achieve scalable, consistent and automated output. Simply stated, Chef saves a lot of money and time by offering a structured reuse system. 

Opscode, the Chef developers utilize a simple Ubuntu deployment script, but their way of deployment is unsuitable if one intends to utilize Ruby on Rails. This guide will explain how to enable an actual Ruby environment.

Ruby can be installed with the command given below:

sudo apt-get install ruby


However, it is not suggested as you will encounter problems associated with clashing gems or requirement of a particular version of gem by projects even though you may not be employing different Ruby versions on a VPS.  The Ruby Version Manager (RVM) can easily solve all the stated problems.

Note: Another viable alternative is utilizing rbenv in place of RVM. RVM was selected for this guide as it’s better to be armed with more power than you need rather than having lesser power and discovering that you needed more. 

Step 1: Installation of Ruby With The Ruby Version Manager


There are three dependencies of RVM: Bash, Curl, and Git.

By default, Bash is already installed, so command is utilized for installing just the remaining two:

sudo apt-get install git-core curl


Since we that is out of the way, RVM can now be deployed through the given command:

sudo \curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3


All this takes nearly 5-10 minutes as the Ruby source code and dependencies are first downloaded and is then built. Note: Chef is created against Ruby 1.9 and that’s why we are deploying Ruby 1.9.3. 

On completion, following message would be displayed:

* To start using RVM you need to run `source /usr/local/rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.


Do what is asked and operate the command given below:

source /usr/local/rvm/scripts/rvm


Now, check that Ruby is deployed properly by running the command given below:

ruby -v


For Linux’s 32-bit version, something like below should be displayed:

ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]


For Linux’s 64-bit version, something like below would be displayed:

ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]


Now check that gem is deployed properly by running the command given below:

gem -v


A version number like given below should be seen:

1.8.25


If you are not a developer of Ruby or Rails, then the command below can be used for setting 1.9.3 Ruby as the default for all the new shells:

rvm use 1.9.3 --default


Note: This command will nullify any Ruby version installed previously.

Step 2 – Installation of Chef


Type in the command given below for easily and quickly installing Chef :

gem install chef --no-ri --no-rdoc


Next we check that Chef is deployed properly by using the command given below:

chef-solo -v


A version number like one given below is returned:

Chef: 11.4.4


Furthermore, we will be installing three beneficial add-ons: Knife-Solo, Berkshelf, and Foodcritic.

A plug -in for knife tool of Chef, Knife-Solo, enables provisioning instances using chef-solo. Small installations are made easy by Knife-Solo as it prevents you from operating chef-client which in turn needs a chef server.

It can be installed with the command given below:

gem install knife-solo --no-ri --no-rdoc


Berkshelf aids you in authoring, bundling, and pulling your cookbooks from git, local files and chef server.

For Berkshelf, firstly some dependencies needs to be deployed using the command given below:

sudo apt-get install libxslt-dev libxml2-dev


Now use the command given below for installing Berkshelf:

gem install berkshelf --no-ri --no-rdoc


Next we check that Berkshelf is deployed properly by using the command given below: 

berks -v


A version number like one given below is returned:

Berkshelf (2.0.7)


Foodcritic aids you in finding problems in Chef Cookbooks.

It can be installed by using the command below:

gem install foodcritic --no-ri --no-rdoc


Next we check that Foodcritic is deployed properly by using the command given below:

foodcritic -V


A version number like one given below is returned:

foodcritic 2.2.0


Note: The options –no-ri –no-rdoc are utilized for skipping the generation of documentation.

Next Step


This guide covered installation of Chef on actual Ruby environment appropriate for software development.

Now all is set for starting automation by developing your own recipes or by utilizing 3rd party ones.

KB Admin has written 28 articles

Leave a Reply