Setup a Ruby/Chef Environment on Ubuntu
As I wrote before, this chapter is for PHP programmers who are not used to Ruby. Experienced Rubyists can skip it since we just setup a RVM environment and write a gemfile for bundler to download Chef.
If you didn’t understand the above paragraph, don’t worry, I will cover it.
First we need to install Ruby to install Chef. Most distributions used to ship an out of date version of Ruby. Ubuntu has gotten better at it, but will stick with a manager like RVM. RVM can download and setup Ruby on your system. Since the 2014 edition of Deploy Rails Bluebook stayed with the sturdy and widespread 1.9.3 version we will stay with it in this book.
On your host machine install a few necessary dependencies.
sudo apt-get install build-essential curl
Now install RVM for the user.
curl -L get.rvm.io | bash -s stable
RVM will ask you to run a script to load in the variables set in the environment.
source ~/.profile # Do not copy this text as the '~' character doesn't copy well.
|
On Ubuntu with GNOME Terminal you need to configure an additional setting. If you don’t set this you will need to use Goto Edit->Profile Preferences->Title and Command tab->Check ‘Run command as a login shell’. |
Now we ask RVM to check our system for the requirements to build Ruby.
rvm requirements
It should give you a command to install the software that it requests.
Now let’s install Ruby 1.9.3.
rvm install 1.9.3
RVM allows mutiple Ruby instances on one machine. Even more, it allows mutiple Gemsets per each instance. Gemsets are simply bundles of libaries. You can switch between each bundle to use different versions of the same library, which is handy when something breaks.
For now set 1.9.3 as the default.
rvm use 1.9.3 --default
You may get this error.
RVM is not a function, selecting rubies with ‘rvm use …’ will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use
/bin/bash --loginas the command.Please visit https://rvm.io/integration/gnome-terminal for an example.
The simplest thing to try in this case is to relogin and try again.
/bin/bash --login
rvm use 1.9.3 --default
If you get this message you’re good.
Using '/home/user/.rvm/gems/ruby-1.9.3-pXXX'
Now tell RVM to handle gems.
rvm rubygems current
You now have a fully working local Ruby environment on your machine, but you still need to install Chef and go over the Chef DSL which is covered in Part 2 of Deploy Rails Bluebook.
|
DSL stands for Domain Specific Language, a type of syntactic sugar Ruby offers for metaprogramming. |