# 2potatocakes/muto

Switch Ruby versions and Windows environment variables from the command line
Ruby Visual Basic
Fetching latest commit…
Cannot retrieve the latest commit at this time.

# Overview

Muto is a lightweight little ruby/vbs/bat script that will allow you switch to another version of Ruby while also allowing you to alter multiple other Windows Environment variables at the same time. You can do this with Muto without having to reload your command prompt/shell and all gem paths associated with the chosen version of ruby are automatically updated as you switch versions.

As a precautionary measure when using muto, make a backup of your Windows PATH environment variable before using this gem

## Why I put this together..

Firstly, I’m not trying to take anything from Pik, check it out first if you haven’t already, there’s a thousand things you can do with it and it might be better suited to what your needs are: https://github.com/vertiginous/pik

I put Muto together because I needed to also frequently change a few environment variables every time I changed my version of ruby and I just got sick of having to do it all the time and then having to reload my command prompt as well just to pick up the changes. Also I needed to be able to switch ruby versions and persist the change to another version of Ruby across my entire Windows environment.

## Example Usage

#From the command line

muto
=>Expected format:  muto [ruby_version]
=>
=>Available Versions are:
=>  186     - ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
=>  187     - ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]
=>  rhodes  - ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
=>
=>Currently using:
=>ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

ruby -v
=>ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
echo %JAVA_HOME%
=>C:\Program Files\Java\jre5

muto 187
=>System updated. Now using:
=>ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]

ruby -v
=>ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]
echo %JAVA_HOME%
=>C:\Program Files\Java\jre7


## How Muto works..

Muto works by using an executable .bat file to call a ruby script which will alter your systems environment variables and send an environment changed signal to your Windows environment. It’ll then finish by calling a basic vb script to update the shell you’re working in so that you won’t need to restart your command prompt/shell window.

The actual muto gem is not really a gem at all.. It’s just basically a wrapper to help copy the muto scripts to your machine somewhere.

## Setup/Config

Use a normal Windows MRI version of Ruby to install Muto

gem install muto

From the command line, change into a directory where you want to keep the scripts and run: extract_muto

cd c:\
extract_muto
#=>Extracting to C:\Muto
#=>Generating C:\Muto\muto.rb
#=>Generating C:\Muto\reset_command_line.vbs
#=>Generating C:\Muto\ruby_versions.yml
#=>Writing C:\Muto\muto.bat file..
#=>
#=>Then add C:\Muto to your Windows PATH environment variable and you're good to go


### ruby_versions.yml

As well as being able to switch to other versions of Ruby in your Windows environment, you can also define other User Environment Variables to change at the same time. Muto switches versions of Ruby by just regex-ing out the ruby bin folder out of your Windows PATH variable and replacing it with the new version you choose. This way none of the other paths in your environments PATH variable are altered.

The User Environment Variables are set completely differently! The values you give them are the full values used to define the variable so if there is an existing variable already defined in your User Environment variables then it will be overwritten with the new value.

ADD A ‘HOME’ ENVIRONMENT VARIABLE FOR EACH VERSION OF RUBY!!
Ruby will install and run just fine without a ‘HOME’ environment variable, however you’ll likely run into problems with rubygems while installing gems if you do not setup a ‘HOME’ environment variable for each separate version of ruby you install. I usually just create an empty directory within the ruby folder I’m using and then just add a ‘HOME’ environment variable to my ‘ruby_versions.yml’ file like in the following example.

To add multiple items to your windows PATH environment variable when switching
Inside my windows PATH environment variable I’ve manually added an %ADD_TO_PATH% environment variable so that it looks something like this:
In the following example, when switching to my “rhodes” environment I want to add a heap of stuff to my windows PATH environment variable that I don’t want to be in the PATH when using ruby 186 or 192. In these cases I use a tilde ‘~’ character or a semicolon ‘;’ which will just change the value of the %ADD_TO_PATH% variable to a semicolon and adding nothing to the PATH when I switch between versions.

# ruby_versions.yml example

ruby_versions:
ruby_186:
shortcut: 186
bin_folder: C:\ruby\bin
user_env_variables:
home: C:\ruby\home
java_home: C:\Program Files\Java\jre5
ruby_187:
shortcut: 187
bin_folder: C:\ruby187\bin
user_env_variables:
home: C:\ruby187\home
java_home: C:\Program Files\Java\jre7
rhodes_193:
shortcut: rhodes
bin_folder: C:\RhodesSuite2.2.1.13\ruby\bin
user_env_variables:
home: C:\RhodesSuite2.2.1.13\ruby\home
java_home: C:\Program Files\Java\jre7



Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.