红联Linux门户
Linux帮助

《Swift入门》Ubuntu 14 server安装Swift运行环境

发布时间:2016-04-05 09:53:47来源:linux网站作者:微wx笑

Swift的开发环境可以使用苹果平台(OS X)或Linux系统(Ubuntu),这里介绍在我在Ubuntu 14 server下安装Swift运行环境的过程。


1、安装所需的依赖项

$ sudo apt-get install clang libicu-dev 

我是先安装的clang,中间会提示需要下载多少M的文件,安装完成后会占用多少磁盘空间,是否继续?

如下面加粗的部分所示,输入字母y,回车

# sudo apt-get install clang 
Reading package lists... Done 
Building dependency tree
Reading state information... Done 
The following extra packages will be installed: 
binfmt-support clang-3.4 libclang-common-3.4-dev libclang1-3.4 libffi-dev 
libllvm3.4 libobjc-4.8-dev libobjc4 libtinfo-dev llvm-3.4 llvm-3.4-dev 
llvm-3.4-runtime 
Suggested packages: 
llvm-3.4-doc 
The following NEW packages will be installed: 
binfmt-support clang clang-3.4 libclang-common-3.4-dev libclang1-3.4 
libffi-dev libllvm3.4 libobjc-4.8-dev libobjc4 libtinfo-dev llvm-3.4 
llvm-3.4-dev llvm-3.4-runtime 
0 upgraded, 13 newly installed, 0 to remove and 10 not upgraded. 
<strong>Need to get 31.3 MB of archives. 
After this operation, 156 MB of additional disk space will be used. 
Do you want to continue? [Y/n] y</strong> 
Get:1 http://hk.archive.ubuntu.com/ubuntu/ trusty/main libllvm3.4 amd64 1:3.4-1ubuntu3 [6,540 kB] 
Get:2 http://hk.archive.ubuntu.com/ubuntu/ trusty-updates/main libobjc4 amd64 4.8.4-2ubuntu1~14.04.1 [111 kB] 
Get:3 http://hk.archive.ubuntu.com/ubuntu/ trusty-updates/main libobjc-4.8-dev amd64 4.8.4-2ubuntu1~14.04.1 [378 kB] 
Get:4 http://hk.archive.ubuntu.com/ubuntu/ trusty/universe libclang1-3.4 amd64 1:3.4-1ubuntu3 [3,534 kB] 
Get:5 http://hk.archive.ubuntu.com/ubuntu/ trusty/main binfmt-support amd64 2.1.4-1 [49.0 kB] 
Get:6 http://hk.archive.ubuntu.com/ubuntu/ trusty/universe libclang-common-3.4-dev amd64 1:3.4-1ubuntu3 [667 kB] 
Get:7 http://hk.archive.ubuntu.com/ubuntu/ trusty/universe clang-3.4 amd64 1:3.4-1ubuntu3 [8,922 kB] 
Get:8 http://hk.archive.ubuntu.com/ubuntu/ trusty/universe clang amd64 1:3.4-0ubuntu1 [2,476 B] 
Get:9 http://hk.archive.ubuntu.com/ubuntu/ trusty/main libtinfo-dev amd64 5.9+20140118-1ubuntu1 [76.3 kB] 
Get:10 http://hk.archive.ubuntu.com/ubuntu/ trusty/main llvm-3.4-runtime amd64 1:3.4-1ubuntu3 [36.2 kB] 
Get:11 http://hk.archive.ubuntu.com/ubuntu/ trusty/main llvm-3.4 amd64 1:3.4-1ubuntu3 [1,078 kB] 
Get:12 http://hk.archive.ubuntu.com/ubuntu/ trusty-updates/main libffi-dev amd64 3.1~rc1+r3.0.13-12ubuntu0.1 [99.8 kB] 
Get:13 http://hk.archive.ubuntu.com/ubuntu/ trusty/main llvm-3.4-dev amd64 1:3.4-1ubuntu3 [9,801 kB] 
Fetched 31.3 MB in 1min 55s (272 kB/s)  
Selecting previously unselected package libllvm3.4:amd64. 
(Reading database ... 78700 files and directories currently installed.) 
Preparing to unpack .../libllvm3.4_1%3a3.4-1ubuntu3_amd64.deb ... 
Unpacking libllvm3.4:amd64 (1:3.4-1ubuntu3) ... 
Selecting previously unselected package libobjc4:amd64. 
Preparing to unpack .../libobjc4_4.8.4-2ubuntu1~14.04.1_amd64.deb ... 
Unpacking libobjc4:amd64 (4.8.4-2ubuntu1~14.04.1) ... 
Selecting previously unselected package libobjc-4.8-dev:amd64. 
Preparing to unpack .../libobjc-4.8-dev_4.8.4-2ubuntu1~14.04.1_amd64.deb ... 
Unpacking libobjc-4.8-dev:amd64 (4.8.4-2ubuntu1~14.04.1) ... 
Selecting previously unselected package libclang1-3.4:amd64. 
Preparing to unpack .../libclang1-3.4_1%3a3.4-1ubuntu3_amd64.deb ... 
Unpacking libclang1-3.4:amd64 (1:3.4-1ubuntu3) ... 
Selecting previously unselected package binfmt-support. 
Preparing to unpack .../binfmt-support_2.1.4-1_amd64.deb ... 
Unpacking binfmt-support (2.1.4-1) ... 
Selecting previously unselected package libclang-common-3.4-dev. 
Preparing to unpack .../libclang-common-3.4-dev_1%3a3.4-1ubuntu3_amd64.deb ... 
Unpacking libclang-common-3.4-dev (1:3.4-1ubuntu3) ... 
Selecting previously unselected package clang-3.4. 
Preparing to unpack .../clang-3.4_1%3a3.4-1ubuntu3_amd64.deb ... 
Unpacking clang-3.4 (1:3.4-1ubuntu3) ... 
Selecting previously unselected package clang. 
Preparing to unpack .../clang_1%3a3.4-0ubuntu1_amd64.deb ... 
Unpacking clang (1:3.4-0ubuntu1) ... 
Selecting previously unselected package libtinfo-dev:amd64. 
Preparing to unpack .../libtinfo-dev_5.9+20140118-1ubuntu1_amd64.deb ... 
Unpacking libtinfo-dev:amd64 (5.9+20140118-1ubuntu1) ... 
Selecting previously unselected package llvm-3.4-runtime. 
Preparing to unpack .../llvm-3.4-runtime_1%3a3.4-1ubuntu3_amd64.deb ... 
Unpacking llvm-3.4-runtime (1:3.4-1ubuntu3) ... 
Selecting previously unselected package llvm-3.4. 
Preparing to unpack .../llvm-3.4_1%3a3.4-1ubuntu3_amd64.deb ... 
Unpacking llvm-3.4 (1:3.4-1ubuntu3) ... 
Selecting previously unselected package libffi-dev:amd64. 
Preparing to unpack .../libffi-dev_3.1~rc1+r3.0.13-12ubuntu0.1_amd64.deb ... 
Unpacking libffi-dev:amd64 (3.1~rc1+r3.0.13-12ubuntu0.1) ... 
Selecting previously unselected package llvm-3.4-dev. 
Preparing to unpack .../llvm-3.4-dev_1%3a3.4-1ubuntu3_amd64.deb ... 
Unpacking llvm-3.4-dev (1:3.4-1ubuntu3) ... 
Processing triggers for man-db (2.6.7.1-1ubuntu1) ... 
Processing triggers for ureadahead (0.100.0-16) ... 
ureadahead will be reprofiled on next reboot 
Processing triggers for install-info (5.2.0.dfsg.1-2) ... 
Setting up libllvm3.4:amd64 (1:3.4-1ubuntu3) ... 
Setting up libobjc4:amd64 (4.8.4-2ubuntu1~14.04.1) ... 
Setting up libobjc-4.8-dev:amd64 (4.8.4-2ubuntu1~14.04.1) ... 
Setting up libclang1-3.4:amd64 (1:3.4-1ubuntu3) ... 
Setting up binfmt-support (2.1.4-1) ... 
binfmt-support start/running 
Setting up libclang-common-3.4-dev (1:3.4-1ubuntu3) ... 
Setting up clang-3.4 (1:3.4-1ubuntu3) ... 
Setting up clang (1:3.4-0ubuntu1) ... 
Setting up libtinfo-dev:amd64 (5.9+20140118-1ubuntu1) ... 
Setting up libffi-dev:amd64 (3.1~rc1+r3.0.13-12ubuntu0.1) ... 
Processing triggers for ureadahead (0.100.0-16) ... 
Setting up llvm-3.4-runtime (1:3.4-1ubuntu3) ... 
Setting up llvm-3.4 (1:3.4-1ubuntu3) ... 
Setting up llvm-3.4-dev (1:3.4-1ubuntu3) ... 
Processing triggers for libc-bin (2.19-0ubuntu6.7) ... 

接着安装libicu-dev

# sudo apt-get install clang libicu-dev 
Reading package lists... Done 
Building dependency tree
Reading state information... Done 
clang is already the newest version. 
The following extra packages will be installed: 
icu-devtools libicu52 
Suggested packages: 
icu-doc 
The following NEW packages will be installed: 
icu-devtools libicu-dev libicu52 
0 upgraded, 3 newly installed, 0 to remove and 10 not upgraded. 
Need to get 14.5 MB of archives. 
After this operation, 65.5 MB of additional disk space will be used. 
Do you want to continue? [Y/n] y 
Get:1 http://hk.archive.ubuntu.com/ubuntu/ trusty-updates/main libicu52 amd64 52.1-3ubuntu0.4 [6,752 kB] 
Get:2 http://hk.archive.ubuntu.com/ubuntu/ trusty-updates/main icu-devtools amd64 52.1-3ubuntu0.4 [163 kB] 
Get:3 http://hk.archive.ubuntu.com/ubuntu/ trusty-updates/main libicu-dev amd64 52.1-3ubuntu0.4 [7,588 kB] 
Fetched 14.5 MB in 2min 28s (97.7 kB/s) 
Selecting previously unselected package libicu52:amd64. 
(Reading database ... 79807 files and directories currently installed.) 
Preparing to unpack .../libicu52_52.1-3ubuntu0.4_amd64.deb ... 
Unpacking libicu52:amd64 (52.1-3ubuntu0.4) ... 
Selecting previously unselected package icu-devtools. 
Preparing to unpack .../icu-devtools_52.1-3ubuntu0.4_amd64.deb ... 
Unpacking icu-devtools (52.1-3ubuntu0.4) ... 
Selecting previously unselected package libicu-dev:amd64. 
Preparing to unpack .../libicu-dev_52.1-3ubuntu0.4_amd64.deb ... 
Unpacking libicu-dev:amd64 (52.1-3ubuntu0.4) ... 
Processing triggers for man-db (2.6.7.1-1ubuntu1) ... 
Setting up libicu52:amd64 (52.1-3ubuntu0.4) ... 
Setting up icu-devtools (52.1-3ubuntu0.4) ... 
Setting up libicu-dev:amd64 (52.1-3ubuntu0.4) ... 
Processing triggers for libc-bin (2.19-0ubuntu6.7) ... 


2、下载最新的二进制版本

# wget https://swift.org/builds/swift-2.2-release/ubuntu1404/swift-2.2-RELEASE/swift-2.2-RELEASE-ubuntu14.04.tar.gz

swift- <版本> - <平台> .tar.gz文件是工具链本身。
所述的.sig文件是数字签名。


3、如果您是首次下载Swift包,可导入PGP密钥到你的钥匙圈(可选,主要用于验证包的正确性)
使用以下命令:

$ gpg --keyserver hkp://pool.sks-keyservers.net \ 
--recv-keys \ 
'7463 A81A 4B2E EA1B 551F  FBCF D441 C977 412B 37AD' \ 
'1BE1 E29A 084C B305 F397  D62A 9F59 7F4D 21A5 6D5F' 

或者

$ wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - 

如果你之前已导入过钥匙,跳过这一步。

# wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - 
gpg: /root/.gnupg/trustdb.gpg: trustdb created 
gpg: key 412B37AD: public key "Swift Automatic Signing Key #1 <swift-infrastructure@swift.org>" imported 
gpg: key 21A56D5F: public key "Swift 2.2 Release Signing Key <swift-infrastructure@swift.org>" imported 
gpg: Total number processed: 2 
gpg:   imported: 2  (RSA: 2) 


4、验证PGP签名(可选)

Swift开源项目为Linux 下的.tar.gz文件使用GnuPG生成一个签名密匙文件,大力鼓励每个人都在使用软件之前验证签名,以确定文件的完整性,真实性,安全性。

首先刷新证书缓存

# gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift 
gpg: refreshing 2 keys from hkp://pool.sks-keyservers.net 
gpg: requesting key 412B37AD from hkp server pool.sks-keyservers.net 
gpg: requesting key 21A56D5F from hkp server pool.sks-keyservers.net 
gpg: key 412B37AD: "Swift Automatic Signing Key #1 <swift-infrastructure@swift.org>" not changed 
gpg: key 21A56D5F: "Swift 2.2 Release Signing Key <swift-infrastructure@swift.org>" 1 new signature 
gpg: Total number processed: 2 
gpg:  unchanged: 1 
gpg: new signatures: 1 
gpg: no ultimately trusted keys found 

然后,使用签名文件以验证存档是否完好

# gpg --verify swift-2.2-RELEASE-ubuntu14.04.tar.gz.sig 
gpg: Signature made Tuesday, March 22, 2016 AM02:15:34 CST using RSA key ID 21A56D5F 
gpg: Good signature from "Swift 2.2 Release Signing Key <swift-infrastructure@swift.org>" 
gpg: WARNING: This key is not certified with a trusted signature! 
gpg:  There is no indication that the signature belongs to the owner. 
Primary key fingerprint: 1BE1 E29A 084C B305 F397  D62A 9F59 7F4D 21A5 6D5F 

如果GPG无法验证,因为你没有公钥(GPG:无法检查签名:不公开密钥),请按照下面的Active签名密钥的指示键导入到你的钥匙圈。

您可能会看到一个警告:

gpg: WARNING: This key is not certified with a trusted signature! 
gpg:  There is no indication that the signature belongs to the owner. 

这个密钥没有被证明是可信的签名,没有任何迹象表明签名属于所有者


5、解压文件用下面的命令

# tar xzf swift-2.2-RELEASE-ubuntu14.04.tar.gz 

这会创建USR /目录在存档位置的目录下。
例如:/home/aven/swift-2.2-RELEASE-ubuntu14.04/usr


6、添加Swift到你的Path环境变量:

# export PATH=/home/aven/swift-2.2-RELEASE-ubuntu14.04/usr/bin:"${PATH}" 

现在,您可以执行快捷命令来运行交互式解释器(REPL)或建立Swift项目。
到这里就算安装完成了,你可以切换到任意目录下,输入swift,回车,看看效果吧!


上图:看最下面,你最熟悉的……,我就不说它是什么了。

《Swift入门》Ubuntu 14 server安装Swift运行环境


本文永久更新地址:http://www.linuxdiyf.com/linux/19510.html