Swift programming on Linux

Can I run swift compiler in Linux?

Yup! Apple only distributes builds for 64-bit Ubuntu, on other distros you’d have to compile it on your own.

Short installation instructions:

1. sudo apt-get install clang libicu-dev

2. Download binaries from here: 

3. Extract them (tar xzf swift-…tar.gz)

4. Add <extracted directory>/usr/bin to path environment:
export PATH=/path/to/usr/bin:"${PATH}”
preferably append this to your shell configuration file 
(.zshrc in my case)

5. Try running ‘swift’ command to verify your installation

Full installation instructions provided by Apple (ignore key validation steps, they’re not required):


If you’re running a Linux Virtual Machine from Mac, I strongly recommend using Parallels Desktop over free alternatives (has 14-day trial). After installing Parallels additions I got 2D and 3D hardware acceleration and smooth user experience, which I never got on VirtualBox.

How do I use it?

swiftc is a compiler (run swiftc —help), but in the beginning you’ll find swift REPL much more useful (just run: swift). It allows you to run swift code using interactive mode (scripting language style). Works fairly well, I do recommend it.

Can I run all this on Windows?

Not right now, currently it only builds on Linux. You can install Ubuntu 64-bit virtual machine and go from there.

What IDE should I use?

That’s a tough one! The only IDE that supports Swift (and doesn’t suck) is CLion from JetBrains. Yes, it’s proprietary (you get a free trial), but it’s pretty much your only choice (if you don’t feel like going back to 80-ties and coding in your text editor).

Currently stable release doesn’t support Swift plugin, you need to install (potentially unstable) Early Access Program version from here:


There’s also a Swift plugin download link on the page above, grab that one too. Then follow official configuration instructions:


Don’t make a mistake of skimming through them, they’re crucial. Pay attention to the CMakeLists file, you’ll have to configure yours too (add_swift live template helps in getting that chore done).

On the bottom of the article there’s a YouTube video presenting how properly configured IDE should behave and look like:

That’s as good as it gets with Swift on non-Apple OS.

In my case I experienced some EAP build crashes and the whole IDE worked much, much slower than it’s Mac OS version. At this point I gave up and just run the same version of CLion on my OS X natively.

If you have trouble configuring your CMake file in CLion, type add_swift in there, it’ll expand to a full template. After you do that, you should be able to create, compile and debug some Swift files. Enjoy!

Can I build iPhone apps on Linux? Pretty please?

Nope, you can’t. Swift is open source, as is it’s standard library, but Cocoa framework is not. You’ll never be able to write apps for iOS on Linux/Windows using Apple’s technologies. Deal with it. And you wouldn’t really want to: on Mac even if you’re normally using AppCode, you still revert to XCode from time to time. Like it or not, as an iOS developer you always depend on XCode to some extent.

Soo… is Swift programming on Linux a viable choice?

I would say it is, but only for learning purposes, not for writing anything useful. If you want to just play with the language, see for yourself what the hype is all about and how coding in Swift feels like, by all means, dive in swift REPL. It’s a tremendous help in learning the language and it runs perfectly fine on linux.

However if you want to write a more serious project in swift (not just play with some code samples from a book) just get a Mac. Your life it’s going to be so much easier, I promise. The tools that we have on OS X (Xcode, Code Runner, AppCode) are miles better and everything just works seamlessly. Plus you actually can write iOS apps, which will never be the case on Linux.



Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Log Out / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Log Out / Zmień )

Facebook photo

Komentujesz korzystając z konta Facebook. Log Out / Zmień )

Google+ photo

Komentujesz korzystając z konta Google+. Log Out / Zmień )

Connecting to %s

%d bloggers like this: