Ruby equivalent of virtualenv?

Viewed 67969

Is there something similar to the Python utility virtualenv?

Basically it allows you to install Python packages into a sandboxed environment, so easy_install django doesn't go in your system-wide site-packages directory, it would go in the virtualenv-created directory.

For example:

$ virtualenv test
New python executable in test/bin/python
Installing setuptools...cd .........done.
$ cd test/
$ source bin/activate
(test)$ easy_install tvnamer
Searching for tvnamer
Best match: tvnamer 0.5.1
Processing tvnamer-0.5.1-py2.5.egg
Adding tvnamer 0.5.1 to easy-install.pth file
Installing tvnamer script to /Users/dbr/test/bin

Using /Library/Python/2.5/site-packages/tvnamer-0.5.1-py2.5.egg
Processing dependencies for tvnamer
Finished processing dependencies for tvnamer
(test)$ which tvnamer 
/Users/dbr/test/bin/tvnamer

Is there something like this for RubyGems?

8 Answers

Here's two cents from an experienced Python developer currently learning Ruby. Using rbenv together with its rbenv-gemset plugin is the closest thing to Python Virtual Environments I have found so far.

rbenv is a tool to manage multiple Ruby versions against the same platform. If you are a Python developer you have probably stumbled upon pyenv. Well, they share the very same purpose and, as a matter of fact, pyenv was actually born as a fork of rbenv.

Without entering in to much technical details, rbenv intercepts Ruby commands using SHIM executables injected into your PATH, and determines which Ruby version has been specified by your application, and passes your commands along to the correct Ruby installation.

A Ruby version can be specified for a project in many different ways. One of the most common is to place a .ruby-version file in the project root directory containing the desired version.

However, whenever a version is used to install gems, those will be shared among all the projects using that version.

Here's where rbenv-gemset plugins comes in handy. In a similar fashion to the .ruby-version file you may initialize a .ruby-gemsets file containing the path of the directory where the gems should be installed for this project (by default a local .gems directory in the project root). Thus isolation between project is achieved.

Here's an oldie but good article about the topic.

Mineshaft is a project that I've been working on for some time and am continuing development work on.

It offers the ability to both create virtual environments akin to how virtualenv works and can also install Ruby globally as well.

Related