Using rbenv for multiple projects Feb 15 2018

I prefer to keep all my gems separated by project so I use rbenv-gemset you might want to do that too.

If you want to use a specific ruby version on a project do the following:

1
2
cd project
rbenv install 2.4.1 # you can pick any version `rbenv install -l`

then use that specif ruby-version on the project

1
rbenv local 2.4.1

This will create a .ruby-version file that contains the version you are using, to verify that you can check the version running:

1
ruby -v

you shoudl see 2.4.1 (for this example, or the version you choose)

Then create a gemset for that specific version.

1
2
rbenv gemset create [ruby-version] [name]
rbenv gemset create 2.4.1 myproject

Now you can add that gemset to the current project:

1
echo "myproject" > .rbenv-gemset

You can check where a command is located using

1
rbenv which [command]

for example:

1
rbenv which gem

this should show you that the gem command is from the ruby version you choose and if you do a gem list you'll see the gems installed for that version.

now install bundler

1
gem install bundler

if you do a gem list you'll see bunlder installed there

after any install or uninstall of gems that have scripts you want to call from the terminal you should run rbenv rehash to have all the shims updated on your path.

now check where bundler command is located:

1
rbenv which bundler

you should see it is installed in the gemset that we previously created.

and that's it, you now have your rbenv setup and ready to use on your project without polluting your global gemsets.


** If you want to check what else I'm currently doing, be sure to follow me on twitter @rderik or subscribe to the newsletter. If you want to send me a direct message, you can send it to derik@rderik.com.