# How do I manually remove a broken port?



## macgruder (Jun 12, 2011)

I believe I screwed up when trying to install ruby on rails with ruby1.9.

Is there a simple way to start from scratch with Ruby and rubygem-rails by deinstalling them manually somehow?

I attempted to deinstall with but got errors:


```
# cd /usr/ports/www/rubygem-rails && make deinstall
===>  Deinstalling for www/rubygem-rails
===>   Deinstalling rubygem-rails-3.0.5
pkg_delete: file '/usr/local/lib/ruby/gems/1.8/cache/rails-3.0.5.gem' doesn't exist
pkg_delete: file '/usr/local/lib/ruby/gems/1.8/specifications/rails-3.0.5.gemspec' doesn't exist
pkg_delete: file '/usr/local/lib/ruby/gems/1.8/gems/rails-3.0.5/bin/rails' doesn't exist
pkg_delete: file '/usr/local/lib/ruby/gems/1.8/gems/rails-3.0.5/bin' doesn't exist
pkg_delete: unable to completely remove directory '/usr/local/lib/ruby/gems/1.8/gems/rails-3.0.5/bin'
pkg_delete: file '/usr/local/lib/ruby/gems/1.8/gems/rails-3.0.5' doesn't exist
pkg_delete: unable to completely remove directory '/usr/local/lib/ruby/gems/1.8/gems/rails-3.0.5'
pkg_delete: couldn't entirely delete package (perhaps the packing list is
incorrectly specified?)
```

And now if I attempt to reinstall I get an error. 

```
===>  Checking if www/rubygem-rails already installed
/usr/bin/env  /usr/local/bin/gem18 install -l --no-update-sources --no-ri --install-dir /usr/local/lib/ruby/gems/1.8 --no-rdoc
 /usr/ports/distfiles/rubygem/rails-3.0.5.gem -- --build-args 
/usr/local/bin/gem18:8:in `require': no such file to load -- rubygems (LoadError)
	from /usr/local/bin/gem18:8
*** Error code 1

Stop in /usr/ports/www/rubygem-rails.
*** Error code 1

Stop in /usr/ports/www/rubygem-rails.
```


----------



## wblock@ (Jun 12, 2011)

It doesn't look as much like a ports error as a ports files that have been removed by another system, like, well rubygems.

Clean out the port first, then rebuild and install (not reinstall).
`# cd /usr/ports/www/rubygem-rails && make clean`

If that doesn't work, manually delete /usr/ports/www/rubygem-rails/work.


----------



## macgruder (Jun 12, 2011)

So you mean I should do this?
`# cd /usr/ports/www/rubygem-rails && make clean`
followed by
`#  make install clean`


----------



## wblock@ (Jun 12, 2011)

Yes.


----------



## macgruder (Jun 12, 2011)

Thanks. I did that and I got the same error so I did
`# rm -r  /usr/ports/www/rubygem-rails/work`
`# cd /usr/ports/www/rubygem-rails && make clean`
`# make install clean`

but I still get the same error:


```
===>  Checking if www/rubygem-rails already installed
/usr/bin/env  /usr/local/bin/gem18 install -l --no-update-sources --no-ri --install-dir /usr/local/lib/ruby/gems/1.8 --no-rdoc
 /usr/ports/distfiles/rubygem/rails-3.0.5.gem -- --build-args 
/usr/local/bin/gem18:8:in `require': no such file to load -- rubygems (LoadError)
	from /usr/local/bin/gem18:8
*** Error code 1

Stop in /usr/ports/www/rubygem-rails.
*** Error code 1

Stop in /usr/ports/www/rubygem-rails.
```

Any ideas? Thanks.


----------



## wblock@ (Jun 12, 2011)

devel/ruby-gems might be partly missing.  Reinstalling it shouldn't hurt.


----------



## macgruder (Jun 12, 2011)

OK. I did this:

`# cd /usr/ports/devel/ruby-gems/`
`# make && make deinstall reinstall clean`

`# cd /usr/ports/www/rubygem-rails && make clean`
`# make install clean`

with the following result (different error)


```
===>  Checking if www/rubygem-rails already installed
/usr/bin/env  /usr/local/bin/gem18 install -l --no-update-sources --no-ri 
--install-dir /usr/local/lib/ruby/gems/1.8 --no-rdoc /usr/ports/distfiles/rubygem/rails-3.0.5.gem -- --build-args 
[color="DarkRed"]ERROR:  While executing gem ... (Gem::DependencyError)
    Unable to resolve dependencies: rails requires activesupport (= 3.0.5), 
actionpack (= 3.0.5), activerecord (= 3.0.5), activeresource (= 3.0.5), 
actionmailer (= 3.0.5), railties (= 3.0.5), bundler (~> 1.0)[/color]
*** Error code 1

Stop in /usr/ports/www/rubygem-rails.
*** Error code 1
```

Removing work had the same effect. Any ideas from here?


----------



## wblock@ (Jun 12, 2011)

Deinstall/reinstall all of those ports:

```
devel/rubygem-activesupport
databases/rubygem-activerecord
www/rubygem-actionpack
mail/rubygem-actionmailer
www/rubygem-activeresource
www/rubygem-railties
sysutils/rubygem-bundler
```

There may be more.  That list can be fed to ports-mgmt/portmaster to automate the rebuild.

What's going on is that those ports were upgraded or deleted outside of ports, probably with rubygems.  I remember reading here somewhere that some of the gem ports were missing or outdated, so using rubygems instead of ports might be the way to go for this.  If possible, sticking with ports makes dealing with them on FreeBSD easier.  Helping update the ports you use is encouraged, also.


----------



## macgruder (Jun 13, 2011)

Hello, sorry for the late reply.

Should I remove all of these (or just the gems)?


```
# sudo portmaster -L | grep ruby
===>>> ruby-1.8.7.302,1
===>>> ruby18-iconv-1.8.7.302,1
===>>> rubygem-abstract-1.0.0_1
===>>> rubygem-actionpack-3.0.5
===>>> rubygem-activemodel-3.0.5
===>>> rubygem-activesupport-3.0.5
===>>> rubygem-arel-2.0.9
===>>> rubygem-builder-2.1.2
===>>> rubygem-erubis-2.6.6
===>>> rubygem-i18n-0.5.0,1
===>>> rubygem-mail-2.2.17
===>>> rubygem-mime-types-1.16
===>>> rubygem-polyglot-0.3.1
===>>> rubygem-rack-1.2.2,2
===>>> rubygem-rack-mount-0.6.14
===>>> rubygem-rack-test-0.5.7
===>>> rubygem-rake-0.8.7
===>>> rubygem-thor-0.14.6
===>>> rubygem-treetop-1.4.9
===>>> rubygem-tzinfo-0.3.25
===>>> ruby18-gems-1.7.2
===>>> rubygem-actionmailer-3.0.5
===>>> rubygem-activerecord-3.0.5
===>>> rubygem-activeresource-3.0.5
===>>> rubygem-bundler-1.0.13
===>>> rubygem-railties-3.0.5
```


I already have ports-mgmt/portmaster. When you say:



> There may be more. That list can be fed to ports-mgmt/portmaster to automate the rebuild.



Are you saying I should use portmaster to do the removal, or the rebuild, or both? If so what would be the exact command? Sorry, this is a basic question, but with things not working I'm worried about breaking things again.


----------



## jb_fvwm2 (Jun 13, 2011)

```
sudo portmaster -L | grep ruby | grep gem | awk '{print $2}' | xargs -J % portmaster -d -B %
```
 ... to only answer part of the post, that (untested) is what I expect would rebuild all of the rubygem ports.  Half of the time portmaster would fail on one or more, in which case you could complete the individual port, then add an exclusion to the pipe: 

```
...grep ruby | grep -v [some port unique name] | grep gem ...
```
(Chance of a typo or something I've forgotten in the above example, also no taking the context of the thread, just one of its questions.)

BTW, the case of portmaster rebuilding all rather than some should be negligible in terms of time wasted, and sometimes uncovers other install/upgrade problems along the way.


----------



## wblock@ (Jun 13, 2011)

macgruder said:
			
		

> Are you saying I should use portmaster to do the removal, or the rebuild, or both? If so what would be the exact command? Sorry, this is a basic question, but with things not working I'm worried about breaking things again.



portmaster will build and reinstall all of the ports given on the command line.  The port names can be in several forms, and globbing is supported.  If you wanted to rebuild everything that had rubygem in the name:

`# portmaster rubygem\*`

If you had a list of ports that needed to be rebuilt in a file:
`# portmaster `cat list-of-ports-to-rebuilt.txt``


----------



## macgruder (Jun 14, 2011)

Thanks for the advice:
What I did was as suggested 

`# portmaster rubygem\*`

but it gave an error about ruby-iconv and so I deinstalled that, and redid the above command, and all seemed to work. There were regular errors like this:


```
tar: lib/ruby/gems/1.8/gems/abstract-1.0.0/setup.rb: Cannot stat: No such file or directory
tar: lib/ruby/gems/1.8/gems/abstract-1.0.0/test/test.rb: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors.
pkg_create: make_dist: tar command failed with code 256

===>>> Package creation failed for rubygem-abstract-1.0.0_1!

===>>> Ignore this error  [i]
===>>> Abort              [a]

===>>> How would you like to proceed? [i]
```

but pressing 'i' each time ended with this:


```
Terminated
===>>> The following actions were performed:
	Installation of converters/ruby-iconv (ruby18-iconv-1.8.7.302,1)
	Re-installation of rubygem-activesupport-3.0.5
	... [snip]...
	Re-installation of rubygem-railties-3.0.5
	Re-installation of rubygem-bundler-1.0.13
```

which seems fine.

I'm thinking I should now delete all the ruby stuff just to make sure. Is there a recommended way to do this?


----------



## wblock@ (Jun 14, 2011)

Deleting all the ruby stuff should not be necessary.  If you still want to, see pkg_delete(1).


----------



## macgruder (Jun 15, 2011)

The reason I want to start from scratch is that I want to have rails working with ruby 1.9, and all this problem stemmed from trying to update to 1.9 after I'd installed the gems. So it would seem the sensible thing to delete all gems and ruby and start from scratch with ruby 1.9.


----------



## wblock@ (Jun 15, 2011)

`# portmaster -r ruby-1.9.2.136,1`
will rebuild ruby1.9 and all the ports that depend on it.  Installing, updating, or deleting gems with rubygems rather than through ports will still cause the same problems.  The package database thinks they are present, but the files have been deleted or changed by rubygems.


----------

