Installing Ruby 1.9.2 on Ubuntu using Chef and Vagrant - ruby
I would like to provision a new Ubuntu 10.04 box with Ruby 1.9.2. I'm using Vagrant and Chef Solo to provision the box with everything else I need (e.g. Rails, Rake, MongoDB). The default Ruby version is 1.8.7.
Is there a way to install Ruby 1.9.2 as part of the Vagrant/Chef provisioning process?
I've read on the Chef website about using my own bootstrap template — possibly with knife — such as this one, but because I'm using Vagrant I'm not sure where to put this template — I don't have a chef-repo, a .chef directory or even any Chef stuff installed in /etc/chef.
First, a bit of context. Most Vagrant baseboxes install Ruby for use by Chef and Puppet, but the latest ones do this into /opt/ruby rather than using the system packages. They also add /opt/ruby/bin to the path, but at the end.
This VeeWee template shows how the 10.04 box is currently built: https://github.com/jedi4ever/veewee/blob/master/templates/ubuntu-10.04.3-server-i386/postinstall.sh
As for your question, their are several different contexts you might be trying to address, each with a different solution. Hopefully one of these will be what you're looking for.
Run Chef recipes with 1.9.2
You might be wanting to test running Chef recipes under 1.9.2 and you don't want 1.8.7 anywhere near your box. The best way of approaching this would be to create your own VeeWee template and build yourself a new basebox. You could modify the one linked above to compile 1.9.2 instead of 1.8.7 and follow the instructions on https://github.com/jedi4ever/veewee
Develop with Ruby 1.9.2
Probably more likely is that you want to hack on some Ruby code using 1.9.2. For this you just need to install Ruby and have the binaries on your path before the /opt/ruby entry. There are several ways of doing this:
Compile Ruby from scratch yourself
Use a package. The apt packages in lucid won't give you 1.9.2 so you can roll your own if you like. Or here's one I'm currently using https://github.com/garethr/packages/downloads
Use something like RVM http://beginrescueend.com/
All of these could be managed using a Chef recipe. I'd probably not go for the compile option, leaving either just a straight download and package resource or the following RVM cookbook might be handy http://community.opscode.com/cookbooks/rvm for RVM.
The *gem_binary* option on the package resource might also be useful here depending on how you want to ensure gems get installed for your new 1.9.2 Ruby (rather than the 1.8.7 in opt)
The goal of knife bootstrap is to get Chef installed on the target system so it can run Chef Client. The Vagrant baseboxes tend to already have Chef installed so unless you're doing something specific and want to run multiple versions of Chef I'd avoid this route. The built in Chef provisioners like http://vagrantup.com/docs/provisioners/chef_solo.html are a better bet.
I know the question is quite old and already answered, but I hope this still may be interesting for someone stumbling upon this question.
I've built a Github repo which intends to provide several configurations for building and provisioning a Vagrant box without requiring to write a provisioning recipe from scratch.
For example, using the currently provided configuration, you can build and provision a box with:
Ruby 1.9.2-p290, managed with rbenv and using Bundler for gems
PostgreSQL 8.4
MongoDB
Here is an introduction article on my blog.
Since this almost match the request, I felt it was worth adding this late answer :)
Here's the recipe i'm using to install Ruby 1.9.2
package "libffi5" do
action :install
provider Chef::Provider::Package::Apt
end
package "ruby-1.9.2" do
action :install
source "/tmp/vagrant-chef/cookbooks-0/ruby-1.9.2/files/default/ruby-1.9.2-p290_i386.deb"
provider Chef::Provider::Package::Dpkg
end
Related
How to install Ruby Gems for Vagrant, i.e. for usage in a Vagrantfile and executed on the host, on linux and windows?
I am using Vagrant for provisioning virtual machines. The Vagrantfile executes some custom Ruby code on the host. (This Ruby code is executed directly in the Vagrantfile, but could also be executed as part of a proper Vagrant plugin. It is the same situation.) I would like to use the functionality of 3rdparty Ruby Gems in this very code, but I'm not sure how to properly install the Gems in the Vagrant context. 1) I don't know how Vagrant invokes Ruby. Is it some modified Ruby interpreter for Vagrant? Or is it a standard Ruby installation? 2) How do I, preferably on the command line (linux shell/PowerShell), install Ruby Gems that can be used from the Vagrantfile? Is there a special location for the Gems so that Vagrant can include them? I would write about what I did so far at this point, but I just don't know where to start. This seems to be an uncommon use case, because I haven't found anything that goes into this direction. Maybe the answer is obvious, but I seem to lack proper understanding of what is required for Vagrant/Ruby to 'see' an installed Ruby Gem.
According to the documentation for Vagrant plugins: This installs a plugin with the given name or file path. If the name is not a path to a file, then the plugin is installed from remote repositories, usually RubyGems. # Installing a plugin from a known gem source $ vagrant plugin install my-plugin I don't use Vagrant so I can't confirm that it works, however a quick search shows that someone else wanted to accomplish the same goal and this worked for them: require 'inifile' settings = IniFile.load(CONFIGFILE) Message: LoadError: cannot load such file -- inifile I found that I can get these to work if I do: vagrant plugin install inifile
Specify ruby version to use with Pik
I need to run two Ruby apps on a Windows 2008 server. So, I'm thinking to install Pik for the job (I understand I could use also RVM but the install process doesn't seem very 'stable' to me). Before installing Pik, however, I'd like to know if there is a way to specify which Ruby version should be used for each app. Something like a .ruby-version file. I have looked for the answer on the official Pik repo but I couldn't find anything about it.
In my opinion, Ref 1, Ref 2 are the two simple references you could have to install different ruby versions using Pik in Windows. After setting up the environment correctly, you could just use the command similar to RVM. pik use ruby-2.0.0-p0 Then ruby -v will show ruby 2.0.0p0. So, for different projects, from with in each project folder choose which ruby you want to have. Hope it helps :)
How to setup a Vagrant box for a stasis project?
I'm learning how to use vagrant, and I've a simple project that uses stasis to generate static files. I'm looking for a setup to run stasis on a vagrant box. So the question would be: what's box do I need to make stasis work? (Any hints on what should the Puppetfile include would be nice)
As a posible solution I've used this setup. It's a Ubuntu precise 64 using puppet as provisioner with: rvm ruby 2.0.0 git nodejs stasis gem project specific gems I can compile the project and see it on http://localhost:4000 using stasis -d 4000. There is another related question that came along when finding this solution.
Why doesn't rails.vim recognize any gems that I install?
I'm a ruby and vim newbie. I recently installed the rails.vim plugin and all the commands work fine apart from the commands to create a new Rails project. Every time I do this it says rails is not installed on my system, but it is! It also acts up when I create a class that requires a gem that I've installed. Can anyone help with this?
Did you rvm use system before building / brew install-ing macvim? I didn't and got many errors. Doing rvm use system beforehand fixed things up for me.
RubyGems via MacPorts a good idea?
Upon upgrading from a MB to a new MBP, Apple's migration assistant didn't move my gems. I'm installing rubygems via macports this time, hoping to avoid this upon next upgrade. Are there any pitfalls I should be aware of?
If you want your gems installed in your home directory (which should copy over during a transfer, and, as a side benefit, will let you run gem install as yourself, rather than root), set the gemhome: key to a path in your home directory in your ~/.gemrc.
Where were your gems installed? The migration assistant only moves files in certain areas; I'm not sure if it copies files from places like /usr/local or /opt/local, you may have to do that manually (in which case, you can just copy the entire tree over to your new machine). That said, you shouldn't have a problem installing gems using the version of RubyGems installed by MacPorts.
Installing a package manager via a package manager seems like it should be wrong. Assuming you are not going to use the system ruby, and will only be using ruby installed via MacPorts; it should not be a problem. If you plan on using gems with system ruby, you might have problems when Apple upgrades the system version of ruby, unless you are installing your gems in /Library/Ruby/Gems/ I'm going to assume you can just copy the gems to /Library/Ruby/Gems/1.8/gems from /opt/local/lib/ruby/gems but I wouldn't count on it working 100% with every gem.
The migration assistant doesn't move a lot of unix level stuff. This will be true of the macports installed gems as well (which typically live in /opt/local/lib/ruby/gems). I use macports gem, and this generally works fine with the macports ruby. Be sure you know which ruby executable your shell ends up using, and perhaps use symlinks to control it specifically. I prefer using the macports version so that I'm not beholden to Apple's update schedule. Sadly macports iteself is somewhat inferior to package managers offered on bsd/linux distributions.
I would say don't use MacPorts. People that use their operating systems version of RubyGems often end up with an out of date gem version and then run into problems when they try to update their version of rubygems. Installing Rubygems from source is easy, and it's not hard to install gems when you get a new machine, I mean how often does that really happen????
I just installed ruby 1.8.7 with macport and when I launch scripts with gems, it complains that it doesn't know them. Anyway to add cleanly the gems in the path of my macport ruby? Gam PS: I installed the gems via system gem
What no one mentioned rvm? Use rvm to manage all of your ruby issues - seriously!