Porting Swift 3 to Debian


Swift is available for Linux. At the moment it is only available for Ubuntu linux. If you want it on another Linux flavor you have to compile it from source. This is a log of the steps to do this on Debian linux.This installation has been done on the Debian “jessie” release. It should not be relevant but I mentioned it for completeness, this installation was done in a chroot environment on a Synology machine.

The steps

The environment

The first step is to make sure that everything is up to date and to install the necessary development environment:

$ apt-get update && apt-get upgrade –assume-yes
$ apt-get install git cmake ninja-build clang python \
uuid-dev libicu-dev icu-devtools libbsd-dev \
libedit-dev libxml2-dev libsqlite3-dev swig \
libpython-dev libncurses5-dev pkg-config \
libblocksruntime-dev libcurl4-openssl-dev \
autoconf libtool systemtap-sdt-dev


Unfortunately the cmake that comes with the standard Debian distribution is not new enough. It needs to be at least version 3.8 so uninstall cmake:

$ apt-get remove cmake

Install the latest version from cmake

$ wget https://cmake.org/files/v3.8/cmake-3.8.0.tar.gz
$ cd cmake-3.8.0
$ ./configure
$ make
$ make install

Compile Swift

The next step is to download and install swift. This takes a very long time. In my case serveral hours.

$ cd /tmp
$ mkdir swift-source
$ cd swift-source
$ git clone https://github.com/apple/swift.git
$ ./swift/utils/update-checkout –clone
$ ./swift/utils/build-script –preset=buildbot_linux install_\
  destdir=”/tmp/install” installable_package=/tmp/swift.tar.gz

Although I havent tested this it should be possible to update this in the future using the following commands:

$ ./swift/utils/update-checkout –all
$ ./swift/utils/build-script –preset=buildbot_linux \
  install_destdir=”/tmp/install” \

The build command has to be identical to the previous request. If not there will be a full compile, if identical it will only compile the absolutely required and be much quicker.

Install Swift

In my case I install in the /opt directory so that all Swift binaries and libraries stay in a nice easy to replace place.

$ mkdir -p /opt/swift
$ cd /opt/swift
$ tar xfz /tmp/swift.tar.gz
$ sed -i -e ‘$a PATH=/opt/swift/usr/bin:$PATH’ /etc/profile

Testing Swift

During the compilation Swift is already tested but to finish off this is Hello World for Swift:

$ cd /tmp
$ echo ‘print(“hello world!”)’ > hello.swift
$ swiftc hello.swift -o hello
$ ./hello
hello world!


Have fun with Swift on Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.