如果你對(duì)Swift熱情萬分,請(qǐng)看此文,此文介紹 Swift 源碼方式安裝,如果你只是希望安裝運(yùn)行、編譯環(huán)境,請(qǐng)看此文。
環(huán)境準(zhǔn)備
- Ubuntu 14.04
- apt-get
源的選擇
由于庫比較新,需要使用官方源,修改方法如下。
首先備份源列表(for sure):
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
而后用gedit或其他編輯器打開:
gksu gedit /etc/apt/sources.list[](http://wiki.ubuntu.org.cn/File:Qref_Kubuntu_Logo.png) kdesudo kate /etc/apt/sources.list [](http://wiki.ubuntu.org.cn/File:Qref_Xubuntu_Logo.png) gksu mousepad /etc/apt/sources.list[](http://wiki.ubuntu.org.cn/File:Qref_Xubuntu_Logo.png) gksu leafpad /etc/apt/sources.list (12.04版)[](http://wiki.ubuntu.org.cn/File:Qref_Edubuntu_Logo.png) gksu gedit /etc/apt/sources.list
從下面列表中選擇合適的源,替換掉文件中所有的內(nèi)容,保存編輯好的文件:
deb http://archive.ubuntu.com/ubuntu/ vivid main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ vivid-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ vivid-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ vivid-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ vivid-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ vivid main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ vivid-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ vivid-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ vivid-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ vivid-backports main restricted universe multiverse
一定要執(zhí)行下面的Shell更新 apt-get
sudo apt-get update
安裝依賴
執(zhí)行以下命令安裝 Swift 依賴
sudo apt-get install git cmake ninja-build clang uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config
如果你的系統(tǒng)版本低于 14.04,執(zhí)行以下Shell:
sudo apt-get install clang-3.6
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
下載 Swift 源碼到本機(jī)
創(chuàng)建一個(gè) Swift 的目錄,然后在該目錄下執(zhí)行以下命令 Clone Github 上的源文件到本機(jī)。
git clone https://github.com/apple/swift.git swift
git clone https://github.com/apple/swift-llvm.git llvm
git clone https://github.com/apple/swift-clang.git clang
git clone https://github.com/apple/swift-lldb.git lldb
git clone https://github.com/apple/swift-cmark.git cmark
git clone https://github.com/apple/swift-llbuild.git llbuild
git clone https://github.com/apple/swift-package-manager.git swiftpm
git clone https://github.com/apple/swift-corelibs-xctest.git
git clone https://github.com/apple/swift-corelibs-foundation.git
嘆完一杯星巴克后,再回來,發(fā)現(xiàn),已經(jīng)執(zhí)行完這些命令了。
設(shè)置環(huán)境變量并安裝 Ninja
export PATH=/Applications/CMake.app/Contents/bin:$PATH
git clone https://github.com/martine/ninja.git
cd ninja
./configure.py --bootstrap
然而,安裝完這些以后,到現(xiàn)在,對(duì)我們來說并沒有什么卵用。
接下來,我們再討論一下從源碼安裝后的一些開發(fā)指南。