For years, mentioning Swift in a programming conversation was synonymous with a closed ecosystem: Mac, Xcode,iOS, and Apple’s famous “walled garden.” If you were a Windows user, Swift was that unreachable language, reserved only for those who owned hardware with the bitten apple logo.
But that has changed drastically.
Today, Swift is a robust, mature, and—most importantly—cross-platform open-source language. Thanks to a monumental effort by the Swift Core Team and the community (including strong support from developers at Microsoft and The Browser Company), Swift on Windows is no longer a curious experiment: it is a functional reality.
In this comprehensive tutorial, you won’t just learn how to install the compiler. We will guide you step-by-step to set up a professional development environment on Windows 10 or 11, configure Visual Studio Code as your IDE, and compile your first project.
Part 1: Why Swift on Windows?
Before opening the terminal, it is vital to understand the context. If Swift does not support SwiftUI on Windows (as is the case), why install it?
- Swift on the Server (Backend): Frameworks like Vapor allow you to build incredibly fast and secure backends using Swift. You can develop your backend on Windows and deploy it to Linux (Docker).
- Cross-Platform Development: With business logic written in pure Swift, you can share code between an iOS app and a command-line tool on Windows.
- Performance and Safety: Swift offers memory safety and performance close to C++, making it ideal for system tools.
- The New Wave of Apps: Browsers like Arc are proving that Swift can be used to build the logic for modern,native Windows applications.
Part 2: Preparing the Ground (Prerequisites)
Swift on Windows does not work in isolation; it needs to link with system libraries. Unlike Python or Node.js, Swift is a compiled language that requires low-level build tools.
1. The Operating System
Make sure you are running Windows 10 (version 1809 or higher) or Windows 11. It is highly recommended to have your system fully updated via Windows Update.
2. Visual Studio Build Tools (Crucial)
This is the step where 80% of beginners fail. Swift needs the linker and Microsoft’s C++ runtime libraries. You do not need to install the entire Visual Studio IDE (which is very heavy), just the build tools.
- Download the Visual Studio Community or Build Tools for Visual Studio installer from the official Microsoft website.
- Run the installer.
- In the “Workloads” tab, select “Desktop development with C++”.
- On the right sidebar, ensure the following are checked:
- MSVC v143 – VS 2022 C++ x64/x86 build tools.
- Windows 10 (or 11) SDK.
- Click Install. This may take a few minutes and will require about 6-8 GB of space.
Important Note: Once this installation is complete, restart your computer. Swift will not find the libraries if the environment variables are not updated after the reboot.
Part 3: Installing the Swift Toolchain
There are two ways to install Swift: the modern way (via terminal) and the classic way (via web installer).
Method A: Using Winget (Recommended)
The Windows Package Manager (winget) is the cleanest way to do this, as it facilitates future updates.
- Open PowerShell or Windows Terminal as Administrator.
2. Type the following command and press Enter:
winget install Swift.Toolchain- The system will download and install the latest official stable version.
- Once finished, close and reopen the terminal to refresh the paths.
Method B: Manual Installation
If you prefer to control the file yourself:
- Go to Swift.org/download.
- Look for the Windows 10/11 section.
- Download the
.exeinstaller (usually namedswift-<version>-windows10.exe). - Run the installer and follow the instructions. Accept the default installation path.
Verifying the Installation
To know if everything went well:
- Open a new Terminal window (PowerShell or CMD).
- Run:
swift --versionYou should see something similar to: Swift version 6.0 (swift-6.0-RELEASE) Target: x86_64-unknown-windows-msvc-env
If you see this message, congratulations! The compiler is alive.
Part 4: Configuring the IDE (Visual Studio Code)
Although you could write code in Notepad, to work seriously we need an IDE. Visual Studio Code (VS Code) is the gold standard for Swift outside the Apple ecosystem.
1. Install VS Code
If you don’t have it, download it from code.visualstudio.com.
2. The Official Swift Extension
Apple maintains an official extension that offers autocomplete, code navigation, and package management.
- Open VS Code.
- Go to the Extensions tab (Ctrl+Shift+X).
- Search for “Swift”.
- Install the extension created by The Swift Server Workgroup (SSWG) or Swift.
3. Configure the Debugger
To be able to pause code execution and inspect variables, we need CodeLLDB.
- In extensions, search for CodeLLDB.
- Install it (created by Vadim Chugunov).
- The Swift extension will automatically detect CodeLLDB and configure it for you.
Part 5: Your First “Hello World” Project (Pro Level)
We are not going to make a simple hello.swift file. We are going to create a complete Swift Package. This teaches you how real projects are structured with the Swift Package Manager (SPM).
1. Create the directory
Open your terminal and create a folder for your projects:
mkdir SwiftProjects
cd SwiftProjects
mkdir HelloWindows
cd HelloWindows2. Initialize the package
Run the magic SPM command:
swift package init --type executableThis will generate the professional folder structure:
Package.swift: The project manifest (where you define dependencies).Sources/: Where your code lives.Tests/: For your unit tests.
3. Run the project
Without leaving the terminal, type:
swift runThe first time will take a moment because it is compiling and linking. Finally, you will see in the console: Hello, World!
4. Editing in VS Code
Now, open that folder in VS Code:
code .In the file explorer, go to Sources/main.swift. You will see the source code. Change it to:
import Foundation
print("Hello from Windows!")
print("The current date is: \(Date())")Save and run swift run again in the integrated VS Code terminal (Ctrl+`).
Part 6: Understanding the Ecosystem (REPL and SPM)
Now that you have the basics, let’s dive into two powerful tools you have installed.
The REPL (Read-Eval-Print Loop)
Swift includes an interactive console, similar to Python’s. It is useful for testing quick ideas without creating files.
- In your terminal, simply type
swiftand hit Enter. - You will see a welcome cursor
Welcome to Swift. - Type code directly:
1> var message = "Swift is great"
2> print(message.uppercased())To exit, type :quit.
Swift Package Manager (SPM)
SPM is the native dependency manager. If you come from JS, it’s the equivalent of npm. If you come from Python, it’s pip.
On Windows, SPM is vital. If you want to use a third-party library (for example, a library to parse JSON or connect to a database), you add it to your Package.swift file.
Example: If you wanted to use Apple’s swift-argument-parser library to build complex command-line tools, you would add its repository URL to the dependencies section of your Package.swift, and VS Code will download the code automatically.
Part 7: Troubleshooting Common Issues
On Windows, things can get complicated due to paths and permissions. Here are the most common errors:
Error: “The term ‘swift’ is not recognized…”
- Cause: Environment variables (PATH) were not updated.
- Solution: Restart your PC. If it persists, search for “Edit the system environment variables” in Windows, and make sure the path to the Swift
usr/binfolder is added to thePath.
Error: “LINK : fatal error LNK1104: cannot open file…”
- Cause: Conflict with Visual Studio versions or missing Windows SDK.
- Solution: Open the Visual Studio Installer, select “Modify,” and verify that the Windows 10/11 SDK is checked. Sometimes, simply repairing the Visual Studio installation fixes this.
Error: “Unable to load standard library for target…”
- Cause: Your Swift installation does not match your system architecture (you installed x86 on an x64 system or vice versa, although this is rare nowadays).
- Solution: Reinstall the Toolchain, ensuring you use the correct version.
Part 8: The Future and Next Steps
You have successfully installed Swift on Windows. What’s next?
The Swift on Windows ecosystem is expanding rapidly. Although you cannot use SwiftUI (as we clarified at the start), you have access to powerful tools:
- Explore Vapor: Try creating your first REST API. Vapor’s documentation is excellent and works very well on Windows.
- Swift 6: Swift version 6 brings massive improvements in Concurrency, eliminating race conditions in your programs. It is a great time to learn Swift’s
async/awaitmodel. - Contribute: Being Open Source, you can report bugs you find on Windows in the official Swift.org forums.
Conclusion
Installing Swift on Windows is no longer an odyssey reserved for hackers. It is a standardized process that opens the doors to one of the most modern, safe, and enjoyable languages to write in the world. You no longer need a Mac to learn the syntax or develop the logic for the next big application.
The barrier to entry has fallen. Now it’s your turn to write the code.
If you have any questions about this article, please contact me and I will be happy to help you 🙂. You can contact me on my X profile or on my Instagram profile.