Monday, November 10, 2008
Cleaning up MacPorts
I am running MacPorts on my laptop. Unfortunately, the laptop have a limited amount of space on the hard drive, so I constantly have to keep trimming away things that I do not need.
I noticed that my MacPort folder was growing quite a bit, and I wondered if it would be possible to trim what was in the MacPorts folder without removing any of the applications? After searching a little on the net, I discovered a few interesting things.
It seems as though MacPorts, when upgrading to a new version of an application, leaves the old version behind. After a while, this will eat up quite a bit of your precious hard disk space. So in order to see what you have installed on your machine, type in the following:
There will probably be a lot of ports installed, and only the ones marked "(active)" are used. The rest may be removed. Before doing so it might be fun to see just how much space MacPorts is using. I run the command
du -sh /opt
This will give you an aproximate value for the disk space occupied by MacPorts. On my machine (which already have been cleaned once) it reports 2.5G. The next step is now to remove all the old versions. I would start out by doing a "clean" for all the installed ports. You do this by typing
sudo port clean --all installed
This erases all temporary files in that are being generated during a build of an application. Only things that can be rebuilt are removed in this step. For fun you could run the "du" command again, to see what your savings are. It might not be much at the moment, but on my system I now ended up with 2.7G, a saving of 200MB.
Now for the actual removal of the old versions. This is accomplished by this command:
sudo port -f uninstall inactive
My first attempt was a bit longer, but it also did the trick:
port installed | grep -v "(active)" | while read i; do sudo port -f uninstall $i; done
This will give you an error message as the first line of output is "The following ports are currently installed:", and since there are no port with that name, it will fail, but continue. This is harmless, and I decided that creating a fix for this would make the command line more complicated that necessary. Anyway, after running the first command, the "du" command showed my /opt directory to be 2.6G. I had run this series of commands before, so my savings were not that grate this time around, but the first time I saved almost 1.5G.
I hope this was to some help for some of you.