Switching Ruby Version in RVM for Metasploit Development

If you have setup a development environment with RVM to do development in Metasploit Framework you are bound to encounter that the Metasploit team has changed preferred Ruby versions.

carlos@ubuntu:/opt$ cd metasploit-framework/
ruby-2.4.2 is not installed.
To install do: 'rvm install ruby-2.4.2'

You get a useful message that mentions the RVM command you need to run to install the new version but there is a bit more to do to fully migrate to the new version. Lets stat installing the new version of Ruby by running the command specified when we switched to the folder rvm install 2.4.2:

$ rvm install 2.4.2

Now that the new version is installed lets migrate gemsets. In my case I set the gemset in RVM to the one recommended by the Metasploit dev team, with the metasploit-framework name. The name tag allows me to migrate one gemset from one version of Ruby to the other using the gemset copy command:

$ rvm gemset copy ruby-2.4.1@metasploit-framework ruby-2.4.2@metasploit-framework

Now that we migrated the gemsets I make the new Ruby and gemset the default for my console.

$ rvm --default use ruby-2.4.2@metasploit-framework

I can quickly test to see I have the correct version of Ruby:

$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
$ rvm list

rvm rubies

   ruby-2.4.1 [ x86_64 ]
=* ruby-2.4.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

I can also check the gemset is the correct one and set as default:

$ rvm gemset list

gemsets for ruby-2.4.2 (found in /home/carlos/.rvm/gems/ruby-2.4.2)
   (default)
   global
=> metasploit-framework

Once that is done I will generate the ri documentation. I find it very useful specially when I'm traveling or in any other environment without internet access where I can not do a simple Google search. 

$ rvm docs generate-ri

Once done I can test that the documentation was generated by looking at the help information for the Array object and for the method each for the object. 

$ ri Array
$ ri Array#each

I hope those of you getting started with coding against Metasploit Framewok find this information useful.