wiki:Migration

Version 62 (modified by Dmole (Tim), 10 years ago) (diff)

--

Migrating a MacPorts install to a new major OS version or CPU architecture

An installation of MacPorts and the ports installed by it are only designed to work on a single OS release and a single CPU architecture. If you upgrade to a new OS version (e.g. from Leopard to Snow Leopard) or migrate to a new machine with a different type of CPU (e.g. PowerPC to Intel), you may get lucky and have your ports keep working, but in general, things will break. If you are only upgrading Xcode (e.g. 4.1 to 4.2 on Lion) but not the major OS version or CPU architecture, you do not need to reinstall ports as described below.

Reinstall Xcode

After performing either of these types of system upgrades, you will need to update the development tools. If you are upgrading from a prior version of OS X, install the latest version of Xcode for your new OS. This will not be done for you automatically; Xcode is not updated by Software Update, so you must update it manually.

Mac OS X 10.6 Snow Leopard and earlier

You will find the Xcode installer on the Mac OS X installation DVD or on the Apple Developer web site.

OS X 10.7 Lion and OS X 10.8 Mountain Lion

Xcode is available for free on the Mac App Store (after install you also need to install "Command Line Tools": XCode->Preferences->Downloads; if upgrading from previous version of Xcode you may also need to do sudo xcode-select -switch /Applications/Xcode.app, see this SO article).

OS X 10.9 Mavericks

MacPorts require Xcode, which is available for free on the Mac App Store.

sudo xcode-select --install
sudo xcodebuild -license

Reinstall MacPorts

After updating the development tools such as Xcode and the Command Line Tools, install the base MacPorts system again, either from the appropriate disk image if already available or from source.

Update macports.conf

If your macports.conf contains uncommented settings for universal_archs or build_arch, you will likely want to update them, since unlike earlier OS versions, the compiler on Snow Leopard will build for x86_64 by default on systems that support it. The default values will be fine for almost all users, so unless you know you need something different, just comment out these two lines.

Several other settings in macports.conf have changed their defaults over the years. Take a moment to compare each line of your macports.conf with the corresponding line in macports.conf.default in the same directory. Unless you know a reason why a line your settings file should be different from the defaults, adopt the line from the defaults file.

cp /opt/local/etc/macports/macports.conf.default /opt/local/etc/macports/macports.conf

Reinstall ports

To reinstall your ports:

  1. Save the list of installed ports:
    port -qv installed > my_installed_ports.txt
    port list requested | perl -pe 's/ .*//g' | sort -u > my_requested_ports.txt
    
  2. Uninstall all installed ports:
    sudo port -f uninstall installed
    
  3. Clean any partially-completed builds:
    sudo port clean all
    
  4. Install your old ports:
    sudo port install $(cat my_requested_ports.txt | perl -pe 's/\n/ /g')
    

Automatically reinstall ports

A script has been written to automate Step 4 above more accurately, though it has some caveats. If it fails, you will just have to do it manually. (But see workaround for conflicting ports below.)

To use it, you will first need to run steps 1-3 as described above. Then:

  1. Run these commands to download and execute the restore_ports script. (If you installed MacPorts from source and put its Tcl package somewhere other than /Library/Tcl, then you'll need to use the -t 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 my_installed_ports.txt
    

One known issue is that the script will fail if there are conflicting ports in the list. It's possible to have conflicting ports installed provided at most one of the conflicting set is active. If the script fails for this reason, you can delete one of the conflicting ports from myports.txt and then simply run the script again. You may need to do this multiple times if there are multiple conflicting ports listed.

The requested status of the ports will also not be preserved, since it is not available to the script. You can restore it manually by doing something like this (where myport1, myport2 etc. are the ports you actually asked for):

sudo port unsetrequested installed
sudo port setrequested myport1 myport2 …