Swift Runs on My Ubuntu Box Now, and I'm Weirdly Excited About It

Swift Runs on My Ubuntu Box Now, and I'm Weirdly Excited About It

Tutorials apple linux open-source programming swift

I don't normally get worked up over programming language news. Half the "huge announcement" posts that show up in my RSS reader turn out to be some startup's internal DSL with a marketing budget behind it. But last Thursday Apple actually did the thing people have been asking for since WWDC back in June: they put Swift up on GitHub, spun up swift.org, and shipped binary snapshots that run on Ubuntu, not just OS X.

I spent most of Saturday afternoon with it instead of doing yard work, which my wife wasn't thrilled about.

Getting it going took maybe twenty minutes, most of that just download time. The Ubuntu 14.04 toolchain tarball is a bit north of 300MB, so plan accordingly if you're not on decent broadband. Untar it, add the bin directory to your PATH, and swift --version just works. No Xcode, no simulator, no App Store account tied to anything. That part actually impressed me. I've installed enough half-finished "now on Linux!" releases over the years to expect at least one missing shared library error, and I did hit one, some libicu complaint on a fairly bare install, fixed with a quick apt-get install libicu-dev. Not nothing, but not the afternoon-eating nightmare I braced for either.

The REPL is the part worth trying first if you've got five minutes and don't want to set up a whole project. Type swift at the prompt and you get an interactive interpreter that feels a lot like working in Python or Node, except the type inference is doing something closer to what a real compiler does under the hood. I typed out a small script to bucket a list of numbers into evens and odds with filter and a closure, and it read almost exactly like the Swift code I'd seen in iOS tutorials all year, just running on a machine that's never had Xcode anywhere near it.

Here's my actual take, and I know some people will disagree with it: this matters a lot less for server-side Swift right now, despite what half of Hacker News wants it to mean, and a lot more as a signal about how Apple thinks about developer goodwill these days. Objective-C never got this treatment and never will. Putting the compiler, the standard library, and a chunk of the LLVM-based tooling under an Apache 2.0 license is a genuinely different posture for a company that spent a decade treating its toolchain like a trade secret. I'm not going to pretend anyone's shipping a real production backend on this in 2016. Probably not much happens there for a while yet. But the fact that a hobbyist on a ThinkPad can now poke at the same compiler that ships inside Xcode, for free, with the actual source sitting right there when something breaks, is a bigger deal than most of the tech press coverage made it sound.

One complaint, because there's always one: the Linux support is specifically Ubuntu 14.04 and 15.10, and I run Debian on my main dev box, so I ended up doing this whole experiment in a spare VirtualBox VM instead of my regular environment. Not a huge deal, just mildly annoying to spin up a VM for what should've been a five-minute curiosity check. If you're on Fedora or Arch you're building from source or waiting, and a few people in the swift-users mailing list were already grumbling about that by Friday night.

I also pored over some of the standard library source out of curiosity, and it's more readable than I expected a systems-ish runtime to be. There's clearly a lot of committee thinking baked into things like Optional and the collection protocols that isn't obvious just from writing app code. You can actually see the reasoning in the comments, which I'll take over documentation that goes stale six months after anyone bothers writing it.

None of this changes what I ship day to day. My actual job runs on a stack that has nothing to do with any of it. But it's the first new-language release in a long while that I bothered installing the same week it dropped instead of bookmarking the article and forgetting about it, and that counts for something on its own.