Small exercises to learn Swift, in the style of Rustlings, that run with the open-source Swift toolchain on Linux with no Mac or Xcode required. The exercises teach Swift the language, so the "-linux" is about the toolchain and runner, not Linux-specific content. You fix one broken file at a time; the runner recompiles it on save and moves you forward when it passes. Each exercise links to the matching chapter of The Swift Programming Language.
This is a fork of Swiftlings by Tornike Gomareli, which assumes macOS and Xcode. The exercises and the runner come from there. What this fork adds is making the whole thing build and run on Linux.
Swift is not only for Apple platforms, and most people who reach for it on Linux are not writing iOS apps. Common reasons:
- Server-side Swift. Frameworks like Vapor and Hummingbird run on Linux. If you write Swift backends, they are built, tested, and deployed on Linux, usually inside containers.
- Contributing to Swift itself. The compiler, standard library, Foundation, and the package manager are all developed and tested on Linux. Learning the language on Linux is a natural first step toward working on the toolchain.
- No Mac needed. Swift is worth learning on its own, and you do not need Apple hardware to do it. Students and anyone on a Linux machine can start here.
- CI/CD. Swift continuous integration runs in Linux containers (the official
swiftDocker images). Knowing the Linux toolchain helps when a build behaves differently from a Mac. - Cross-platform reach. Swift targets Linux, Windows, and embedded systems. Learning it outside Xcode keeps the focus on the language rather than the IDE.
- Swift 6.x, installed from swift.org
Check your toolchain:
swift --versiongit clone https://github.com/lucasly-ba/swiftlings-linux.git
cd swiftlings-linux
make install
swiftlingsmake install builds a release binary and puts swiftlings in ~/.local/bin,
so make sure that is on your PATH. Then swiftlings starts the watcher. If you
would rather not install anything, run it straight from the repo with
swift run swiftlings.
Open the first unsolved exercise. It has a // TODO and a compiler or logic
error. Fix it and save. In watch mode the runner recompiles and reruns the file
automatically. An exercise is solved once it compiles and all of its checks pass,
and you move on to the next one.
While watching, the runner reads these keys:
| Key | What it does |
|---|---|
n |
Move on to the next exercise once it passes |
h |
Show a hint |
l |
List every exercise and your progress |
c |
Check all exercises |
x |
Reset the current exercise to its starting state |
q |
Quit |
The exercises go from the basics to the deeper parts of the language:
00_basics01_control_flow02_strings_and_characters03_collections04_functions05_closures06_optionals07_structs08_classes09_initialization10_enums11_properties12_protocols13_extensions14_generics15_error_handling16_memory_management17_codable18_property_wrappers19_concurrency20_result_builders21_advanced_types
Each topic folder has a README.md with a short explanation and links to the
official docs.
After the numbered topics there is dsa_queue, a small data-structures track
that builds a FIFO queue from scratch, from a basic struct up to Collection
conformance. It is not part of the numbered language curriculum.
- Swiftlings by Tornike Gomareli: the original Swift runner and exercises this is built on (MIT).
- Rustlings: the Rust project that started the idea (MIT).
MIT. See LICENSE.
