Updating Installed Gems

Author: Samuel Williams When: Thursday, 29 April 2010

I recently had to upgrade DataMapper which has lots of separate gems for different bits of functionality. Rather than typing them all in manually, I wrote a one-liner to do it. Firstly, we have a list of gems on the computer, and then we grep for "dm":

-- Print out a list of local gems
Nekomimi:~ samuel$ gem list

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (2.3.5, 2.2.2, 2.1.0, 1.3.6)
actionpack (2.3.5, 2.2.2, 2.1.0, 1.13.6)
actionwebservice (1.2.6)
-- And hundreds more....

Nekomimi:~ samuel$ gem list | grep dm
dm-adjust (0.10.2, 0.10.1)
dm-aggregates (0.10.2, 0.10.1)
dm-ar-finders (0.10.2, 0.10.1)
dm-cli (0.10.2, 0.10.1)
dm-constraints (0.10.2, 0.10.1)
-- And lots more...

So we have a list of gems.. but we need to remove the version number brackets (0.10.2, 0.10.1). To do this there are a number of options, but we will use sed:

-- Remove the trailing brackets using sed (Stream EDitor)
Nekomimi:~ samuel$ gem list | grep dm | sed -E "s/\(.*\)//"
dm-adjust 
dm-aggregates 
dm-ar-finders 
dm-cli 
dm-constraints 
dm-core 
-- And lots more...

# This prints the command we are want to run:
Nekomimi:~ samuel$ gem list | grep dm | sed -E "s/\(.*\)//" | xargs echo sudo gem install
sudo gem install dm-adjust dm-aggregates dm-ar-finders dm-cli dm-constraints dm-core dm-is-list dm-is-nested_set dm-is-remixable dm-is-searchable dm-is-state_machine dm-is-tree dm-is-versioned dm-is-viewable dm-migrations dm-more dm-observer dm-querizer dm-rest-adapter dm-serializer dm-shorthand dm-sweatshop dm-tags dm-timestamps dm-types dm-validations dm-yaml-adapter

-- Here is the command actually running:
Nekomimi:~ samuel$ gem list | grep dm | sed -E "s/\(.*\)//" | xargs sudo gem install
Successfully installed dm-adjust-0.10.2
Successfully installed dm-aggregates-0.10.2
Successfully installed dm-ar-finders-0.10.2
-- And lots more...

Comments

Leave a comment

Please note, comments must be formatted using Markdown. Links can be enclosed in angle brackets, e.g. <www.codeotaku.com>.