Skip to main content

Mike Kreuzer

Install Swift on Debian

11 June 2024

Big breath out. The 2024 WWDC Keynote & SOTU are over & nothing's going to break that's obvious. Phew.

One segment of the SOTU was about open source & Swift, & Swift on servers, which got me wanting to play with that again. The instructions on swift.org to install Swift on Debian are incomplete, however. Partly in the spirit of being the change etc, but also just as a note to myself when I want to do this again in a few weeks, here are the steps to install Swift on Debian Bookworm.

(No I haven't bothered with a pull request on Github. Partly because I don't like Github, but also because I've tried that before. Last time I submitted something to Apple on Github it sat around for a year until it got rejected as out of date. There are pull requests queued up on the site repo from March last year, so I think I'll pass.)

The option of adding a third party repo's missing. I haven't tried it, but swiftlang.xyz's out there.

If you're installing it directly though, the main missing piece of the puzzle is installing the prerequisites, which are different on Debian to any of the other distros listed.

sudo apt-get -q install -y \
    binutils-gold \
    build-essential \
    libicu-dev \
    libcurl4-openssl-dev \
    libedit-dev \
    libsqlite3-dev \
    libncurses-dev \
    libpython3-dev \
    libxml2-dev \
    pkg-config \
    uuid-dev \
    tzdata \
    git

Those are cribbed from the Swift Bookworm Docker file.

Added 23 June 2024: build-essential added to that list in place of just gcc, it's not all needed to install Swift but if you want to build most anything you'll need the C++ headers it has.

After that it's a matter of downloading the tarball from swift.org & unpacking it somewhere. I put apps that don't come from apt into /opt, but feel free to follow your own star.

For the Arm version of Debian for the Raspberry Pi, that's:

curl -O https://download.swift.org/swift-5.10.1-release/debian12-aarch64/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-debian12-aarch64.tar.gz

sudo tar -xvf swift-5.10.1-RELEASE-debian12-aarch64.tar.gz -C /opt

Changing the file name for x86.

You could do the PGP dance at that point if you wanted to. You could even use the Rust Sequoia PGP app for the eponymous lolz.

To finish up you need to add the /usr/bin directory from the unpacked files to your ~/.profile, like eg:

export PATH=/opt/swift-5.10.1-RELEASE-debian12-aarch64/usr/bin:"${PATH}"

And you're done. Profit.