Tutorial

How To Install Chef and Ruby with RVM on a Ubuntu VPS

Published on July 15, 2013
author

Roger Waldron

How To Install Chef and Ruby with RVM on a Ubuntu VPS

Introduction

Chef is an open-source Ruby based tool & framework that enables you to highly automate your server management, and quickly deploy preconfigured VPS without requiring you to remember exactly how you should configure them.

This is increasingly important as it is common to have separate testing, development, database, and production servers. Each with it own unique resources and configurations.

Installing, configuring, updating, and maintaining a single VPS is a time consuming repetitive task. Chef allows you to easily accomplish automated, consistent, scalable roll outs.

Bottom line, Chef saves you time and money by providing you with a structured system of reuse.

Opscode, the developers of Chef do have a easy quick install script for Ubuntu, however their installation method is unsuitable if you wish to use Ruby on Rails. Instead, this tutorial will show you how to setup a real Ruby environment.

You might expect to install Ruby with the command:

sudo apt-get install ruby

However, this is not recommended because even if you're not dealing with multiple versions of Ruby on a VPS, you will have problems with either gems clashing or projects requiring a specific gem version. The Ruby Version Manager (RVM) painlessly solves all these problems.

Note: Using rbenv instead of RVM can also be a viable option. RVM was chosen for this tutorial because all things being equal, it is better to have more power available and not need it, than to discover you need it but cannot have it.

Step 1: How To Install Ruby With The Ruby Version Manager

RVM has three dependencies: Bash, Curl, and Git.

Bash is installed by default, so only the other two have to be installed with the command:

sudo apt-get install git-core curl

With that out of the way we can now install RVM with the command:

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

This will take 5-10 minutes as it downloads dependencies and the Ruby source code and builds it.

Note: Chef is developed against Ruby 1.9 which is why we are installing Ruby 1.9.3.

Upon completion, you should see this message:

* 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 just that, run the command:

source /usr/local/rvm/scripts/rvm

Now, verify Ruby is installed properly with the command:

ruby -v

For the 32-bit version of Linux, you should see something like:

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

For the 64-bit version of Linux, you should see something like:

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

Now verify gem is installed properly with the command:

gem -v

You should see a version number such as:

1.8.25

If you are not a Ruby or Rails developer, then you may wish to set 1.9.3 Ruby as the default for all new shells with the command:

rvm use 1.9.3 --default

Note: This will override the any previously installed version of Ruby.

Step 2 - How to Install Chef

Installing Chef is now a quick and easy process with the command:

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

Now we verify Chef installed fine with the command:

chef-solo -v

This should return a version number like:

Chef: 11.4.4

Additionally, we will install three useful add-ons: Knife-Solo, Berkshelf, and Foodcritic.

Knife-Solo is a plug-in for Chef's knife tool that makes provisioning instances possible with chef-solo. It makes small deployments easy because it saves you from having to run chef-client which in turn requires a chef server.

Install it with the command:

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

Berkshelf helps you author, bundle, and pull your cookbooks from local files, git, and chef server.

Some dependencies must be installed first for Berkshelf with the command:

sudo apt-get install libxslt-dev libxml2-dev

Then, install Berkshelf with the command:

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

Now we verify Berkshelf is installed properly with the command:

berks -v

This should return a version number like:

Berkshelf (2.0.7)

Foodcritic helps you find problems in Chef Cookbooks.

Install it with the command:

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

Then, verify if Foodcritic is installed correctly with the command:

foodcritic -V

This should return a version number like:

foodcritic 2.2.0

Note: in case you are wondering, the options --no-ri --no-rdoc are used to skip the creation of documentation.

Next Step

This tutorial covered how to install Chef on real Ruby environment suitable for software development.

Everything is almost in place to begin automating by creating your own recipes or using 3rd party ones.

Article Submitted by: Roger Waldron

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products


About the authors
Default avatar
Roger Waldron

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
2 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I liked where this article was heading, but it stopped before getting to the good part. Installing RVM and a few gems is the easy part. Now how do you use berkshelf and chef-solo to create some cookbooks and run them on the VPS?

Nice article but the title in inaccurate. This only installs Ruby, not Rails.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel