How to Install Swift on Arch Linux

This guide walks you through installing Swift on Arch Linux. Swift is Apple’s open-source programming language that has grown beyond iOS and macOS development into server-side applications, CLI tools, and cross-platform development. On Arch Linux, you can install Swift through AUR packages that provide pre-built binaries or the official swiftly toolchain manager for managing multiple Swift versions.

Swift offers modern language features including type safety, optionals, protocol-oriented programming, and memory safety without garbage collection. For Arch Linux users, this means you can build server-side applications with frameworks like Vapor, create command-line utilities, or contribute to Swift open-source projects, all from your Linux workstation.

Choose Your Swift Installation Method for Arch Linux

Swift is not available in the official Arch Linux repositories because Apple does not provide official packages for Arch Linux and the distribution’s packaging policies require compilation from source for official repository inclusion. However, the AUR (Arch User Repository) offers two practical approaches: pre-built binary packages and the swiftly toolchain manager.

MethodChannelVersionUpdatesBest For
swift-bin (AUR)AUR PackageLatest stableManual via AUR helperMost users who want a simple system-wide installation
swiftly-bin (AUR)AUR PackageMultiple versionsVia swiftly self-updateDevelopers who need multiple Swift versions or snapshots

For most users, swift-bin is recommended because it provides a straightforward system-wide installation that integrates with your package manager. Choose swiftly-bin if you need to switch between multiple Swift versions, test against snapshot releases, or keep Swift toolchains separate from your system packages.

Install Swift on Arch Linux

Prerequisites

Both installation methods require an AUR helper. If you don’t have one installed, you’ll need to install base-devel and git first, then follow the Arch Wiki AUR helpers guide to install yay or paru.

Update your system before installing Swift:

sudo pacman -Syu

Install via swift-bin (AUR Binary Package)

The swift-bin package provides pre-built Swift binaries repackaged from official RHEL 9 releases. This installs Swift system-wide to /usr/lib/swift/ with symlinks in /usr/bin/, making the swift command available without any PATH configuration.

Install swift-bin using yay:

yay -S swift-bin

Or using paru:

paru -S swift-bin

The package manager automatically pulls in required dependencies including libxml2-legacy (provides the older ABI that Swift binaries need), ncurses, and util-linux-libs.

Verify your installation:

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

Install via swiftly (Toolchain Manager)

Swiftly is Swift’s official toolchain manager, allowing you to install, switch between, and manage multiple Swift versions including nightly snapshots. This approach installs toolchains to ~/.local/share/swiftly/ rather than system-wide, keeping Swift separate from your system packages.

Install swiftly-bin from the AUR:

yay -S swiftly-bin

Initialize swiftly with the UBI9 platform (RHEL 9 binaries are compatible with Arch Linux):

swiftly init --assume-yes --platform ubi9
Creating shell environment file for the user...
Updating profile...
Fetching the latest stable Swift release...
Installing Swift 6.2.3
Downloading Swift 6.2.3
...
Swift 6.2.3 is installed successfully!

Arch Linux is not officially supported by Swift, so swiftly uses RHEL 9 (UBI9) binaries which are compatible with Arch’s glibc version. The --platform ubi9 flag is required to skip the interactive platform selection.

Reload your shell configuration to add swiftly to your PATH:

source ~/.bashrc

Verify the installation:

swiftly list
Installed release toolchains
----------------------------
Swift 6.2.3 (in use) (default)

Installed snapshot toolchains
-----------------------------
swift --version
Swift version 6.2.3 (swift-6.2.3-RELEASE)
Target: x86_64-unknown-linux-gnu

Manage Swift Versions with Swiftly

If you installed Swift via swiftly, you can easily manage multiple toolchain versions. This is useful for testing your code against different Swift releases or trying snapshot builds with upcoming features.

Install Additional Toolchains

Install a specific Swift version:

swiftly install 6.0.3

Install the latest nightly snapshot from the main development branch:

swiftly install main-snapshot

Switch Between Toolchains

Set a different toolchain as the default:

swiftly use 6.1.2

Run a single command with a specific toolchain without changing your default:

swiftly run --toolchain main-snapshot swift --version

List Available Toolchains

View toolchains available for installation:

swiftly list-available
Available release toolchains
----------------------------
Swift 6.2.3
Swift 6.2.2
Swift 6.2.1
Swift 6.2
Swift 6.1.2
Swift 6.1.1
...

Update Swiftly

Keep swiftly itself up to date:

swiftly self-update
Checking for swiftly updates...
Swiftly is already up to date (1.1.1)

Verify Swift Installation

Create a test project to confirm Swift and the Swift Package Manager work correctly. This creates a minimal executable package with a hello world entry point:

mkdir ~/swift-test && cd ~/swift-test
swift package init --name swift-test --type executable

This generates the basic Swift package structure:

.
├── Package.swift
└── Sources
    └── main.swift

Build and run the test project:

swift run swift-test
Building for debugging...
[3/3] Linking swift-test
Build complete! (0.68s)
Hello, world!

Clean up the test project after verification:

cd ~ && rm -rf ~/swift-test

Configure Swift Development Environment

Set Up VS Code for Swift Development

Visual Studio Code with the Swift extension provides code completion, inline error diagnostics, jump-to-definition, and debugging support. Install VS Code from the AUR:

yay -S visual-studio-code-bin

Open VS Code and install the Swift extension from the Extensions marketplace (search for “Swift” by Swift Language Team). The extension integrates with SourceKit-LSP, which Swift provides for language server features.

Enable Swift REPL

The Swift REPL (Read-Eval-Print Loop) requires Python 3.9 for the LLDB debugger integration. If you want to use swift repl for interactive Swift sessions, install Python 3.9 from the AUR:

yay -S python39

Start an interactive Swift session:

swift repl
Welcome to Swift version 6.2.3 (swift-6.2.3-RELEASE).
Type :help for assistance.
  1> 1 + 1
$R0: Int = 2
  2> :quit

The REPL is optional. You can compile and run Swift programs without it. If you encounter libpython3.9.so.1.0: cannot open shared object file when running swift repl, install the python39 AUR package.

Troubleshooting Swift on Arch Linux

libxml2 Library Errors

If you see libxml2.so.2: cannot open shared object file when running Swift commands, install the legacy libxml2 compatibility package. This is usually installed automatically as a dependency, but may be missing if you upgraded from an older installation:

sudo pacman -S libxml2-legacy

This provides the older libxml2 ABI that the pre-built Swift binaries were linked against.

Swiftly Configuration Not Found

If swiftly commands fail with Could not load swiftly's configuration file, run the initialization command:

swiftly init --assume-yes --platform ubi9

Swift Not Found After Installation

If you installed via swiftly and swift is not found, swiftly’s bin directory may not be in your PATH yet. Reload your shell configuration to pick up the new environment variables:

source ~/.bashrc

Or for Zsh users:

source ~/.zshrc

If the problem persists, check that swiftly added its environment configuration to your shell profile:

cat ~/.bashrc | grep swiftly

Package Conflict Between swift-bin and swiftly-bin

The swift-bin and swiftly-bin packages conflict because both provide swift-language. You can only have one installed at a time. If you want to switch methods, remove the current package first:

sudo pacman -Rns swift-bin

Or:

sudo pacman -Rns swiftly-bin

Update or Remove Swift

Update Swift

For swift-bin installations, update through your AUR helper:

yay -Syu swift-bin

For swiftly installations, install the latest toolchain:

swiftly install latest
swiftly use latest

Remove Swift

Remove swift-bin and its dependencies:

sudo pacman -Rns swift-bin

The -Rns flags remove the package, its dependencies that aren’t needed by other packages, and saved config files.

Remove swiftly and all managed toolchains:

swiftly self-uninstall
sudo pacman -Rns swiftly-bin

The swiftly self-uninstall command removes all installed toolchains and swiftly’s configuration from your home directory. Run this before removing the swiftly-bin package to ensure complete cleanup.

Frequently Asked Questions

Is Swift officially supported on Arch Linux?

No. Apple does not provide official Swift packages for Arch Linux. The AUR packages use RHEL 9 binaries which are compatible with Arch Linux’s glibc version. This works reliably for most Swift development but is not an officially supported configuration.

What is the difference between swift-bin and swiftly-bin?

swift-bin installs a single Swift version system-wide, managed by pacman. swiftly-bin installs the swiftly toolchain manager which lets you install multiple Swift versions to your home directory and switch between them. Use swift-bin for simple installations; use swiftly-bin if you need to test against multiple Swift versions.

Why does the Swift REPL require Python 3.9?

The Swift REPL uses LLDB for its interactive debugger functionality, and LLDB is compiled with Python 3.9 support in the binary releases. The python39 AUR package provides the required libpython3.9.so library. This is only needed for the REPL; compiling and running Swift programs works without Python.

Can I compile Swift from source on Arch Linux?

The swift-language AUR package provides a from-source build, but it requires an existing Swift compiler (bootstrapping) and the build process is resource-intensive, taking several hours even on powerful hardware. For most users, the binary packages are more practical.

Why does swiftly require the ubi9 platform flag?

Swiftly does not recognize Arch Linux as a supported platform, so you must specify ubi9 (RHEL 9) manually. The RHEL 9 binaries are compatible with Arch Linux because both use similar glibc versions. Without this flag, swiftly prompts for platform selection interactively.

Conclusion

You now have Swift installed on Arch Linux with a working development environment, including package management via SwiftPM and optional VS Code integration. From here, explore server-side frameworks like Vapor, build command-line tools, or contribute to Swift’s open-source ecosystem. For production projects, consider using swiftly to test your code against multiple Swift versions before releasing.

Additional Resources

Leave a Comment

Let us know you are human: