Removing most – not all! – gems on Windows using Powershell

We’ve started using bundle package to package all our gems prior to deployment. But before I push our code up to take care of this I need to clean down all the globally installed gems on each production machine. But I wanted to keep the bundler gem, the rack gem and any torquebox gems.

There were a few ways to do this on *nix boxes but this great tutorial got me most of the way using Powershell. The only problem was it removed all gems. I wanted to keep some. So I adjusted that script to exclude any gems with the words “bundler” or “torquebox” in them.

So here it is for my own reference and because perhaps someone else will find it useful:

gem list | %{$_.split(' ')[0]} | where {($_ -notmatch "torque") -and ($_ -notmatch "bundler") -and ($_ -notmatch "rack")} | %{ gem uninstall -Iax $_ }

Simply adjust it as required and run it in a Powershell console.

Advertisements
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s