skip to content

On a Linux build machine, how does swiftly install and select a Swift toolchain, and what does a .swift-version file change?

level: middleimportance: should knowfreq 25%

answer

  1. a toolchain manager, not a package manager
  2. install, use and run subcommands
  3. a file at the repository top
  4. in use versus global default
  5. a plus-prefixed selector for one command

basics

~20 s

swiftly is swift.org's toolchain manager for Linux and macOS: swiftly install downloads and verifies a release, swiftly use selects one, and a .swift-version file in the repository pins the toolchain every swiftly user there gets.

solid answer

~50 s

`swiftly` installs swift.org toolchains into your account and puts proxies for `swift`, `swiftc`, `lldb` and the other toolchain commands on your `PATH`. `swiftly install 6.4` takes the newest 6.4 patch, `swiftly install latest` the newest stable release, and `--use` selects the result in the same step; signatures are PGP-verified by default. `swiftly use 6.4.0` inside a git repository offers to write a `.swift-version` file at its top, and from then on anyone working in that directory or below gets that toolchain; a bare `swiftly install` installs whatever the file names. Outside such a directory the global default from `swiftly use --global-default` applies, and `swiftly run swift build +main-snapshot` overrides the choice for one command. On CI you run `swiftly init --assume-yes --skip-install`, then `swiftly install --post-install-file=…` to capture the system packages the toolchain still needs.

code

bash · 11 lines
bash
# once per machine (Linux)
curl -L https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz > swiftly.tar.gz
tar zxf swiftly.tar.gz
./swiftly init --assume-yes --skip-install
. ~/.local/share/swiftly/env.sh

# in the repository
swiftly use 6.4.0                  # offers to write .swift-version
swiftly install                    # installs what .swift-version names
swiftly run swift test +main-snapshot   # one-off run on a snapshot
swiftly list                       # shows (in use) and (default)

go deeper

for a junior

Recall the three verbs: swiftly install fetches a toolchain, swiftly use selects it, and swift --version confirms which compiler now runs.

for a middle

Explain the selection order: a .swift-version file in the directory or a parent decides the in-use toolchain, the global default covers everything else, and a plus selector overrides one command.

for a senior

Show how you keep laptops and CI on one compiler: a committed .swift-version, an unattended init with --skip-install, a post-install script for system packages, and a snapshot job via swiftly run.

for a principal

Weigh who owns the compiler version across repositories: pinning per repository gives reproducible builds but multiplies upgrade work, so set an upgrade cadence tied to the Xcode release the app team ships.

## What swiftly is A **Swift toolchain** is the compiler (`swiftc`), the `swift` driver with the package manager, the debugger (`lldb`), the standard library and the runtime, all at one release. On a Mac, Xcode bundles one toolchain per Xcode version. On Linux there is no Xcode, so swift.org ships **swiftly**, a command-line toolchain manager. Its sources carry a Linux platform and a macOS platform; on Windows you install the toolchain with the swift.org installer or `winget install --id Swift.Toolchain`. swiftly is **not a package manager**: it never resolves your package's dependencies, and installing a newer toolchain does not change your code's **language mode** (Swift 5 or Swift 6 mode is chosen per target with `-swift-version`). It only decides which compiler binary runs when you type `swift`. ## Installing toolchains After downloading the binary, `swiftly init` installs swiftly itself, writes an environment script (for example `~/.local/share/swiftly/env.sh` on Linux) and, unless you pass `--skip-install`, the latest stable toolchain. Every install creates **proxies** in swiftly's `bin` directory, so `swift` on your `PATH` is really swiftly forwarding to the selected toolchain. | Selector | What `swiftly install` fetches | |---|---| | `latest` | the newest stable release | | `6.4` | the newest available 6.4.x patch | | `6.4.0` | exactly that release | | `main-snapshot` | the newest snapshot of the main branch | | `6.4-snapshot-2026-08-30` | the 6.4 branch snapshot from that date | | *(nothing)* | whatever is currently selected, such as the `.swift-version` file's version | - **Signatures** are checked with PGP by default (`--verify` is on; `--no-verify` skips it), which is why minimal Linux images need GPG and `ca-certificates`. - **System dependencies**, the distribution packages a toolchain still needs, are printed after installation, or written to the script named by `--post-install-file` for unattended runs. - `swiftly update` with no argument moves the in-use toolchain to the newest patch of the same major.minor (or the newest snapshot of the same branch); `swiftly update latest` may jump minors. ## Selecting a toolchain: in use versus default swiftly tracks two things, and `swiftly list` tags both: - **In use** is what runs from the current working directory. swiftly looks for a `.swift-version` file in that directory or a parent and uses the version it names. - **Default** is the global fallback, set with `swiftly use --global-default 6.4.0`, used wherever no `.swift-version` file applies. `swiftly use 6.4.0` inside a git repository offers to create or update `.swift-version` at the repository's top. Commit that file and every teammate and CI job running swiftly there builds with the same compiler. A teammate who lacks that toolchain gets an error rather than a silent fallback, and a bare `swiftly install` fixes it. `swiftly use` with no argument prints the in-use toolchain; `--print-location` prints its path. A partial version such as `swiftly use 6` picks the newest installed match. For a single command, `swiftly run` takes a selector prefixed with `+`: `swiftly run swift test +main-snapshot` tests against the snapshot without touching the file or the default (`++` escapes an argument that really starts with `+`). ## A CI recipe 1. Download the swiftly archive for the machine's architecture from swift.org and unpack it. 2. Run `./swiftly init --assume-yes --skip-install`, then source the environment script it prints. 3. Run `swiftly install --post-install-file=post-install.sh` in the repository: it installs the `.swift-version` toolchain. 4. If `post-install.sh` exists, run it with administrative rights (it installs the distribution packages the toolchain needs). 5. Build and test with plain `swift build` and `swift test`. ## Where swiftly stops - On macOS, Xcode's own toolchain is untouched: `xcrun swift` still runs Xcode's, while swiftly's toolchains live in `~/Library/Developer/Toolchains`. Cross-compiling with a Swift SDK, such as the Static Linux SDK, needs a swift.org toolchain whose version matches the SDK exactly, and swiftly is the usual way to get one. - swiftly does not install Swift SDKs; `swift sdk install` does. - The toolchain version and the language mode are independent: a `.swift-version` of 6.4.0 can still compile targets in Swift 5 mode. ## Housekeeping commands worth knowing - `swiftly list` shows installed release and snapshot toolchains with their *in use* and *default* tags; `swiftly list-available` shows what can be installed. - `swiftly uninstall main-snapshot` removes a toolchain you no longer need; snapshots add up quickly on build machines. - `swiftly self-update` updates swiftly itself, separately from any toolchain. - Behind a corporate proxy, swiftly honours the standard `https_proxy` / `HTTPS_PROXY` environment variables when it downloads the toolchain list and archives from swift.org.

  • A teammate clones the repository, runs swift build and gets an error about a missing toolchain. What happened?
    The repository's `.swift-version` file names a toolchain that is not installed on their machine, and swiftly reports that rather than silently falling back to the global default. Running a bare `swiftly install` in the repository installs exactly the version the file names, after which `swift build` uses it.
  • Does pinning 6.4.0 in .swift-version move the package to Swift 6 language mode?
    No. The file selects which compiler binary runs; the language mode is a per-target compiler setting (`-swift-version 5` or `-swift-version 6`). A Swift 6.4 compiler builds Swift 5-mode targets unchanged, so upgrading the pinned toolchain and migrating to Swift 6 mode are separate steps.
  • How do you run your tests against the next release's snapshot without changing anyone's setup?
    Install the snapshot with `swiftly install main-snapshot` (or a release-branch selector such as `6.4-snapshot`), then run `swiftly run swift test +main-snapshot`. The `+` selector applies only to that command; the `.swift-version` file and the global default stay as they were.

  • Says swiftly resolves package dependencies like a package manager.
  • Believes a newer pinned toolchain switches the code to Swift 6 language mode.
  • Thinks swiftly use switches the toolchain Xcode builds with.
  • Assumes swiftly install 6.4 installs exactly 6.4.0.
  • Installs whatever toolchain the CI image ships instead of the pinned version.