Typical RVM Project Workflow
Thanks to rvmrc support in rvm, you can make a project-specific workflow. The following examples tie into how we typically work with rvm along with the advantages of such approahces.
An example
The most basic workflow is typically project-specific rvmrc's. For each project you work on, you create a new gemset (on the ruby interpreter of choice) and let your rvmrc take care of switching. As an example:
$ rvm use ree@tedxperth
Would use the tedxperth gemset on ruby enterprise edition. To make this easier, we can run:
$ echo 'rvm --create --rvmrc use ree@tedxperth' > .rvmrc
from inside the root of your project. This tells rvm that everytime we change in to the project's directory, it should use ree with the tedxperth gemset, creating the gemset if it doesn't exist. After executing the above command, you can reload RVM in order to make it see the new .rvmrc and allow you check it out and 'trust' it.
$ rvm reload
This basic approach not only ensures we have gems seperate from the rest of the system but also means that out of the box, running 'bundle install' will use the project defined gemset to also store the gems.
We specify a relatively loose requirement on the ruby but still require the developers have a consistent choice in what they use. In this approach, it is important to note we also recommend adding the rvmrc to the git repository and, if possible, deploy via rvm ensuring a consistent choice across all stage.
A more complex example
To look at the other extreme, it is possible to use a combined set of features to automate many levels of setup and to make live easier when working with projects in general.
This approach, as seen in the source for this site and the open-source TEDxPerth web app not only has an rvmrc that specifies gemset and ruby interpreter, but also goes a few steps further to automatically:
- Install the minimum required gems (e.g. for TEDxPerth where bundler is used, install bundler. In the rvm-site, import a gemset with all of the gems required).
- In the TEDxPerth example, automatically install the ruby if not already installed and use the --create option to ensure the gemset is automatically created.
- We avoid calling bundle install directly in the .rvmrc (to avoid the speed cost when changing in to the directory) but if you wish, you can also make it automatically bundle all of the gems as needed.
Overall, this approach not only ensures you have a consistent environment everywhere you develop and deploy the project, but it also helps with tasks such as continious integration. For further reference, see:
- Our guide for CI with Hudson
- Our guide for Passenger, Including details on automatic gemset detection
- Our page on using per-project rvmrc's