How to Install Swift on Ubuntu 26.04, 24.04 and 22.04

Last updated Wednesday, May 6, 2026 11:41 am Joshua James 8 min read

Swift is no longer tied to Apple-only workflows. On Linux it gives you the same compiler, package manager, and server-side tooling used for command-line apps, Vapor projects, and cross-platform development. To install Swift on Ubuntu Linux, the right method depends on your LTS release because Ubuntu 26.04 packages swiftlang, while Swift.org still targets Ubuntu 24.04 and 22.04 for its upstream toolchains.

That release split matters. Ubuntu 26.04 can install Swift directly from universe, but Ubuntu 24.04 and 22.04 need Swiftly or the official tarball. That gives you a complete path across all three supported Ubuntu LTS releases, from verification and a first Swift Package Manager project to troubleshooting, updates, and clean removal.

Install Swift on Ubuntu Linux

Three installation paths are available. Ubuntu 26.04 uses the swiftlang package, while Ubuntu 24.04 and 22.04 rely on Swift.org builds. On Ubuntu 24.04 and 22.04, do not use apt install swift for Apple’s language because that package name belongs to OpenStack Swift object storage.

MethodChannelRelease TrackUpdatesBest For
swiftlangUbuntu UniverseDistribution defaultapt upgradeUbuntu 26.04 users who want a system-managed install
SwiftlySwift.orgLatest stable upstreamswiftly updateUbuntu 24.04 and 22.04 users who want the easiest upstream workflow
Official tarballSwift.orgLatest stable upstreamsudo update-swift-tarballUbuntu 24.04 and 22.04 users who want an upstream install without a manager

Use swiftlang on Ubuntu 26.04, and use Swiftly on Ubuntu 24.04 or 22.04 unless you specifically want a manager-free tarball install. Ubuntu 26.04 currently ships Swift 6.1.x, while Swift.org’s Ubuntu 24.04 and 22.04 toolchains are already on Swift 6.3.x. Swiftly handled the compiler, Swift Package Manager, and CLI project builds cleanly on both older LTS releases, while the tarball method is useful when you want the same upstream toolchain under /opt without another layer on top.

These steps cover Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. Swift.org has not published native Ubuntu 26.04 toolchains yet, so Swiftly exits with Error: Unsupported Linux platform on Resolute and the upstream tarballs still target 24.04 or 22.04. Ubuntu 26.04 users should use swiftlang for now, then switch to Swift.org toolchains later only after upstream publishes native 26.04 downloads.

Update Ubuntu Before Installing Swift

Refresh the package index first so Ubuntu sees the latest repository metadata before you install Swift or any upstream prerequisites.

sudo apt update
Hit:1 http://au.archive.ubuntu.com/ubuntu resolute InRelease
Hit:2 http://security.ubuntu.com/ubuntu resolute-security InRelease
Reading package lists... Done

These commands use sudo for tasks that need root privileges. If your account is not in the sudoers file yet, follow the guide on how to add a new user to sudoers on Ubuntu.

Several packages used here come from Ubuntu’s universe component. If a minimal or customized system cannot locate swiftlang, gnupg2, libz3-dev, or python3-lldb-13, enable Universe on Ubuntu, then run sudo apt update again.

Install Swift from Ubuntu Repositories on Ubuntu 26.04

Ubuntu 26.04 packages Apple’s language as swiftlang in universe, which makes this the cleanest path on Resolute. The tested package download was about 558 MB and used roughly 2.5 GB after installation.

sudo apt install swiftlang

Check the compiler version once APT finishes.

swift --version
Swift version 6.1.3 (swift-6.1.3-RELEASE)
Target: x86_64-pc-linux-gnu

If you want to confirm Ubuntu is using its own package source rather than an older manual install, check the package policy.

apt-cache policy swiftlang
swiftlang:
  Installed: 6.1.3-4build1
  Candidate: 6.1.3-4build1
  Version table:
 *** 6.1.3-4build1 500
        500 http://au.archive.ubuntu.com/ubuntu resolute/universe amd64 Packages
        100 /var/lib/dpkg/status

Install Swift upstream dependencies on Ubuntu 24.04 or 22.04

Swiftly and the official tarball both need a small set of Ubuntu development libraries. Desktop installs often already have some of them, but minimal and server images can still miss basics such as curl. The curl command guide for Linux explains the download flags used later if you want a closer breakdown.

Swift upstream dependencies on Ubuntu 24.04

Ubuntu 24.04 needs the following packages before you install Swift from Swift.org.

sudo apt install curl ca-certificates tar git gnupg2 jq libcurl4-openssl-dev libpython3-dev libxml2-dev libncurses-dev libz3-dev pkg-config zlib1g-dev

Swift upstream dependencies on Ubuntu 22.04

Ubuntu 22.04 uses the same core dependency set, plus the Jammy LLDB Python binding that Swiftly still recommends there.

sudo apt install curl ca-certificates tar git gnupg2 jq libcurl4-openssl-dev libpython3-dev libxml2-dev libncurses-dev libz3-dev pkg-config python3-lldb-13 zlib1g-dev

The package sets reflect Swiftly’s current release-specific dependency reminders: Ubuntu 24.04 asks for libncurses-dev, while Ubuntu 22.04 still asks for python3-lldb-13. Do not use the Jammy-only python3-lldb-13 package name on Noble, where it has no candidate. The jq package is used later by the tarball method to read the current Swift release tag from GitHub’s JSON API safely.

Install Swift with Swiftly on Ubuntu 24.04 or 22.04

Swiftly is Swift.org’s official toolchain manager for Linux. It keeps the toolchain in your home directory, writes an environment file to ~/.local/share/swiftly/, and makes later updates easier than a manual tarball install.

Download the latest Swiftly release from Swift.org. The versionless URL always resolves to the current bootstrap archive for your architecture.

curl -fsSLO "https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz"

Confirm the archive is in your current directory before extracting it.

ls -1 "swiftly-$(uname -m).tar.gz"
swiftly-x86_64.tar.gz

Extract the archive next. This creates a local swiftly binary in your current directory.

tar -xzf "swiftly-$(uname -m).tar.gz"

Confirm the extracted bootstrap binary is present before you run it.

test -x swiftly && echo swiftly-ready
swiftly-ready

Initialize Swiftly after that. The installer writes its environment file under ~/.local/share/swiftly/, adds a line to ~/.profile, and downloads the current Swift toolchain automatically, so expect a download of roughly 1 GiB.

./swiftly init --assume-yes
Installing swiftly in /home/joshua/.local/share/swiftly/bin/swiftly...
Fetching the latest stable Swift release...
Installing Swift 6.3.1
Swift 6.3.1 is installed successfully!

Swiftly appends an environment line to ~/.profile. Load it in the current shell and clear Bash’s command cache so the new swift path is picked up immediately.

. "$HOME/.local/share/swiftly/env.sh"
hash -r

If you open a new terminal later, Ubuntu reads ~/.profile automatically and you should not need to run that command again.

Verify both the active compiler and the installed Swiftly toolchain list.

swift --version
Swift version 6.3.1 (swift-6.3.1-RELEASE)
Target: x86_64-unknown-linux-gnu
swiftly list
Installed release toolchains
----------------------------
Swift 6.3.1 (in use) (default)

Installed snapshot toolchains
-----------------------------

You can remove the downloaded archive and extracted bootstrap binary once Swiftly is installed.

rm -f "swiftly-$(uname -m).tar.gz" swiftly

Install Swift from the official tarball on Ubuntu 24.04 or 22.04

The tarball method gives you the same upstream compiler without a version manager. This workflow stores each release in its own directory under /opt, points /opt/swift at the active version, and then exposes that path through a system-wide profile script.

Start by confirming your Ubuntu release and CPU architecture. Swift.org publishes separate tarballs for Ubuntu 24.04 and 22.04, plus separate archives for x86_64 and aarch64.

lsb_release -rs
uname -m
24.04
x86_64

Build the Swift download names next. Run the next few blocks in the same terminal session because they reuse these variables.

SWIFT_TAG=$(curl -fsSL https://api.github.com/repos/swiftlang/swift/releases/latest | jq -r '.tag_name // empty')
case "$SWIFT_TAG" in
  swift-*-RELEASE) SWIFT_VERSION=${SWIFT_TAG#swift-}; SWIFT_VERSION=${SWIFT_VERSION%-RELEASE} ;;
  *) echo "Could not find a stable Swift release tag."; exit 1 ;;
esac

UBUNTU_VERSION=$(lsb_release -rs)
ARCH=$(uname -m)

case "$UBUNTU_VERSION:$ARCH" in
  24.04:x86_64) BASE_DIR=ubuntu2404; FILE_ARCH=""; FILE_VERSION=ubuntu24.04 ;;
  24.04:aarch64) BASE_DIR=ubuntu2404-aarch64; FILE_ARCH=-aarch64; FILE_VERSION=ubuntu24.04 ;;
  22.04:x86_64) BASE_DIR=ubuntu2204; FILE_ARCH=""; FILE_VERSION=ubuntu22.04 ;;
  22.04:aarch64) BASE_DIR=ubuntu2204-aarch64; FILE_ARCH=-aarch64; FILE_VERSION=ubuntu22.04 ;;
  *) echo "Use this tarball method on Ubuntu 24.04 or 22.04 only."; exit 1 ;;
esac

TARBALL="swift-${SWIFT_VERSION}-RELEASE-${FILE_VERSION}${FILE_ARCH}.tar.gz"
BASE_URL="https://download.swift.org/swift-${SWIFT_VERSION}-release/${BASE_DIR}/swift-${SWIFT_VERSION}-RELEASE"

Print the final download URL before you fetch anything. This gives you one last chance to confirm the release and architecture match your system.

echo "$BASE_URL/$TARBALL"
https://download.swift.org/swift-6.3.1-release/ubuntu2404/swift-6.3.1-RELEASE/swift-6.3.1-RELEASE-ubuntu24.04.tar.gz

Download the archive and its detached signature from Swift.org.

curl -fsSLO "$BASE_URL/$TARBALL"
curl -fsSLO "$BASE_URL/$TARBALL.sig"

Check that both files downloaded before you import the signing keys.

ls -1 "$TARBALL" "$TARBALL.sig"
swift-6.3.1-RELEASE-ubuntu24.04.tar.gz
swift-6.3.1-RELEASE-ubuntu24.04.tar.gz.sig

The exact tarball size varies slightly by Ubuntu release and architecture, but you should see both files present before the signature step.

Import Swift’s public keys and verify the tarball before you extract it. The keys file is served compressed, so use curl --compressed for the import step.

curl --compressed -fsSL https://www.swift.org/keys/all-keys.asc | gpg --import
gpg --verify "$TARBALL.sig" "$TARBALL"
gpg: Good signature from "Swift 6.x Release Signing Key <swift-infrastructure@forums.swift.org>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!

A trust warning is normal here because the signing key is not in your personal web-of-trust. The important line is Good signature. Extract the archive into a versioned directory first, then point /opt/swift at that directory.

sudo rm -rf "/opt/swift-${SWIFT_VERSION}"
sudo mkdir -p "/opt/swift-${SWIFT_VERSION}"
sudo tar xzf "$TARBALL" -C "/opt/swift-${SWIFT_VERSION}" --strip-components=1
sudo ln -sfn "/opt/swift-${SWIFT_VERSION}" /opt/swift

Add Swift to your shell path next. The tee command writes the profile script as root because plain shell redirection would not inherit sudo.

printf '%s\n' 'export PATH=/opt/swift/usr/bin:$PATH' | sudo tee /etc/profile.d/swift.sh > /dev/null
. /etc/profile.d/swift.sh

Verify that the shell now resolves Swift from /opt/swift.

swift --version
Swift version 6.3.1 (swift-6.3.1-RELEASE)
Target: x86_64-unknown-linux-gnu
readlink -f /opt/swift
/opt/swift-6.3.1

The Swift tarball is a standard .tar.gz archive. If you want a broader refresher on that format, see our guide on how to open .gz and .tgz files in Linux.

Remove the downloaded archive and signature after the install completes.

rm -f "$TARBALL" "$TARBALL.sig"

Create a tarball update helper

The manual tarball method updates by repeating the same release lookup, signature check, extraction, and symlink switch. Create a short helper now so future tarball updates use one memorable command.

sudo tee /usr/local/bin/update-swift-tarball > /dev/null <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

if [ "$(id -u)" -ne 0 ]; then
  echo "Run this helper with sudo: sudo update-swift-tarball" >&2
  exit 1
fi

for cmd in curl jq gpg tar lsb_release uname mktemp; do
  if ! command -v "$cmd" >/dev/null 2>&1; then
    echo "Missing required command: $cmd" >&2
    exit 1
  fi
done

SWIFT_TAG=$(curl -fsSL https://api.github.com/repos/swiftlang/swift/releases/latest | jq -r 'select(.draft == false and .prerelease == false) | .tag_name // empty')
case "$SWIFT_TAG" in
  swift-*-RELEASE) SWIFT_VERSION=${SWIFT_TAG#swift-}; SWIFT_VERSION=${SWIFT_VERSION%-RELEASE} ;;
  *) echo "Could not find a stable Swift release tag." >&2; exit 1 ;;
esac

UBUNTU_VERSION=$(lsb_release -rs)
ARCH=$(uname -m)

case "$UBUNTU_VERSION:$ARCH" in
  24.04:x86_64) BASE_DIR=ubuntu2404; FILE_ARCH=""; FILE_VERSION=ubuntu24.04 ;;
  24.04:aarch64) BASE_DIR=ubuntu2404-aarch64; FILE_ARCH=-aarch64; FILE_VERSION=ubuntu24.04 ;;
  22.04:x86_64) BASE_DIR=ubuntu2204; FILE_ARCH=""; FILE_VERSION=ubuntu22.04 ;;
  22.04:aarch64) BASE_DIR=ubuntu2204-aarch64; FILE_ARCH=-aarch64; FILE_VERSION=ubuntu22.04 ;;
  *) echo "Use this helper on Ubuntu 24.04 or 22.04 only." >&2; exit 1 ;;
esac

INSTALL_DIR="/opt/swift-${SWIFT_VERSION}"
if [ -x "$INSTALL_DIR/usr/bin/swift" ] && [ "$(readlink -f /opt/swift 2>/dev/null || true)" = "$INSTALL_DIR" ]; then
  echo "Swift ${SWIFT_VERSION} is already installed at ${INSTALL_DIR}."
  "$INSTALL_DIR/usr/bin/swift" --version
  exit 0
fi

TARBALL="swift-${SWIFT_VERSION}-RELEASE-${FILE_VERSION}${FILE_ARCH}.tar.gz"
BASE_URL="https://download.swift.org/swift-${SWIFT_VERSION}-release/${BASE_DIR}/swift-${SWIFT_VERSION}-RELEASE"
CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/swift-tarball-updater"
mkdir -p "$CACHE_DIR"
cd "$CACHE_DIR"
rm -f "$TARBALL" "$TARBALL.sig"

echo "Downloading $BASE_URL/$TARBALL"
curl -fsSLO "$BASE_URL/$TARBALL"
curl -fsSLO "$BASE_URL/$TARBALL.sig"

GNUPGHOME=$(mktemp -d)
TMP_DIR="/opt/.swift-${SWIFT_VERSION}.tmp.$$"
cleanup() {
  rm -rf "$GNUPGHOME" "$TMP_DIR"
}
trap cleanup EXIT
export GNUPGHOME

curl --compressed -fsSL https://www.swift.org/keys/all-keys.asc | gpg --batch --import
gpg --batch --verify "$TARBALL.sig" "$TARBALL"

rm -rf "$TMP_DIR"
mkdir -p "$TMP_DIR"
tar xzf "$TARBALL" -C "$TMP_DIR" --strip-components=1
rm -rf "$INSTALL_DIR"
mv "$TMP_DIR" "$INSTALL_DIR"
ln -sfn "$INSTALL_DIR" /opt/swift
# shellcheck disable=SC2016
printf '%s\n' 'export PATH=/opt/swift/usr/bin:$PATH' > /etc/profile.d/swift.sh
chmod 0644 /etc/profile.d/swift.sh
rm -f "$TARBALL" "$TARBALL.sig"

echo "Swift tarball updated at $INSTALL_DIR."
"$INSTALL_DIR/usr/bin/swift" --version
EOF

Make the helper executable, then confirm Ubuntu can find it from your shell path.

sudo chmod +x /usr/local/bin/update-swift-tarball
command -v update-swift-tarball
/usr/local/bin/update-swift-tarball

Create a Swift Project on Ubuntu

Swift Package Manager is the quickest way to confirm the compiler, package tools, and linker are all working together. It also depends on Git for dependency fetches, so install or upgrade Git on Ubuntu if your system does not have it yet.

Create a small executable package and run it.

mkdir ~/HelloSwift
cd ~/HelloSwift
swift package init --name HelloSwift --type executable
swift run HelloSwift
Build of product 'HelloSwift' complete!
Hello, world!

The official Swift Package Manager getting started guide is the next place to go once you want dependencies, release builds, and a bigger project layout. If you prefer a GUI editor, install Visual Studio Code on Ubuntu and add the Swift extension from the marketplace.

Troubleshoot Swift on Ubuntu

Swiftly reports Unsupported Linux platform on Ubuntu 26.04

If you try Swiftly on Ubuntu 26.04 right now, the installer stops immediately with an unsupported platform error.

Error: Unsupported Linux platform

This happens because Swift.org has not published native Resolute toolchains yet. Use Ubuntu’s own package instead.

sudo apt install swiftlang

Verify that the compiler is available afterward.

swift --version
Swift version 6.1.3 (swift-6.1.3-RELEASE)
Target: x86_64-pc-linux-gnu

Swift is not found after the tarball install

If the tarball extracted cleanly but the shell still cannot find swift, the profile script was not loaded in the current shell yet.

bash: line 1: swift: command not found

Load the system-wide profile script now so the tarball path is added to PATH immediately.

printf '%s\n' 'export PATH=/opt/swift/usr/bin:$PATH' | sudo tee /etc/profile.d/swift.sh > /dev/null
. /etc/profile.d/swift.sh

Confirm the shell now resolves the compiler from the tarball location.

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

Update or Remove Swift on Ubuntu

Each installation path has its own maintenance workflow. Match the subsection to the method you originally used: swiftlang on Ubuntu 26.04, Swiftly on Ubuntu 24.04 or 22.04, or the manual tarball on Ubuntu 24.04 or 22.04.

Update swiftlang on Ubuntu 26.04

Choose this subsection only if you installed Swift with Ubuntu’s swiftlang package on 26.04. Ubuntu handles updates through APT, so you only need the package upgrade command.

sudo apt install --only-upgrade swiftlang

Update Swiftly on Ubuntu 24.04 or 22.04

Choose this subsection only if you installed Swift with Swiftly. Swiftly updates the active toolchain and the manager itself with separate commands.

swiftly update
swiftly self-update
Swift 6.3.1 is already up to date
Checking for swiftly updates...
Already up to date.

Update the Swift tarball on Ubuntu 24.04 or 22.04

Choose this subsection only if you installed Swift manually under /opt. The helper repeats the release lookup, signature check, extraction, profile script, and symlink update from the tarball install section.

sudo update-swift-tarball

After you refresh the tarball install, confirm which directory the symlink points to and which compiler version is active.

readlink -f /opt/swift
swift --version
/opt/swift-6.3.1
Swift version 6.3.1 (swift-6.3.1-RELEASE)
Target: x86_64-unknown-linux-gnu

Once the new toolchain is active, remove the older versioned directory if you do not need a rollback copy anymore.

sudo rm -rf /opt/swift-OLD_VERSION

Remove Swift from Ubuntu 26.04

Use this removal path only for the Ubuntu 26.04 swiftlang package. Remove the package first, then preview APT’s cleanup list before deleting auto-installed dependencies.

sudo apt remove swiftlang

Preview the automatic cleanup next. Continue only if the list is limited to Swift-related packages you no longer need, such as libswiftlang.

sudo apt autoremove --dry-run

If the preview is clean, run the real cleanup.

sudo apt autoremove

Check the installed package state after removal.

dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' swiftlang 2>/dev/null | grep '^ii' || echo swiftlang-not-installed
swiftlang-not-installed

Remove Swiftly from Ubuntu 24.04 or 22.04

Use this removal path only if you installed Swift with Swiftly. Remove all Swiftly-managed toolchains first. The --assume-yes flag skips the confirmation prompt.

swiftly uninstall all --assume-yes

Delete the manager directory and remove the profile lines Swiftly added to ~/.profile.

rm -rf ~/.local/share/swiftly
sed -i '/# Added by swiftly/d; /\.local\/share\/swiftly\/env\.sh/d' ~/.profile
hash -r

Verify the Swiftly manager is gone.

command -v swiftly || echo swiftly-not-found
swiftly-not-found

Remove the Swift tarball from Ubuntu 24.04 or 22.04

Use this removal path only for the manual tarball install under /opt. Delete the symlink, the versioned toolchain directories, the profile script, and the helper if you no longer need that install.

This cleanup permanently deletes the tarball-based Swift install under /opt. If you have multiple manual Swift versions there for testing, back up the ones you still need before you remove the whole /opt/swift-* set.

sudo rm -f /opt/swift
sudo rm -rf /opt/swift-*
sudo rm -f /etc/profile.d/swift.sh
sudo rm -f /usr/local/bin/update-swift-tarball
hash -r

Confirm the tarball install and helper are no longer on your shell path.

command -v update-swift-tarball || echo update-swift-tarball-not-found
command -v swift || echo swift-not-found
update-swift-tarball-not-found
swift-not-found

Conclusion

Swift is installed on Ubuntu Linux with the method that fits your release, whether that is swiftlang on 26.04 or Swift.org’s upstream toolchains on 24.04 and 22.04. For editor integration, install Visual Studio Code on Ubuntu. Swift Package Manager also works best when Git is ready, so install or upgrade Git on Ubuntu if it is not already available.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: