How to Install Swift on Ubuntu 26.04 and 24.04

Share

To install Swift on Ubuntu 26.04 or 24.04, use Swiftly, the official toolchain manager. Swift is a programming language for command-line tools, servers and other software.

This guide installs Swift, builds a first program, and explains updates, troubleshooting and removal. If you need help, leave a comment or contact us.

Before you begin
  • Ubuntu 26.04 or 24.04 on x86_64 or aarch64, internet access and several gigabytes of free space.
  • A normal user account with sudo access for system dependencies. The commands use Bash, Ubuntu’s default shell.
  • Check existing Swift installations first. Swiftly changes your shell configuration and selects a toolchain for your user.

1. Check Your System

Step 1: Check your release and processor

Open Terminal and run:

Terminal
cat /etc/os-release

uname -m

command -v swift || true

Confirm Ubuntu 26.04 or 24.04 and x86_64 or aarch64. If a Swift path appears, check its source before changing your setup.

The Ubuntu package named swift refers to OpenStack object storage, not the Swift programming language.

2. Install Swift with Swiftly

Step 1: Install download tools

Refresh the package list and install the prerequisites. Review package changes before accepting them:

Terminal
sudo apt update

sudo apt install curl ca-certificates gnupg tar

If APT reports an error, resolve it before continuing.

Step 2: Download Swiftly

Create a new temporary directory. If it already exists, choose another name so the extracted executable cannot overwrite an existing file:

Terminal
mkdir "$HOME/swiftly-setup" && cd "$HOME/swiftly-setup"

Download the archive for your architecture:

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

Before extracting the archive, verify its signature. Download the matching signature and the Swift project’s automatic signing key:

Terminal
curl -fL -O "https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz.sig"
curl -fL -O https://www.swift.org/keys/automatic-signing-key-4.asc

Stop if either download fails. Inspect the key fingerprint:

Terminal
gpg --show-keys --fingerprint automatic-signing-key-4.asc

Compare it with Swift.org’s active signing keys. The fingerprint for Swift Automatic Signing Key #4 is E813 C892 820A 6FA1 3755 B268 F167 DF1A CF9C E069. If it differs, stop and investigate rather than importing it. Import the verified key and check the archive:

Terminal
gpg --import automatic-signing-key-4.asc
gpg --verify "swiftly-$(uname -m).tar.gz.sig" "swiftly-$(uname -m).tar.gz"

A good signature from the expected key confirms that the archive matches the signature. GPG may also warn that the key is not certified by a trusted signature; that is why you compare the fingerprint separately. If verification fails or the signing key differs, do not extract or run the archive. Check the official Swiftly instructions for changes.

Step 3: Install the toolchain

Extract the archive and start the interactive installer as your normal user, without sudo:

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

./swiftly init

Read the prompts. Swiftly installs itself and downloads a Swift toolchain. It may list additional system packages or a follow-up command: follow its instructions before continuing. The download can take time.

Step 4: Load the environment and check Swift

For the default Bash setup, load Swiftly in this terminal and clear Bash’s remembered command paths:

Terminal
. "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh"

hash -r

swift --version

swiftly list

The first command uses Swiftly’s configured home if you set one. A successful version check prints a Swift version and target. If the installer printed different shell instructions, follow those instead. Open a new terminal to check that your profile loads Swiftly automatically.

3. Build Your First Swift Program

Step 1: Create a project

Choose a new directory name. If the directory exists, choose another name before running the next command.

Terminal
mkdir "$HOME/MySwiftCLI" && cd "$HOME/MySwiftCLI"
Terminal
swift package init --name MySwiftCLI --type executable

Swift Package Manager creates the source files and package manifest.

Step 2: Build and run

Compile and run the generated executable:

Terminal
swift run MySwiftCLI

The first run builds the project and prints a greeting. The build messages and time vary, but the final line normally looks like this:

Hello, world!

Later runs rebuild changed files. To build without running, use swift build.

Find the generated Swift source file from the project directory:

Terminal
find Sources -type f -name '*.swift'

The filename and directory can differ between Swift versions. Open the file listed in Sources in a text editor. Find the existing print statement and change only its text to Hello from Ubuntu!; leave any surrounding function and braces in place. Save the file, then run the program again:

Terminal
swift run MySwiftCLI

The final line should now read Hello from Ubuntu!.

On Linux you can build Swift command-line and server applications. Apple’s Xcode and Apple platform SDKs are separate requirements for building iOS applications.

Use Swift in Visual Studio Code

After installing Visual Studio Code on Ubuntu, open its Extensions view with Ctrl+Shift+X, search for the official Swift extension, and install it. The extension adds code completion, navigation, build tasks and debugging support for Swift projects.

In VS Code, choose File > Open Folder and select your MySwiftCLI folder containing Package.swift. Open the generated source file under Sources to edit it. If the extension cannot find the toolchain, start VS Code from a terminal where swift --version works or select a toolchain using its Swift: Select Toolchain command.

4. Update Swift

Swiftly manages the toolchains it installed. Check the active toolchain first:

Terminal
swift --version

swiftly list

Update the selected stable toolchain to the latest patch in its current major and minor series:

Terminal
swiftly update

To move the latest installed stable toolchain to the newest available release, which can change major or minor versions, use swiftly update latest. Check project compatibility first. Update the manager itself with swiftly self-update.

5. Troubleshooting

Issue 1: Swift is not found or the wrong version runs

Check what Bash resolves:

Terminal
type -a swift

echo "$PATH"

If no Swift command is found, first check that the installer completed and the environment file exists:

Terminal
ls -l "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh"

If the file exists, load it using Step 4 above, run hash -r, and retry swift --version. If it is missing, review the installer output and rerun ./swiftly init from the setup directory; do not guess a replacement PATH. Open a new terminal to check your profile. An older installation earlier in PATH, or a project-specific .swift-version file, can select a different toolchain. Do not delete an existing installation until you know what uses it.

Issue 2: Missing libraries or a failed download

A missing shared library message names the library the program could not load. Note the full error and follow the dependency instructions printed by Swiftly for your Ubuntu release. If APT cannot find a requested package, check the release and enabled repositories before retrying. Avoid replacing system libraries by hand.

For a failed or interrupted download, check available space and the connection:

Terminal
df -h "$HOME"
curl -I https://www.swift.org/

A response from Swift.org shows that this HTTPS request reached the site; it does not prove that every download endpoint is available. Check the reported error, proxy and system clock. Once the problem is fixed, retry the failed download or initialization step. Never disable certificate or signature verification to bypass an error.

6. Remove Swift

Step 1: Review installed toolchains

List the toolchains managed by Swiftly:

Terminal
swiftly list

To remove one, use its exact version from the list with swiftly uninstall VERSION. This removes that toolchain, so check that your projects no longer need it. To remove every toolchain managed by Swiftly, run the following before removing the manager:

Terminal
swiftly uninstall all

Review the prompt before confirming. This affects all Swiftly-managed toolchains, including versions used by other projects. Your personal project files are separate and do not need to be deleted.

Step 2: Remove the manager

For current Swiftly releases, remove the manager with the following command. Read the prompts carefully:

Terminal
swiftly self-uninstall

The manager and its toolchains are separate: remove any unwanted Swiftly-managed toolchains first. Review any Swiftly-added shell profile entries afterwards. Keep project directories and files you still need. Swift installed by APT or another manager is separate and must be removed using its own method.

Frequently Asked Questions

Does Swift work on Ubuntu 26.04 and 24.04?

Yes. Swiftly supports both releases on supported 64-bit Intel/AMD and ARM systems. Check Swift.org for current toolchain availability.

Is Swift the same as the Ubuntu swift package?

No. The Ubuntu package named swift belongs to OpenStack object storage. Swiftly installs the programming language toolchain.

Can I use Swift to build iPhone apps on Ubuntu?

You can write portable Swift code on Ubuntu, but building Apple platform applications requires Apple platform SDKs and tools, including Xcode on macOS.

Does Swiftly require sudo for every Swift command?

No. Swiftly and its toolchains are installed for your user. Installing missing Ubuntu system dependencies can require sudo.

Will removing Swiftly delete my project?

Your project files are separate from Swiftly toolchains. Review the removal prompts and keep your project directories and backups.

Helpful resources: Swift installation and Swiftly documentation.

Related Ubuntu guides: Install curl · Install Node.js.