2016年2月26日 星期五

升級OS X後,重新安裝Macports

Macports是一個開源軟體的管理系統,運行在蘋果電腦上面。不過因為他不是蘋果公司出產的產品,所以每次作業系統大更新的時候,就變成要重新安裝,上面的軟體也要重新安裝。這次是將Yosemite (10.10)升級成El Capitan (10.11),Josh Smith介紹這次升級好玩的點

重新安裝的步驟參考Migrating a MacProts installation,在此簡單分成下面四個步驟:
  1. 備份舊版的OS X系統,與舊版的Macports
  2. 升級新OS X系統,並安裝相關應用程式
  3. 重新安裝Macports的基礎系統
  4. 重新安裝Macports管理的開源軟體

第1步 備份舊系統

備份舊版的Macports,都在/opt下面
# cd /opt
# tar cpvf - local | pigz -9 -p 4 > Yosemite.local.tgz
# tar cpvf - X11 | pigz -9 -p 4 > Yosemite.X11.tgz
# port -qv installed > Yosemite.myports
# port echo requested | cut -d ' ' -f 1 > Yosemite.requested

舊版OS X系統就用TimeMachine去做,做完後把外接備份硬碟給拔除(真的搞壞以後還可以還原回來)。



第2步 升級作業系統,安裝相關程式

用App Store升級系統,之後要安裝Xcode,裝完以後要執行下面指令拿到license
# xcodebuild -license
...
...
...

EA1327
8/11/15

By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel] agree

You can view the license agreements in Xcode's About Box, or at 
/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf

再來是安裝Command Line Tools,這樣才會有編譯器可以編譯macports下面的開源軟體。這次用指令安裝,會出現問題
# xcode-select --install
xcode-select: error: no developer tools were found, and no install could be requested (perhaps no UI is present), please install manually from 'developer.apple.com'.

因此只好去https://developer.apple.com/ 上面下載與作業系統相對應的套件Command_Line_Tools_OS_X_10.11_for_Xcode_7.2.pkg,點兩下依照指示安裝到好。
# xcode-select --install
xcode-select: error: command line tools are already installed, use 
"Software Update" to install updates



第3步 重新安裝Macports的基礎系統

這邊下載Macports的基礎系統,檔案是MacPorts-2.3.4-10.11-ElCapitan.pkg,點兩下依照指示會安裝到好。裝完以後,要先把所有以前安裝的開源軟體都殺掉
# port -f uninstall installed
# rm -rf /opt/local/var/macports/build/*

第一行指令是把以前安裝的軟體都解安裝
第二行指令則是把以前安裝編譯過程產生檔案也都刪除
通通都清除乾淨後/opt/local約莫剩下700MB



第4步 重新安裝Macports管理的開源軟體

使用Macports提供的腳本restore_ports.tcl,自動把以前的軟體給安裝上去
# curl -O https://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl
# chmod +x restore_ports.tcl
# ./restore_ports.tcl Yosemite.myports

慢慢等機器把程式給編譯好。因為編譯蠻吃CPU的,所以如果不希望把所有CPU都吃滿的話,去編輯/opt/local/etc/macports/macports.conf這個檔案,修改下面這行變成
buildmakejobs    1
這樣機器就只會用到一個核心在編譯,只是這樣就會比較慢。

沒有留言:

張貼留言