Installing Swift & Xcode Setup
Install Swift via Xcode on macOS or the standalone toolchain on Linux/Windows, verify your installation, and set up a comfortable editor.
Introduction
Before writing real Swift code, you need the Swift toolchain available on your machine. On a Mac, the simplest route is installing Xcode, which bundles everything you need. On Linux and Windows, you install the standalone Swift toolchain directly from swift.org.
This lesson walks through installing Swift on macOS via Xcode, installing the standalone toolchain elsewhere, verifying the install, and setting up an editor for a comfortable workflow.
Installing on macOS via Xcode
On macOS, the recommended way to get Swift is to install Xcode, Apple's full IDE, from the Mac App Store. Xcode bundles the Swift compiler, debugger, Interface Builder, SwiftUI previews, and the iOS/macOS/watchOS/tvOS simulators — everything you need to build real apps, not just scripts.
- Open the Mac App Store and search for "Xcode," then click Get / Install.
- Once installed, open Xcode at least once and accept the license agreement so it can install additional components.
- Open Terminal and run `xcode-select --install` if you also want the standalone command line developer tools.
- Xcode automatically keeps the Swift compiler on your PATH — no manual configuration needed.
Swift Playgrounds
Xcode includes Playgrounds — interactive scratchpad files that show the result of every line as you type, ideal for experimenting with syntax without creating a full project. To create one, open Xcode, choose File → New → Playground, pick a blank macOS playground, and start typing Swift code.
Verifying Your Installation
Whichever platform you're on, once installed, verify Swift is available by checking its version in a terminal.
swift --versionClick Run to see what this code prints.
You should see a version number and target platform. If you instead see "command not found," Swift isn't on your PATH yet — on macOS, make sure Xcode has finished installing; on Linux/Windows, double-check the PATH steps from the installer.
Installing on Linux & Windows
On Linux and Windows, Swift is not bundled with anything else — you download the standalone toolchain directly from swift.org/install.
# Linux (Ubuntu example) — download and extract the toolchaintar xzf swift-5.10-RELEASE-ubuntu22.04.tar.gzexport PATH=$PWD/swift-5.10-RELEASE-ubuntu22.04/usr/bin:"${PATH}"
# Then verifyswift --versionOn Windows, swift.org provides a standard .exe installer that sets up the toolchain and adds it to your PATH automatically. After installing, open a new terminal window and run the same `swift --version` check.
Managing Toolchains with Swiftly
Swiftly is the official Swift toolchain installer and version manager, similar in spirit to `nvm` for Node.js. It lets you install, switch between, and update multiple Swift versions without manually managing PATH entries yourself.
# Install swiftly, then use it to install and select a Swift toolchainswiftly install latestswiftly use latestThe Swift REPL
Every Swift install includes an interactive REPL (Read-Eval-Print Loop) for trying out expressions one line at a time, similar to Python's interactive shell. Run `swift` with no arguments in a terminal to launch it.
swift1> let greeting = "Hello from the REPL"2> print(greeting)Hello from the REPLEditor Setup
For building full iOS, macOS, watchOS, or tvOS apps, Xcode remains the primary tool — it's the only way to get Interface Builder, live SwiftUI previews, and the simulators. For writing plain Swift scripts, server-side Swift, or cross-platform code on Linux/Windows, Visual Studio Code with the official Swift extension (which uses `sourcekit-lsp` under the hood) provides autocompletion, inline errors, and debugging.
- macOS app/iOS development: use Xcode, downloaded from the Mac App Store.
- Cross-platform or server-side scripts: install VS Code, then add the official "Swift" extension from the Extensions panel.
- Either way, confirm `swift --version` works in your terminal before opening your editor.
Common Mistakes
- Trying to build a full iOS app with UIKit or SwiftUI previews on Linux/Windows — those frameworks are Apple-platform only; the standard library and Foundation work everywhere.
- Forgetting to open Xcode at least once after installing, which is required to finish installing supporting components.
- Downloading Swift toolchains from unofficial third-party sites instead of the official swift.org/install page.
- Assuming an old terminal window will see a freshly updated PATH — open a new terminal after installation.
Best Practices
- Keep Xcode updated through the Mac App Store to get the latest Swift compiler and SDK improvements.
- Use Playgrounds for quick syntax experiments before committing code to a full project.
- On Linux/Windows, consider Swiftly so switching between Swift versions doesn't require manual PATH surgery.
- Bookmark swift.org/documentation for official setup and troubleshooting guides.
Frequently Asked Questions
Not for learning the core language — the standard library and Foundation work fine on Linux and Windows. Building and shipping real iOS or macOS apps, however, requires Xcode on a Mac.
Yes. Xcode is free on the Mac App Store, and the standalone toolchain on swift.org is free and open source for every platform.
Swift is the programming language and its compiler; Xcode is Apple's full IDE that bundles the Swift toolchain along with Interface Builder, simulators, and debugging tools.
Key Takeaways
- On macOS, install Xcode from the Mac App Store to get the full Swift toolchain plus app-building tools.
- On Linux and Windows, install the standalone toolchain from swift.org/install.
- Verify any install with `swift --version` in a fresh terminal window.
- Playgrounds and the `swift` REPL are both great ways to experiment before writing full programs.
Summary
You now have Swift installed and verified, whichever platform you're on, and know how to experiment quickly with Playgrounds or the REPL. Next, you'll dive into variables, constants, and Swift's core data types.