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)


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)
  • No problem! Please mark it as accepted if it solves your problem :) – Yasyf Nov 11 '12 at 22:31
  • 7
    Isn't it better to run port list requested rather than port installed, so that MacPorts installs only the dependencies that are in use and in the right order? – Deditos Nov 26 '12 at 12:44

List ports that you've installed:

port echo requested > ports.txt

To later install the latest versions of those ports on a new system

sudo port install $(cut -f1 -d\  ports.txt | uniq)

See also

port help echo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .