macOS xcode-select 切換Xcode 正式版與測試版

macOS xcode-select 切換Xcode 正式版與測試版

vs

每次Xcode改版時都會面臨要進行Xcode Beta的試用,然而這次的Xcode 6伴隨著Apple新一代語言Swift的關系,2種版本的Xcode同時存在顯得是必要的,所以Apple已經有為開發者準備一個命令xcode-select來切換預設的Xcode相關路徑。

參數命令

在命令列中執行:

xcode-select

了解一下它的命令提供什麼樣的功能:

Usage: xcode-select [options]

Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example,
xcodebuild) as well as the BSD development commands (such as cc and make).

Options:
  -h, --help                  print this help message and exit
  -p, --print-path            print the path of the active developer directory
  -s <path>, --switch <path>  set the path for the active developer directory
  --install                   open a dialog for installation of the command line developer tools
  -v, --version               print the xcode-select version
  -r, --reset                 reset to the default command line tools path

依照上面的原文稍為解釋一下:

-h 螢幕上印出幫助訊息
-p 螢幕上印出目前設定的路徑
-s 設定路徑,這裡提供的路徑為Developer的路徑
-v 螢幕上印出xcode-select版本
-r 重設回xcode-select預設的路徑
--install 開啟指示安裝命令列開發者工具的對話框

使用

xcode-select命令需要透過sudo才能正確執行,接下來依各個參數進行實作。

  • -v
$ sudo xcode-select -v

執行結果:

xcode-select version 2333.

  • -p
$ sudo xcode-select -p

執行結果:

/Applications/Xcode.app/Contents/Developer

  • -s

使用方法:

$ sudo xcode-select -s 路徑

路徑必需要指定Xcode App之中的Developer的路徑,舉個例子:

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

像Xcode6 Beta5就要改成:

$ sudo xcode-select -s /Applications/Xcode6-Beta5.app/Contents/Developer

  • -r

如果已經不確定怎麼做了,那就將它重置吧!重置後會回到預設路徑:

$ sudo xcode-select -r

執行結果:

/Applications/Xcode.app/Contents/Develope

  • –install

此命令在後期才加上,讓開發者可以重新執命令列開發者工具是否要再度安裝的提示:

xcode-select --install

執行後會跳出示窗詢問是否安裝命令列開發者工具

Xcode編譯時產生錯誤,或是錯過此提示安裝命令列開發者工具時就能手動的再次呼叫此對話框重新安裝命令列開發者工具

參考資料

更新日誌

日期 內容
2017/06/14 更新xcode-select新版參數及內容
2014/08/19 初版

關鍵字

  • xcode-select 切換Xcode預設路徑
  • Xcode 正式版 測試版 切換
  • Xcode 正式版 測試版 同時使用 併存
  • 切換預設的 Xcode
  • 切換默認的 Xcode