Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Swift on Ubuntu

Install the dependencies, unpack the Swift toolchain, add it to PATH and check the version.

VPS and Cloud Servers1 min read8 screenshots

Step 1: Update the system

sudo apt update && sudo apt upgrade
Updating the system
  • apt update refreshes the package list.
  • apt upgrade installs newer versions of the installed packages.

Step 2: Install the dependencies

sudo apt install clang libpython3-dev libncurses-dev libxml2-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev
Installing the dependencies

clang is the compiler Swift uses. The other packages are libraries the toolchain needs. Check the Swift site for the exact list for your release.

Step 3: Download Swift

Get the toolchain for your Ubuntu version from swift.org. This example uses Swift 5.10.1 for Ubuntu 22.04:

wget https://download.swift.org/swift-5.10.1-release/ubuntu2204/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-ubuntu22.04.tar.gz
Downloading Swift

Step 4: Extract the archive

tar -xzf swift-5.10.1-RELEASE-ubuntu22.04.tar.gz
Extracting the Swift archive

Step 5: Move it to a system folder

sudo mv swift-5.10.1-RELEASE-ubuntu22.04 /usr/share/swift
Moving Swift to /usr/share/swift

Step 6: Add Swift to PATH

echo 'export PATH=/usr/share/swift/usr/bin:$PATH' >> ~/.bashrc
Adding the Swift path

Load the change:

source ~/.bashrc
Reloading the shell profile

Step 7: Check the version

swift --version
The Swift version

Quick recap

  • Install clang and the libraries.
  • Download and extract the toolchain, then move it to /usr/share/swift.
  • Add its usr/bin folder to PATH and run swift --version.