Linux Installation Options

Installation via Docker

Swift official Docker images are hosted on hub.docker.com/_/swift.

Swift Dockerfiles are located on swift-docker repository.

Using Docker Images

  1. Pull the Docker image from Docker Hub:

    docker pull swift
    
  2. Create a container using tag latest and attach it to the container:

    docker run --privileged --interactive --tty \
    --name swift-latest swift:latest /bin/bash
    
  3. Start container swift-latest:

    docker start swift-latest
    
  4. Attach to swift-latest container:

    docker attach swift-latest
    

Installation via Tarball

  1. Install required dependencies:
Ubuntu 18.04 Ubuntu 20.04 Ubuntu 22.04 CentOS 7 Amazon Linux 2
$ apt-get install \
          binutils \
          git \
          libc6-dev \
          libcurl4 \
          libedit2 \
          libgcc-5-dev \
          libpython2.7 \
          libsqlite3-0 \
          libstdc++-5-dev \
          libxml2 \
          pkg-config \
          tzdata \
          zlib1g-dev
$ apt-get install \
          binutils \
          git \
          gnupg2 \
          libc6-dev \
          libcurl4 \
          libedit2 \
          libgcc-9-dev \
          libpython2.7 \
          libsqlite3-0 \
          libstdc++-9-dev \
          libxml2 \
          libz3-dev \
          pkg-config \
          tzdata \
          uuid-dev \
          zlib1g-dev
$ apt-get install \
          binutils \
          git \
          gnupg2 \
          libc6-dev \
          libcurl4-openssl-dev \
          libedit2 \
          libgcc-9-dev \
          libpython3.8 \
          libsqlite3-0 \
          libstdc++-9-dev \
          libxml2-dev \
          libz3-dev \
          pkg-config \
          tzdata \
          unzip \
          zlib1g-dev
$ yum install \
      binutils \
      gcc \
      git \
      glibc-static \
      libbsd-devel \
      libedit \
      libedit-devel \
      libicu-devel \
      libstdc++-static \
      pkg-config \
      python2 \
      sqlite

      # __block conflicts with clang's __block qualifier
      sed -i -e 's/\*__block/\*__libc_block/g' /usr/include/unistd.h
$ yum install \
      binutils \
      gcc \
      git \
      glibc-static \
      gzip \
      libbsd \
      libcurl \
      libedit \
      libicu \
      libsqlite \
      libstdc++-static \
      libuuid \
      libxml2 \
      tar \
      tzdata
  1. Download the latest binary release (5.9.1).

    The swift-<VERSION>-<PLATFORM>.tar.gz file is the toolchain itself. The .sig file is the digital signature.

  2. If you are downloading Swift packages for the first time, import the PGP keys into your keyring:

    $ gpg --keyserver hkp://keyserver.ubuntu.com \
          --recv-keys \
          '7463 A81A 4B2E EA1B 551F  FBCF D441 C977 412B 37AD' \
          '1BE1 E29A 084C B305 F397  D62A 9F59 7F4D 21A5 6D5F' \
          'A3BA FD35 56A5 9079 C068  94BD 63BC 1CFE 91D3 06C6' \
          '5E4D F843 FB06 5D7F 7E24  FBA2 EF54 30F0 71E1 B235' \
          '8513 444E 2DA3 6B7C 1659  AF4D 7638 F1FB 2B2B 08C4' \
          'A62A E125 BBBF BB96 A6E0  42EC 925C C1CC ED3D 1561' \
          '8A74 9566 2C3C D4AE 18D9  5637 FAF6 989E 1BC1 6FEA' \
          'E813 C892 820A 6FA1 3755  B268 F167 DF1A CF9C E069'
    

    or:

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

    Skip this step if you have imported the keys in the past.

  3. Verify the PGP signature.

    The .tar.gz archives for Linux are signed using GnuPG with one of the keys of the Swift open source project. Everyone is strongly encouraged to verify the signatures before using the software.

    First, refresh the keys to download new key revocation certificates, if any are available:

    $ gpg --keyserver hkp://keyserver.ubuntu.com --refresh-keys Swift
    

    Then, use the signature file to verify that the archive is intact:

    $ gpg --verify swift-<VERSION>-<PLATFORM>.tar.gz.sig
    ...
    gpg: Good signature from "Swift Automatic Signing Key #4 <swift-infrastructure@forums.swift.org>"
    

    If gpg fails to verify because you don’t have the public key (gpg: Can't check signature: No public key), please follow the instructions in Active Signing Keys below to import the keys into your keyring.

    You might see a warning:

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

    This warning means that there is no path in the Web of Trust between this key and you. The warning is harmless as long as you have followed the steps above to retrieve the key from a trusted source.

    If gpg fails to verify and reports “BAD signature”, do not use the downloaded toolchain. Instead, please email swift-infrastructure@forums.swift.org with as much detail as possible, so that we can investigate the problem.

  4. Extract the archive with the following command:

    $ tar xzf swift-<VERSION>-<PLATFORM>.tar.gz
    

    This creates a usr/ directory in the location of the archive.

  5. Add the Swift toolchain to your path as follows:

    $ export PATH=/path/to/usr/bin:"${PATH}"
    

    You can now execute the swift command to run the REPL or build Swift projects.

Active Signing Keys

The Swift project uses one set of keys for snapshot builds, and separate keys for every official release. We are using 4096-bit RSA keys.

The following keys are being used to sign toolchain packages:

Download
https://swift.org/keys/release-key-swift-5.x.asc
Fingerprint
A62A E125 BBBF BB96 A6E0 42EC 925C C1CC ED3D 1561
Long ID
925CC1CCED3D1561

To import the key, run:

  $ gpg --keyserver hkp://keyserver.ubuntu.com \
        --recv-keys \
        'A62A E125 BBBF BB96 A6E0  42EC 925C C1CC ED3D 1561'

Or:

  $ wget -q -O - https://swift.org/keys/release-key-swift-5.x.asc | \
    gpg --import -

Expired Signing Keys

Installation via RPM

Use the instructions below for RPM installation:

Amazon Linux 2

$ curl https://download.swift.org/experimental-use-only/repo/amazonlinux/releases/2/swiftlang.repo > /etc/yum.repos.d/swiftlang.repo
$ amazon-linux-extras install epel
$ yum install swiftlang

CentOS 7

$ curl https://download.swift.org/experimental-use-only/repo/centos/releases/7/swiftlang.repo > /etc/yum.repos.d/swiftlang.repo
$ yum install epel-release
$ yum install swiftlang