Swift currently officially supports running on Ubuntu (16.04, 18.04, 20.04) and Red Hat derivatives (currently CentOS 8 and Amazon Linux 2).

These are a few ways to get Linux*;

However you choose to get Linux, install Swift on the Command Line with these steps;

Install required dependencies (see the using downloads section of Swift docs for Linux dependencies based on distribution)

Download the Swift toolchain for your Linux version (with curl**)
$ curl -O https://swift.org/builds/swift-5.2.2-release/ubuntu1804/swift-5.2.2-RELEASE/swift-5.2.2-RELEASE-ubuntu18.04.tar.gz

Make install location (this example is a hidden folder on user root)
$ mkdir ~/.swift

Unpack and move to final install location
$ tar -xvzf swift-5.2.2-RELEASE-ubuntu18.04.tar.gz -C ~/.swift

Add the following to Path e.g. in ~/.profile
export PATH="~/.swift/swift-5.2.2-RELEASE-ubuntu18.04/usr/bin:$PATH"

Source the updated .profile***
$ source .profile

Verify Swift version installed
$ swift --version
Swift version 5.2.2 (swift-5.2.2-RELEASE)

Verify Swift in REPL
$ swift
Welcome to Swift version 5.2.2 (swift-5.2.2-RELEASE).
Type :help for assistance.
1> 1 * 1
$R0: Int = 1

Type :q to exit the Swift REPL

* Swift is also available in a Docker image and in WSL (Windows Subsystem for Linux), but my focus in on using Linux with a desktop.

** You might need to install curl
$ sudo apt-get install curl

*** The .profile configuration file is read once only at Logon, so you’ll need to logout / login again to make the change permanent. Learn more about Linux configuration files.

Written by Mark Brownsword

I've been working as an enterprise developer for more than 15 years, always using .NET platform and recently building for iOS with Swift. My degree is in Business Studies, majoring in information systems, where I learnt the fundamentals of software engineering for building systems for business.

1 comment

Comments are closed.