最新のxcodeを使うために、社用のMacBookAirのOSをyosemiteからHighSierraに更新した。
すると当然macportsが動かなくなったので、macportsを使えるようにする。
エラー
selfupgradeなど何かを更新しようとするとPlatformが変わってますよ、とエラーが出る。
$ sudo port selfupdate
Password:
Error: Current platform "darwin 17" does not match expected platform "darwin 14"
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
対処法
1.Xcodeの最新版をインストール
Xcode and the Xcode Command Line Toolsをインストールする
$ xcode-select --install
xcode-select: note: install requested for command line developer tools
Xcode licenseの同意
$ sudo xcodebuild -license
enter→文章を下まで→"agree"
2.macportsの最新版をインストール
何も考えずにmacportsの公式サイト(下記)からOSに対応するversionのmacportsのインストーラーをdownloadして、インストールする。
The MacPorts Project -- Installing MacPorts
https://www.macports.org/install.php
最新版が正しくインストールされているか確認。
$ sudo port selfupdate
Password:
---> Updating MacPorts base sources using rsync
MacPorts base version 2.4.3 installed,
MacPorts base version 2.4.3 downloaded.
---> Updating the ports tree
---> MacPorts base is already the latest version
The ports tree has been updated. To upgrade your installed ports, you should run
port upgrade outdated
3.portをインストールし直す。
前のOSの際にインストールしたportのlistを保存する。
$ port -qv installed > myports.txt
requestedのportのlistを保存する。(optional)
$ port echo requested | cut -d ' ' -f 1 > requested.txt
インストールされているportをアンインストールする。
$ sudo port -f uninstall installed
---> Deactivating gedit @3.28.1_0+python36
---> Cleaning gedit
---> Uninstalling gedit @3.28.1_0+python36
---> Cleaning gedit
(以下略)
部分的にbuildされたものを削除する。
$ sudo rm -rf /opt/local/var/macports/build/*
restore_portsのscriptをdownloadして実行する。
$curl --location --remote-name https://github.com/macports/macports-contrib/raw/master/restore_ports/restore_ports.tcl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 164 0 164 0 0 195 0 --:--:-- --:--:-- --:--:-- 195
100 9474 100 9474 0 0 7461 0 0:00:01 0:00:01 --:--:-- 7461
$chmod +x restore_ports.tcl
$sudo ./restore_ports.tcl myports.txt
"requestedのport listを保存していれば"、requested statusをrestoreする。
※保存していない場合は、インストールされていないportにnot-requestedのフラグが立ち、削除したりするなどの良くないことが起きる。
※その場合は、requested.txtを編集して、インストールされていないportを手作業で削除する必要がある。
※port echo requestedなどでチェック。
$ sudo port unsetrequested installed
$ xargs sudo port setrequested < requested.txt
4.躓いたことがある箇所
4.1
"1.Xcodeの最新版をインストール"で、インストールのコマンドを入力しウィンドウが立ち上がり、インストール完了画面になり、Xcode licenseの同意コマンドを入力すると、以下のようなエラーが出る。
$ sudo xcodebuild -license
Password:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
command line toolsはインストールされている。
$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
とここで、そもそもapp storeからXcodeをインストールしていないことに気がづいた。笑
apple idが無いと、Xcodeはインストール出来ないことに注意。
4.2
HighSierra→Catalinaのように、OSのバージョンに対応するXcodeのバージョンにギャップがあることが問題になるLibraryについては、以下のようなerrorが出る。
Error: The installed version of Xcode (10.1) is too old to use on the installed OS version. Version 11.1 or later is recommended on macOS 10.15.
この時は、素直にapp storeからXcodeをアップデートしましょう。