Getting started with Swift 3 on Linux
Posted on November 8, 2016 by Paul
In this article, I will show you how to install and use Swift 3 on Linux. Swift is officially tested and supported on Ubuntu Linux. I will assume that you have Ubuntu 16.04 installed on your server or on your local computer.
First, make sure that you have an up to date system:
Next, install Clang which is required if you want to be able to use the Swift compiler:
You can download the official Swift binary for Ubuntu 16.04 from swift.org. Chose the latest stable release (currently this is version 3.0.1). If you see a new version of Swift, update the URL from the next instructions accordingly:
At this point, you have Swift installed. Next step is to add it to your system PATH:
If you want to permanently add Swift to your PATH, use:
Let’s check the version of Swift installed. This is what I see on my machine:
You can start a Swift REPL with the swift command, after which you can start writing Swift. When you want to to close the REPL, use :q. Here is a simple example of a Swift REPL session:
If you want to compile a Swift code, you will use the swiftc command. Open a new text file and copy the next piece of code:
save the file as “Hello.swift”. You can compile and run the code with:
If you are interested to learn more about the latest Swift syntax, I would recommend reading Swift Programming: The Big Nerd Ranch Guide (2nd Edition) by M Mathias, J Gallagher: