Version 124 (modified by cooljeanius (Eric Gallager), 3 years ago) (diff) |
---|
Migrating MacPorts after a major operating system upgrade or from one computer to another
A MacPorts installation is designed to work with a particular operating system and a particular hardware architecture.
This migration procedure ensures a smooth transition after major system changes, such as:
- major operating system upgrades (e.g., from macOS 10.15 Catalina to macOS 11 Big Sur).
- architecture migrations (e.g., from Intel to Apple Silicon).
- migrations from one computer to another
If you don't want to migrate, you can always uninstall MacPorts entirely before manually reinstalling ports.
Note: If you move from one Mac to another Mac using Migration Assistant, you have to do it first.
Migration procedure
- Install the latest version of Xcode and the Xcode command-line tools
Install the latest version of Xcode that is compatible with your OS. Open the Xcode application once after installation and follow any prompts.
Install the same version of the command line tools. (Run
xcode-select --install
). Recent versions of macOS have a bug that prevents them from automatically updating the command line tools, so if the preceding command says they're already installed, they may not be up to date and you may need to update manually by following the instructions in ProblemHotlist#reinstall-clt.
- Reinstall MacPorts base system
To reinstall, simply install the base MacPorts system for your new platform.
- Update your macports.conf (if not default)
If your
macports.conf
(typically at/opt/local/etc/macports/macports.conf
) contains uncommented settings foruniversal_archs
orbuild_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. Default values are fine for most 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 yourmacports.conf
with the corresponding line inmacports.conf.default
in the same directory. Unless you know a reason why a line in your settings file should be different from the defaults, adopt the line from the defaults file.
- Reinstall your ports
- Save the list of installed ports:
port -qv installed > myports.txt
- Save the list of requested ports:
port echo requested | cut -d ' ' -f 1 | uniq > requested.txt
- Uninstall all installed ports:
sudo port -f uninstall installed
- Run a regular clear out of your installation:
sudo port reclaim
- Download and execute the restore_ports script. (If you installed MacPorts from source and used a custom prefix, then you'll need to use the -p option when you run restore_ports.tcl; see
./restore_ports.tcl -h
.)curl --location --remote-name https://github.com/macports/macports-contrib/raw/master/restore_ports/restore_ports.tcl chmod +x restore_ports.tcl xattr -d com.apple.quarantine restore_ports.tcl sudo ./restore_ports.tcl myports.txt
Note: ports that are not available on your new platform will be skipped, with only a warning message.
- Restore requested status:
If you saved the list of requested ports, you can now restore the requested flags for your newly installed ports to their former states.
sudo port unsetrequested installed xargs sudo port setrequested < requested.txt
Warning: if a port inrequested.txt
was not installed in the previous step, the iterativesetrequested
will terminate, leaving some ports still marked as not-requested. Editrequested.txt
to remove any ports that were not installed and repeat this step. Double-check your desired ports are set as requested withport echo requested
.
- Save the list of installed ports:
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 by browsing myports.txt
and installing 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.
If you see an "infinite loop" error message, such as this:
Error: we appear to be stuck, exiting... infinite loop while executing "sort_ports $portList" invoked from within "set operationList [sort_ports $portList]" (file "./restore_ports.tcl" line 285)
it indicates that the script has a list of ports to install, and it can't figure out which of the ports to install next. Each port has some obstacle that prevents it from being the next to install. One cause of this problem is a "dependency cycle": port A depends directly or indirectly on port B, while port B depends on port A. A workaround is to reduce your list of ports to install, until it no longer has a dependency cycle. Note that if you still need additional help debugging a dependency cycle like this, there is a pull request against this script that may improve things: https://github.com/macports/macports-contrib/pull/10
If things go really wrong, don't forget that you can always uninstall MacPorts entirely before manually reinstalling ports.
Another potential problem is that the restore_ports.tcl
command may fail with a Too many open files
error message. Under macOS Sierra, the default shell has a default ulimit
of 256 open files. The solution is to restore the ports with a slightly modified command:
sudo bash -c "ulimit -n 4096; ./restore_ports.tcl myports.txt"
This will raise the file limit for the duration of the restore_ports.tcl
command.
Another potential problem comes from possible differences between ports that do compile on an older macOS, but no longer on the newer. For instance, you might have installed OpenBLAS om macOS Mojave. This was built with gcc10, the then preferred version of gcc. OpenBLAS sets a +gcc10 variant for this and it has remained like that as long as you were updating it. When upgrading to macOS Monterey according to the procedure above, MacPorts will try to exactly recreate what was on Mojave, hence OpenBLAS +gcc10. But gcc10 may not compile on macOS Monterey (it does not as I write this example). Hence, the migration of OpenBLAS and everything that depends on it fails.