My Profile Photo

Juan Roa

Web Developer from Cali, Colombia. HTML5 | CSS3 | JS | Ruby on Rails | SASS | PostgreSQL | Linux SysAdmin

Swift 2 on Linux

Maybe many of you didn’t notice that Apple has open-sourced its Swift 2 code (compiler and core-libraries too) under the MIT license the past december (2015).

I’m going to show you how to install it on your Linux System (Archlinux, Ubuntu and Debian distros) and how to run some basic examples on the swift shell environment.

Ubuntu 14.04-3

At first, we’re going to install some dependences and libs needed for swift lang.

sudo apt-get update
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

Lets get the swift package for this version of Ubuntu.


Now, untar (decompress) the package

tar -zxvf swift-2.2-SNAPSHOT-2016-02-08-a-ubuntu14.04.tar.gz

Ubuntu 15.10

This is your package at 15.10


Decompress the package

tar -zxvf swift-2.2-SNAPSHOT-2016-02-08-a-ubuntu15.10.tar.gz

Export the environment variable

export PATH=/path/to/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin/:"${PATH}"

Test your swift installation

swift --version

Let try something in swift lang !

print("Hello World!")  

> Hello World!


> $R0: Int = 201

We’ve set swift 2 on Ubuntu ! Now, lets do it for Archlinux.

Install the binary package from AUR repo

yaourt -S swift-bin

I’m sure that you will get some kind of error about GPG keys, like this:

==> Validating source files with md5sums...

    ncurses-6.0.tar.gz ... Passed

    ncurses-6.0.tar.gz.asc ... Skipped

==> Verifying source file signatures with gpg...

    ncurses-6.0.tar.gz ... FAILED (unknown public key 702353E0F7E48EDB)

==> ERROR: One or more PGP signatures could not be verified!

==> ERROR: Makepkg was unable to build ncurses5-compat-libs.

Fix: Install the GPG signature for ncurses package

gpg --keyserver --recv-keys C52048C0C0748FEE227D47A2702353E0F7E48EDB

Possible error # 2:

==> Validating source files with sha256sums...

    swift-2.2-SNAPSHOT-2015-12-10-a-ubuntu15.10.tar.gz ... Passed

    swift-2.2-SNAPSHOT-2015-12-10-a-ubuntu15.10.tar.gz.sig ... Skipped

==> Verifying source file signatures with gpg...

    swift-2.2-SNAPSHOT-2015-12-10-a-ubuntu15.10.tar.gz ... FAILED (unknown public key D441C977412B37AD)

==> ERROR: One or more PGP signatures could not be verified!

==> ERROR: Makepkg was unable to build .

“Another GPG signature missing…”

Fix it with:

wget -q -O - | gpg --import -  

And that’s all!

Step Bytes
raw 24019
endings 23893
startings 23875
comments 23801
collapse 22189
clippings 22068