It has been nearly 6 years since Apple first open sourced the Swift language and brought it to Linux. In that time we’ve seen the rise (and sometimes fall) of server-side frameworks such as Zewo, Kitura, and Vapor as well as porting Swift to SBC devices such as the Raspberry Pi and Beaglebone.
I recently checked in with some folks in the Swift ARM community to find out if there was an easy way to install the latest version of Swift on Ubuntu. FutureJones pointed me to a Debian-based repository he’s been working on at Swiftlang.xyz. A nicely put together repo, Swiftlang.xyz supports multiple flavors of Debian and Ubuntu OSes as well as both x86 and ARM architectures! I’ve installed Swift 5.4 and the upcoming 5.6 release with great success.
Using https://swiftlang.xyz/public/ is a piece of cake with an installer script to configure your apt
repository list automatically. arkansas
below is an Ubuntu VM running on Apple Silicon with Parallels.
Type curl -s https://swiftlang.xyz/install.sh | sudo bash
to get started.
I want to use Swift 5.6 so I’ll select option 2 which will include the dev
repository in my apt
sources.
1 2 3 |
root@arkansas:~# cat /etc/apt/sources.list.d/swiftlang-release.list deb https://archive.swiftlang.xyz/ubuntu/ hirsute main dev deb https://swiftlang.xyz/ubuntu/ hirsute main dev |
Now it’s time to install Swift through the provided swiftlang
package. apt-get install swiftlang
is all it takes.
Once installed let’s kick the tires a bit. First, typing swift
in the terminal will bring up the REPL:
1 2 3 4 |
root@arkansas:~# swift Welcome to Swift version 5.6-dev (LLVM ba0b85f590c1ba2, Swift d18133629449a50). Type :help for assistance. 1> |
To really test things out let’s hit a REST API and destructure the response. For this we’ll use ReqRes and just grab a user with GET https://reqres.in/api/users/2
.
1 |
{"data":{"id":2,"email":"janet.weaver@reqres.in","first_name":"Janet","last_name":"Weaver","avatar":"https://reqres.in/img/faces/2-image.jpg"},"support":{"url":"https://reqres.in/#support-heading","text":"To keep ReqRes free, contributions towards server costs are appreciated!"}} |
And now, some code!