Windows Installation Options
Dependencies
Swift has the following general dependencies:
- Git (used by Swift Package Manager)
- Python1 (used by the debugger - LLDB)
Swift on Windows has the following additional platform specific dependencies:
- Windows SDK (provides the Windows headers and import libraries)
- Visual Studio (provides the Visual C++ SDK/Build Tools for additional headers)
Developer Mode
In order to develop applications, particularly with the Swift Package Manager, you will need to enable developer mode. Please see Microsoft’s documentation for instructions about how to enable developer mode.
Installation via Windows Package Manager
Windows Package Manager (aka WinGet) comes pre-installed with Windows 11 (21H2 and later). It can also be found in the Microsoft Store or be installed directly.
-
Install required dependencies:
winget install --id Git.Git -e winget install --id Python.Python.3.9 -e winget install --id Microsoft.VisualStudio.2022.Community --exact --force --custom "--add Microsoft.VisualStudio.Component.Windows11SDK.22000 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
Start up a new command-line shell (eg. Command Prompt, Windows PowerShell) and install the Python library
six
.pip install six
-
Install Swift:
winget install --id Swift.Toolchain -e
Installation via Scoop
Scoop is a command-line installer for Windows. It can be installed through the following PowerShell commands.
# Optional: Needed to run a remote script the first time
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# Command for installing Scoop
Invoke-RestMethod get.scoop.sh | Invoke-Expression
-
Install general dependencies:
scoop bucket add versions scoop install python310
Start up a new command-line shell (eg. Command Prompt, Windows PowerShell) and install the Python library
six
.pip install six
-
Install platform dependencies:
The platform dependencies cannot be installed through Scoop as the install rules cannot install all required components. They will be installed through the Visual Studio installer.
This code snippet must be run in a traditional Command Prompt (
cmd.exe
).curl -sOL https://aka.ms/vs/17/release/vs_community.exe start /w vs_community.exe --passive --wait --norestart --nocache --add Microsoft.VisualStudio.Component.Windows11SDK.22000 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 del /q vs_community.exe
-
Install Swift:
scoop install swift
Traditional Installation
The traditional installation process is required for Swift older than 5.4.2.
Swift has been tested with Visual Studio 2019. You will need to install Visual Studio with the following components. The installer for Swift is available in the Download section. The toolchain on Windows is typically installed to %SystemDrive%\Library\Developer\Toolchains
.
The following Visual Studio components are required:
Component | Visual Studio ID |
---|---|
MSVC v142 - VS 2019 C++ x64/x86 build tools (Latest) | Microsoft.VisualStudio.Component.VC.Tools.x86.x64 |
Windows 10 SDK (10.0.17763.0)2 | Microsoft.VisualStudio.Component.Windows10SDK.17763 |
The following additional Visual Studio components are recommended:
Component | Visual Studio ID |
---|---|
Git for Windows | Microsoft.VisualStudio.Component.Git |
Python 3 64-bit (3.7.8) | Component.CPython.x64 |
The following additional Visual Studio component is suggested:
Component | Visual Studio ID |
---|---|
C++ CMake tools for Windows | Microsoft.VisualStudio.Component.VC.CMake.Project |
After Visual Studio and the required components are installed:
-
Download a latest Swift release (5.9.1) or development snapshot installer.
-
Run the package installer.
Support Files
This is only required for versions older than 5.4.2.
You must run the following commands using x64 Native Tools for VS2019 Command Prompt
as administrator.
The x64 Native Tools for VS2019 Command Prompt
sets up the necessary environment variables to find the system headers.
Administrator permission is required to modify the Visual Studio installation.
In order to make the Windows SDK accessible to Swift, it is necessary to deploy a few files into the Windows SDK.
copy /Y %SDKROOT%\usr\share\ucrt.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy /Y %SDKROOT%\usr\share\visualc.modulemap "%VCToolsInstallDir%\include\module.modulemap"
copy /Y %SDKROOT%\usr\share\visualc.apinotes "%VCToolsInstallDir%\include\visualc.apinotes"
copy /Y %SDKROOT%\usr\share\winsdk.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
Because it is installing the files into the Visual Studio image, the files will need to be copied each time Visual Studio is updated.
Repairing after Visual Studio Updates
This is only required for versions older than 5.9.0.
If Visual Studio is updated, you may have to repair the installation. For versions older than 5.4.2, reinstall support files as mentioned above. For newer versions, see Microsoft’s instructions for repairing installed programs.
Code Signing on Windows
The following commands must be run in PowerShell.
-
Install GPG from GnuPG.org
-
If you are downloading Swift packages for the first time, import the PGP keys into your keyring:
$ gpg.exe —keyserver hkp://keyserver.ubuntu.com ` —receive-keys ` 'A62A E125 BBBF BB96 A6E0 42EC 925C C1CC ED3D 1561' ` '8A74 9566 2C3C D4AE 18D9 5637 FAF6 989E 1BC1 6FEA'
or:
$ wget https://swift.org/keys/all-keys.asc -UseBasicParsing | Select-Object -Expand Content | gpg.exe —import -
Skip this step if you have imported the keys in the past.
-
Verify the PGP signature.
The
.exe
installer for Windows are signed using GnuPG with one of the keys of the Swift open source project. Everyone is strongly encouraged to verify the signatures before using the software.First, refresh the keys to download new key revocation certificates, if any are available:
$ gpg.exe —keyserver hkp://keyserver.ubuntu.com —refresh-keys Swift
Then, use the signature file to verify that the archive is intact:
$ gpg.exe —verify swift-<VERSION>-<PLATFORM>.exe.sig ... gpg: Good signature from "Swift Automatic Signing Key #3 <swift-infrastructure@swift.org>"
If
gpg
fails to verify because you don’t have the public key (gpg: Can’t check signature: No public key
), please follow the instructions in Active Signing Keys below to import the keys into your keyring.You might see a warning:
gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner.
This warning means that there is no path in the Web of Trust between this key and you. The warning is harmless as long as you have followed the steps above to retrieve the key from a trusted source.
If gpg
fails to verify and reports “BAD signature”, do not run the downloaded installer. Instead, please email swift-infrastructure@forums.swift.org with as much detail as possible, so that we can investigate the problem.