Mac – How to find what packages I’ve installed via terminal

command linemacportspackage-management

I've been learning the shell for a few weeks and have installed several packages. I know/remember what some of them are, like oh-my-zsh and emacs 24 (which was a nightmare to upgrade to), but not sure sure about what else. I've used different methods like curl, wget and Macports.

My question is, if and when I want to do a clean installation of MacOS, how do I backup or script a fresh installation of these packages? In other words, when I do a new install of MacOS I won't be restoring from Time Machine using Migration Assistant: rather I'll install the system and manually restore files. How do I know the installation paths and dependancies of what I've installed in my previous installation using the command line? Is there a txt file somewhere that the system maintains to keep track of what has been installed?

(MacOS 10.8.2)

Best Answer

Since OS X has no package manager, anything you install would have been manual, through MacPorts or through Installer.

If you want a list of the binaries your terminal has access to, you can run the following commands to check the most common spots, and output the result as a text file:

touch ~/Binaries.txt
ls /usr/bin > ~/Binaries.txt
ls /usr/sbin >> ~/Binaries.txt
ls /usr/local/bin >> ~/Binaries.txt
ls /usr/local/sbin >> ~/Binaries.txt
ls /opt/local/bin >> ~/Binaries.txt
ls /opt/local/sbin >> ~/Binaries.txt

Alternatively, if you just want to get the packages installed by MacPorts, run the following (this is probably the one you want):

touch ~/MacPorts.txt
port installed > ~/MacPorts.txt

And for Homebrew:

touch ~/HomeBrew.txt
brew list > ~/HomeBrew.txt

And finally, for all packages installed by Installer

touch ~/InstalledPackages.txt
pkgutil --packages > ~/InstalledPackages.txt

To restore, for example, your MacPorts ports from the list generated above, use the following:

 port install $(cat ~/MacPorts.txt)