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*;
- A Virtual Machine e.g. VirtualBox
- A repurposed PC e.g. try using a live USB
- A dedicated PC e.g. System76
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
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
Welcome to Swift version 5.2.2 (swift-5.2.2-RELEASE).
Type :help for assistance.
1> 1 * 1
$R0: Int = 1
: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.
One response to “Swift on Linux: Getting Started”
[…] You’ll need Swift and Git installed before using […]