Macports: Current platform "darwin 19" does not match expected platform "darwin 17"

root's picture

Let's say you are in my situation: you have bought recently a new mac, with Catalina (10.15) and you are switching from an older one that was supporting only High Sierra (10.13).

And you get this error when trying to do sudo port selfupdate.

fmbpro:~ florian$ sudo port -v selfupdate
Password:
Error: Current platform "darwin 19" does not match expected platform "darwin 17"
Error: If you upgraded your OS, please follow the migration instructions: https://trac.macports.org/wiki/Migration
OS platform mismatch
    while executing
"mportinit ui_options global_options global_variations"
Error: /opt/local/bin/port: Failed to initialize MacPorts, OS platform mismatch

The error is explaining very well what is happening and the recommendation is to visit the Migration website for further instructions.
My recommendation (and tested of course) is to just download the latest macports, the Catalina version, install it, then proceed as normal with port selfupdate command.

Afterwards you need of course to run sudo port upgrade outdated and you get another error, related to Xcode.

fmbpro:~ florian$ sudo port -v upgrade outdated
--->  Fetching archive for gperf
--->  gperf-3.1_0.darwin_19.x86_64.tbz2 doesn't seem to exist in /opt/local/var/macports/incoming/verified
--->  Attempting to fetch gperf-3.1_0.darwin_19.x86_64.tbz2 from https://packages.macports.org/gperf
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 89471  100 89471    0     0   253k      0 --:--:-- --:--:-- --:--:--  253k
--->  Attempting to fetch gperf-3.1_0.darwin_19.x86_64.tbz2.rmd160 from https://packages.macports.org/gperf
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   512  100   512    0     0   6918      0 --:--:-- --:--:-- --:--:--  6918
Error: The installed version of Xcode (10.1) is too old to use on the installed OS version. Version 11.6 or later is recommended on macOS 10.15.
Error: Follow https://guide.macports.org/#project.tickets to report a bug.

Which is normal and you need to update that one too (via App Store). Once you are done with that, run again sudo port upgrade outdated and will be OK this time.

If you get compile errors, follow the migration instructions.

In short, you have to do the following:

fmbp:~ root# port -qv installed > myports.txt
fmbp:~ root# port echo requested | cut -d ' ' -f 1 > requested.txt
fmbp:~ root# port -f uninstall installed
fmbp:~ root# port selfupdate
fmbp:~ root# port clean all
fmbp:~ root# curl -O https://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl
fmbp:~ root# chmod +x restore_ports.tcl
fmbp:~ root# ./restore_ports.tcl myports.txt

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.