Swift is open source and runs on macOS, Linux and Windows. This guide covers running, debugging and building Swift in VS Code.
Install Swift
- •macOS: install Xcode from the App Store (includes the full Swift toolchain), or the Command Line Tools.
- •Linux: download the toolchain from swift.org/install and add it to your PATH.
- •Windows: follow the official swift.org Windows installation guide.
Verify: swift --version
VS Code
Install the Swift extension by the Swift Server Work Group. It provides IntelliSense (via SourceKit-LSP), build tasks and LLDB debugging.
Write and run
Create main.swift:
func greet(_ name: String) -> String {
"Hello, \(name)!"
}
print(greet("Ada"))Run a single file:
swift main.swiftDebug it
The Swift extension uses LLDB. Set a breakpoint, press F5, and step through your code, inspecting optionals and structs as you go.
Build a package
For anything beyond one file, use Swift Package Manager:
swift package init --type executable
swift run
swift build -c release # optimised binary in .build/release/SwiftPM manages dependencies, builds and tests — the standard way to structure Swift apps and libraries.