How can I clean up my MacPorts installation?

58

42

Which command should I run to

  • delete all old port versions
  • delete downloaded files
  • temp files created during build
  • all other stuff which I don't need when I am sure that updated version works fine

I got a suggestion to use

port clean --all all

but it tries to clean ports I don't have, though I tried

port clean --all installed

but it did not delete old inactive versions, then

port -u uninstall

but it got stuck saying that py25-nose (which is active) depends on py25-setuptools (which is inactive).

tig

Posted 2010-07-20T10:33:06.723

Reputation: 3 906

Answers

94

The suggestions you received cover what you're after:

sudo port -f clean --all all
sudo port -f uninstall inactive

If you can't wait for the clean one to run in the background, there are a few commands you can run manually and faster.

Remove leftover build files (this is done automatically by default):

sudo rm -rf /opt/local/var/macports/build/*

Remove download files:

sudo rm -rf /opt/local/var/macports/distfiles/*

Remove archives (these aren't created by default):

sudo rm -rf /opt/local/var/macports/packages/*

Jeremy L

Posted 2010-07-20T10:33:06.723

Reputation: 2 587

3

I have 1.8 GiB of .tbz2 archives in /opt/local/var/macports/software surely they can go... according to http://apple.stackexchange.com/questions/64074/macports-software-clean-up-opt-local-var-macports-software they can be deleted

– Orwellophile – 2014-10-15T13:05:52.863

// , I get the following problem when I attempt this: $ sudo port -f uninstall inactive sudo: cannot get working directory error getting working directory name: no such file or directory while executing "pwd" invoked from within "set current_portdir [pwd]" (file "/opt/local/bin/port" line 5260) – Nathan Basanese – 2015-11-30T17:51:01.283

// , Hold on, problem solved. I just had to close the terminal that gave me that error. Apparently these commands mess with the environment variables, or something. – Nathan Basanese – 2015-11-30T17:52:39.497

What about deleting inactive ports taking into account problem with py25-nose which I described? – tig – 2010-07-20T22:04:43.707

1port -f uninstall inactive – Jeremy L – 2010-07-21T10:42:43.890

Updated to add it since you're after two separate things. – Jeremy L – 2010-07-22T00:33:08.227

Thanks! When I did a macports upgrade it started downloading about 15 GiB of tex stuff I didn't want. I was panicking about how to remove the crap. Thank you! – Wyatt8740 – 2014-01-29T05:09:08.203

8

port uninstall inactive

is the way to go.

Mijndert Stuij

Posted 2010-07-20T10:33:06.723

Reputation: 331

Still complains about py25-nose depending on py25-setuptools – tig – 2010-07-20T21:50:53.663

2"port -f uninstall inactive" will force this behavior to be overridden. – Mijndert Stuij – 2010-07-21T06:55:23.233

2

@tig This is a bug with the old registry format and is fixed when using the sqlite registry introduced with 1.9. The announce for 1.9.0 has instructions how to switch: http://lists.macosforge.org/pipermail/macports-announce/2010-June/000008.html

– raimue – 2010-09-05T23:54:59.583

@Raim: Thank you very much! leaves pseudo name will be of a great help for me! – tig – 2010-09-06T21:20:16.607

2

I just wanted to add my experiences with the above in case it helps anyone else: When I ran

port clean --all all

it ran for several minutes, and this made me concerned, so I interrupted the process.

I too, wanted to "clean up" after multiple installs of Macports on Yosemite. I had installed first via Terminal, and then did

rm -rf MacPorts-2.3.3 which I realized does not clean up, because I saw the command port stopped working.

My solution: I installed again with the pkg installer, which doesn't leave any directories behind.

gurlinthewurld

Posted 2010-07-20T10:33:06.723

Reputation: 21

// , Thanks for the answer! Does the pkg installer work with macports, or should I uninstall macports before using pkg? – Nathan Basanese – 2015-11-30T17:33:10.203

I followed Macports' recommendation: the pkg or dmg installer depending on your Mac OS version. I did not have to manually remove, or uninstall any old versions, directories, etc. when using the installer. For example, I recently updated from Yosemite to El Capitan, and Macports had to be re-installed.

You could later perform maintanance with some common tasks and commands like sudo port selfupdate and sudo port upgrade outdated

Hth!

– gurlinthewurld – 2015-12-01T19:31:40.563