wiki:Migration

Version 80 (modified by dave@…, 9 years ago) (diff)

Use a single sudo, so only one password is required.

Migrating a MacPorts installation

A MacPorts installation is designed to work with a particular operating system and a particular hardware architecture. Problems may occur after major system changes, such as:

  • major operating system upgrades (e.g., from 10.9 Mavericks to 10.10 Yosemite).
  • architecture migrations (e.g., from PowerPC to Intel).

Please follow this procedure to ensure a smooth transition. (This isn't necessary if you only upgrade Xcode.)

Migration procedure

  1. Reinstall Xcode. After a major system change, update the development tools by installing the latest version of Xcode.
  2. Reinstall MacPorts base. After updating the development tools, install the base MacPorts system for your new platform, either from the appropriate installer or from source.
    1. 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 and later 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.
  3. Reinstall ports.
    # If there is an argument, then don't preserve 'requested' flags.
    function reinstallPorts() {
      local -r dontPreserveRequestedFlags=$1
      set -e
      # This will fail if xcode-select needs to be run.
      clang --version
      # Save the list of installed ports.
      port -qv installed > myports.txt
      # Preserve the requested flags (optional).
      if [[ ! $dontPreserveRequestedFlags ]] ; then
        port echo requested | cut -d ' ' -f 1 > requested.txt
      fi
      # Download the restore_ports script.
      curl -O https://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl
      chmod +x restore_ports.tcl
      sudo bash << EOF
        # Start with the latest data.
        port selfupdate
        # Uninstall all installed ports.
        port -f uninstall installed
        # Clean any partially-completed builds.
        port clean all
        # Change this if your installation is somewhere else.
        # (There should be a way to get the port command to report this.)
        MACPORTS_HOME=/opt/local
        # Execute the restore_ports script.
        ./restore_ports.tcl -p $MACPORTS_HOME myports.txt
        if [[ ! $dontPreserveRequestedFlags ]] ; then
          port unsetrequested installed
          < requested.txt xargs port setrequested
        fi
      EOF
    }
    

Troubleshooting

Though it is now quite well-tested, the restore_ports script may fail in some cases. 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.

In the worst case, you can reinstall your ports manually:

  1. Browse myports.txt and install the ports one by one, remembering to specify the appropriate variants:
    sudo port install portname +variant1 +variant2 …
    

Note that if you have specified variants which are not the default, you may need to install ports in an order other than the alphabetical order recorded in myports.txt. You may skip explicitly installing ports that you did not request as long as they are not using non-default variants, since they will be installed as dependencies of other ports.