8

How can one do a complete clean reinstall of a port and at the same time a complete clean reinstall of all its dependenceis?

Jack Twain
  • 6,273
  • 15
  • 67
  • 107
  • Well this is odd. Just [posted](http://stackoverflow.com/questions/22238497/cleaning-out-all-other-installed-pythons-on-os-x) minutes ago. – Drewness Mar 06 '14 at 23:46

2 Answers2

18

From the MacPorts wiki (migration):

https://trac.macports.org/wiki/Migration

After having saved a list of installed ports using:

port -qv installed > myports.txt

and having removed them with:

sudo port -f uninstall installed

Download and execute the restore_ports script. (If you installed MacPorts from source and used a custom prefix, then you'll need to use the -p option when you run restore_ports.tcl; see ./restore_ports.tcl -h.)

curl -O https://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl
chmod +x restore_ports.tcl
sudo ./restore_ports.tcl myports.txt
G. Cito
  • 6,210
  • 3
  • 29
  • 42
Marc
  • 181
  • 1
  • 2
  • 1
    @KirkRoybal: That link is the definitive answer to this question, straight from the MacPorts people. This should be the accepted answer. – jvriesem Aug 24 '15 at 16:57
5

Save your currently installed ports

sudo port list installed | sed 's/ .*//' | sort | uniq > ports.lst

Then uninstall everything, leaving the structure in place

sudo port clean installed
sudo port -f uninstall installed

Then reinstall everything, with the new dependencies:

for package in $(<ports.lst); do sudo port install $package; done
Jens
  • 8,423
  • 9
  • 58
  • 78
Kirk Roybal
  • 17,273
  • 1
  • 29
  • 38
  • 2
    This gives me *all* installed ports. Is there a way to list only the leaves of the dependency graph? For example, I wouldn't need to know of ports that will be installed as a dependency of another port. – Jens Dec 12 '14 at 07:17
  • 1
    Also wanted to point out that this approach doesn't keep the installed variants. Using `port -v installed` or somesuch instead of the `port list installed` would be better IMO. – Jens Jan 10 '15 at 16:11
  • What makes this answer better than the one by Marc? – jvriesem Aug 24 '15 at 16:39
  • @jvriesem well he's offering to download some script.. why doing this if you could show commands in here.. – holms Dec 03 '15 at 01:35
  • @holms: This is true, though the script is the script that the MacPorts developers recommend using. Presumably their script has more than just the commands in this answer for some reason. (One would hope! :-) ) Once nice thing about this answer is that it's transparent. – jvriesem Dec 03 '15 at 17:56
  • Any reason for `sudo` in front of `sudo port list`? – Dmitri Zaitsev Jul 06 '19 at 15:51