Five years ago installing Swift on a Raspberry Pi – or really any non-Apple platform – was fairly involved. Compared to getting a Raspberry Pi working to begin with it was easy, but still a far cry from apt install swift
.
Sadly it’s still not quite that easy (and some Python package is squatting on the swift
package name ๐คจ).
You can still install from source, in principle, although I’m not aware of any current instructions on how to do so. The buildSwiftOnARM project has seemingly been abandoned. I haven’t tested if their now-years-old instructions still work for the latest versions of Swift (e.g. 5.10, 6.0).
But, you shouldn’t need to build from source anymore – now you have many better options:
Swift.org (Apple-provided options)
- If you happen to be using a
yum
-centric platform, like RHEL / Amazon Linux / CentOS, you can (finally!) just install RPMs. - If you happen to use one of the officially supported Linux distributions, you can install via Docker. Alas many major distros are notably absent from that list, like Debian1 (and therefore Raspbian). ๐
It’s unfortunate that Swift.org pushes this as the preferred way to install Swift on Linux. I avoid Docker because it tends to just make everything more complex (and error-prone), and encourage bad software practices (“it works in my docker image ๐”).- You can bypass the Docker requirement via the relatively primitive method of splatting a tarball into your system. It works, it’s pretty quick, but it’s a maintenance hassle (no version management, no reliable update method, etc).
Swift Community Apt Repository
Thanks to the efforts of community volunteers – in particular the folks at FutureJones – there is the Swift Community Apt Repository, which fills the massive void left by Apple’s apparent hatred for apt
-based distros:
curl -s https://archive.swiftlang.xyz/install.sh | sudo bash
sudo apt install swiftlang
- There is no step 3!
More details (including the list of supported distros).
It’s a shame that it falls to third parties to make Swift on Linux easy (on major distros, at least). Don’t forget to support them if you benefit from their work!
โ๏ธ FutureJones also run Swift-Arm, which implies that only Swift 5.8 (and older) are supported. But in fact 5.10 is available – it seems they’ve just forgotten / chosen to stop posting about newly supported Swift versions.
- Though it appears Debian support is in the works. โฉ๏ธ
I’m using Swift on a RPi5/CM4 for the control plane and UI of an embedded audio product. It’s working well!
If anyone is using the 32-bit version of Raspberry Pi OS, we still need to cross compile for armv7/armhf. I put a guide up on how to do this here, if anyone is interested:
https://medium.com/@jesselzamora/cross-compiling-swift-5-10-1-for-linux-armv7-b15986c0f1bf
Of course, my hope is that eventually this could become an official “complete” toolchain. But for now this can be used with a little bit of time and effort.