How to Install and run Swift on a Linux Machineby@alexadam
244 reads

How to Install and run Swift on a Linux Machine

by Alex Adam2mDecember 18th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

How to install and run Swift on Linux

Company Mentioned

Mention Thumbnail
featured image - How to Install and run Swift on a Linux Machine
Alex Adam HackerNoon profile picture

A step-by-step guide on how to install Swift on Ubuntu 20.04.


Download Swift from -> select the Toolchain archive for Ubuntu 20.04

Extract the archive, then open ~/.bashrc and append this line:


Reload .bashrc with source ~/.bashrc

Install the required dependencies. See

Linux > Installation > Install required dependencies (for Ubuntu 20.04)

sudo apt-get install \
          binutils \
          git \
          gnupg2 \
          libc6-dev \
          libcurl4 \
          libedit2 \
          libgcc-9-dev \
          libpython2.7 \
          libsqlite3-0 \
          libstdc++-9-dev \
          libxml2 \
          libz3-dev \
          pkg-config \
          tzdata \
          uuid-dev \

Test it, in a terminal:

swift --version

# you should see something similar to
Swift version 5.5.2 (swift-5.5.2-RELEASE)
Target: x86_64-unknown-linux-gnu

Create an example app

Make a folder:

mkdir swift-app
cd swift-app

Then generate an empty project with:

swift package init --type executable

Build it:

swift build

and run the executable:


# or
swift run

# it should print Hello, world!