Mar 12th, 2009

Re-installing all gems automatically

Today while working on rails application I figured out that some of the gems are not configured/installed properly and it was creating strange problems and there older versions are also installed. So I decided to reinstall all installed gems.

But I wondered there is no way to automatically reinstall all the gems. What I have to do is first uninstall all the gems one by one then reinstall gems manually.

This manual process was too hectic, time consuming and also after this manual steps I forgot to reinstall some required gems, and when I ran my application it was giving me strange errors and as a rails newbie it took too much of my time to figure out things.

So after this painful experience I decided automize this whole process and ended up with one shell script with following commands.

 

gem list --no-versions | sed -e '/^(*|$)/d' > installed_gems

sudo gem uninstall --a --ignore-dependencies .+

cat installed_gems | xargs sudo gem install

rm installed_gems

 

1. gem list --no-versions | sed -e '/^(*|$)/d' > installed_gems

This will list down all the installed gems ignoring version number in file named "installed_gems"

 

2. sudo gem uninstall --a --ignore-dependencies .+

This command will uninstall all installed gems one by one ignoring the dependencies of gem.

 

3. cat installed_gems | xargs sudo gem install

This command will read file created at first step "installed_gem" and will install all latest version of all gems one by one.

 

4. rm installed_gems

After reinstalling all the gems file created in first step is of no use. This is just to cleanup this file. Put above 4 commands in one shell script and have fun....

Tags: