Where am I? Displaying current RVM Ruby version and Gemset | BlueDiapente - Lilibeth De La Cruz


Where am I? Displaying current RVM Ruby version and Gemset

I've started trying to make more use of RVM's capabilities recently. While it has been pretty easy to learn there is a major issue I encountered. While having separate versions of Ruby and Gemsets for each project is very useful, it can become quite annoying and lead to mistakes if you are not constantly aware of what is your active Gemset. It happened to me a couple of times that I ended up installing gems in the default Gemset or just in the wrong one since I forgot to specify beforehand which is the one I wanted to work with.

The problem here is obviously me and my memory issues. But you can't really expect everybody to always remember what is the current Gemset?  Is it reasonable to expect that I could execute something as simple as "rvm gemset name" each time? Maybe for you, but for me it is not.

The solution to my problem was rvm-prompt. With this tool I can print what current Ruby version I am working with, what is my Gemset among other stuff. You can find all about it on their site.

I'm using Ubuntu (you would need to check on how to do it on your OS if you are using Windows or Mac), so to do this I need to overwrite the PS1 variable. You can get your current PS1 value with:

echo $PS1

And overwrite it withyou

None of this is permanent, so no need to worry. If you restart your terminal everything will be right like it was before. There is plenty of information on all the things you can do with this and variables here if you are interested and want to customize this more, but for the moment lets focus on our task.

To get started and make it permanent this time go to your bash configuration file usually at ~/.bashrc and add the following at the end:


That's it! Restart your terminal window and if your Ruby version is Ruby 1.9.2-p290 and your Gemset is named "testgemset" you should see something like this:

ruby-1.9.2-p290@testgemset rambler@mypc:~/currentworkingdir$

Now if you want something more specific, more information, less information or some specific colors then read on these links and you'll should be able to set it up:

RVM: Ruby Version Manager - rvm-prompt

How to: Change / Setup bash custom prompt (PS1)