views:

541

answers:

2

Hi:) I have manually set Ruby 1.9.1. I have installed it via

./configure --prefix=/opt
make
make install

The target 'uninstall' does not exist in generated Makefile ...
How to do uninstallation correctly?

PS: I also believe that it is necessary to remove all the gems.
For this I use

#!/bin/sh
gem list --local | grep [^\*] | cut -d ' ' -f 1 | xargs gem uninstall
A: 

I had a similar problem with another software installed in /opt. I solved the issue by

  1. creating an empty directory elsewhere (like /tmp/ruby)
  2. installing exactly the same version you want to remove in this directory
  3. printing a list of all files in the new location, replacing/tmp/ruby with /opt.
  4. erasing the resulting list

On unix, you can first try:

$ find /tmp/ruby | sed "s/\/tmp\/ruby\//\/opt\//"

Look carefully at the list, if it seems valid, use:

$ find /tmp/ruby | sed "s/\/tmp\/ruby\//\/opt\//" | xargs rm

To really remove the files...

paradigmatic
+1  A: 

You can proceed with some tmp directory as paradigmatic suggests here.

Still, his usage of find ... | xargs rm has the following flaws:

  • the list of arguments to rm will be too long most likely,
  • directories will be included in the list causing rm to fail in the middle, so you'll end up with some files deleted and some not.

I'd use rm as an -exec option within find instead:

find /tmp/ruby -depth -type f -exec rm /opt/{} \;

-type f selects only regular files (you're using rm, not rmdir).

In general I find better to use find -exec instead of find|xargs.

[edit: falling back to xargs]

Upon reading the comments I realized and checked that xargs is actually faster - doesn't fork rm subprocess for each file matching the criteria but feeds rm command with arguments in batches. The too-long-list error I mentioned has been fixed quite a time ago.

Moreover, if you drop -type f condition then rm will print error for directories but delete everything else. This is a good thing as you will have an info about possibly empty directiories for free.

Wojciech Kaczmarek
I don't think you understand how xargs works. It doesn't send all the arguments at once, but in batches (you can define the size, otherwise it chooses some sensible value). On top of that, `find -exec` is **really slow** — the search time increases linearly with the number of results found (because it executes the command for each result and the search waits until the command finishes). See this mailing list post for further explanation: http://www.sunmanagers.org/pipermail/summaries/2005-March/006255.html
Chuck
It may be that I described how xargs worked few years ago. Cool they improved.If so, reducing number of rm invocations is a good thing here. +1 for xargs then.
Wojciech Kaczmarek