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

简介: Swift的开发环境可以使用苹果平台(OS X)或Linux系统(Ubuntu),这里介绍在我在Ubuntu 14 server下安装Swift运行环境的过程1、安装所需的依赖项$ sudo apt-get install clang libicu-dev我是先安装的clang,中间会...

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.
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
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,回车,看看效果吧!

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


注意这里使用export设置的环境变量只是临时的,重新打开shell窗口、重新登录、重新启动之后等都会失效,

要设置为永久的请参考:Ubuntu修改配置环境变量


目录
相关文章
|
2天前
|
并行计算 Ubuntu Docker
Docker环境Ubuntu20.04安装Python3.10版本
Docker环境Ubuntu20.04安装Python3.10版本
14 0
|
2天前
|
Ubuntu Shell Linux
ubuntu安装conda
ubuntu安装conda
8 0
|
2天前
|
Ubuntu Docker 容器
Ubuntu 22.04.3 LTS_安装Docker
Ubuntu 22.04.3 LTS_安装Docker
29 1
|
2天前
|
并行计算 Shell Docker
【环境配置】Ubuntu16.04安装nvidia-docker
【环境配置】Ubuntu16.04安装nvidia-docker
18 2
|
2天前
|
并行计算 Ubuntu
Ubuntu安装CUDA和cuDNN
Ubuntu安装CUDA和cuDNN
10 3
|
2天前
|
Ubuntu NoSQL 数据安全/隐私保护
如何在在虚拟机中安装Ubuntu
如何在在虚拟机中安装Ubuntu
9 0
|
2天前
|
SQL 分布式计算 关系型数据库
Ubuntu上安装MySQL以及hive
Ubuntu上安装MySQL以及hive
14 1
|
2天前
|
Ubuntu Unix Linux
在Ubuntu安装RPM文件
Ubuntu使用`apt`和`alien`工具安装软件。`deb`是Ubuntu的标准包格式,但通过`alien`可转换及安装`RPM`包。首先确保启用`Universe`源,然后安装`alien`。转换RPM包为DEB包,运行`sudo alien package_name.rpm`,接着用`sudo apt install package_name.deb`安装。直接安装RPM包可使用`sudo alien -i package_name.rpm`,但这种方法不推荐,可能导致依赖性冲突和系统不稳定。
28 10
|
2天前
|
Ubuntu
ubuntu软件包安装
ubuntu软件包安装
18 1
|
2天前
|
分布式计算 Ubuntu Java
PySpark安装及WordCount实现(基于Ubuntu)
现在,你已经成功安装了PySpark并实现了WordCount示例。你可以根据实际需求修改脚本以处理不同的文本数据。
14 0