Guides 11792 Published by

A quick guide that walks you through getting Apple’s Swift compiler up and running on an Ubuntu 20.04 server. It covers the essential package updates, required libraries, and the exact commands to download, extract, and add Swift to your system PATH. The steps are written for users comfortable with the command line but who prefer a safe, non‑root workflow. After following the four short sections you’ll be able to compile and run Swift code straight from your Linux terminal.



Install Swift on Ubuntu 20.04 – Quick, No‑Nonsense Guide

If you’ve ever wanted to tinker with Swift outside of Xcode, this short walk‑through will get the compiler running on an Ubuntu 20.04 server in a handful of minutes. I’ll point out the little gotchas that usually bite newcomers (like missing clang headers) and show you exactly what to type so you can start writing Swift scripts right away.

Update your package list

Before pulling anything, make sure apt’s view of the repositories is fresh. An outdated cache often leads to “dependency not found” errors later on.

sudo apt update && sudo apt upgrade -y

The -y flag skips the interactive yes/no prompt, which is handy when you’re scripting the whole install.

Install the runtime dependencies

Swift relies on a handful of libraries that aren’t pulled in by default on a minimal Ubuntu install. Skipping any of these will cause the binary to abort with cryptic “cannot open shared object file” messages.

sudo apt install -y clang libicu-dev libpython2.7-dev libtinfo5 libncurses5 libz3-dev

I’ve seen this fail after a kernel upgrade because the system replaced libncurses5 with libncurses6. If you hit “package not found”, roll back to the older library or install the compatibility package.

Grab the Swift tarball

Head over to swift.org and pick the version that matches your OS. The URL below points to the 5.3.3 release, which is stable for Ubuntu 20.04. If you want a newer snapshot, just swap the version numbers in the link.

wget https://swift.org/builds/swift-5.3.3-release/ubuntu2004/swift-5.3.3-RELEASE/swift-5.3.3-RELEASE-ubuntu20.04.tar.gz

Downloading directly avoids the extra HTML page parsing that a browser would do.

Extract and put Swift on the PATH

Extracting into /usr/share keeps system‑wide tools tidy, while adding the bin folder to $PATH lets you call swift from any shell session.

tar xzf swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
sudo mv swift-5.3.3-RELEASE-ubuntu20.04 /usr/share/swift echo 'export PATH=/usr/share/swift/usr/bin:$PATH' >> ~/.bashrc source ~/.bashrc

Why the source? Without it your current terminal wouldn’t see the new $PATH until you log out and back in.

Verify the installation

A quick version check confirms everything is wired correctly:

swift --version

You should see something like:

Swift version 5.3.3 (swift-5.3.3-RELEASE) Target: x86_64-unknown-linux-gnu

If you get a “command not found” error, double‑check that the export line made it into the right profile file (~/.bashrc for Bash, ~/.zshrc for Zsh).

A couple of practical notes

  • Root vs. sudo – I never run the whole install as root because a stray rm -rf / would wipe your system before you even notice. Adding sudo to each command gives you safety nets and logs what needed elevation.
  • Stale dependencies – On older VPS images, the default clang version can be too new for Swift 5.3.3, leading to compilation failures. Pinning clang to the repository’s stable release (sudo apt install clang-10) often solves the issue.

That’s it. You now have a working Swift toolchain on Ubuntu 20.04 and can start playing with server‑side Swift, compile small utilities, or just satisfy that curiosity about Apple’s language on Linux.