Windows Installation Options

Dependencies

Swift has the following general dependencies:

Swift on Windows has the following additional platform specific dependencies:

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.

  1. Setup all needed dependencies.

  2. Install required Visual Studio components:

    Install the latest MSVC toolset and Windows 11 SDK (10.0.22000) through Visual Studio 2022 Community installer. You may change the Visual Studio edition depending on your usage and team size.

    winget install --id Microsoft.VisualStudio.2022.Community --exact --force --custom "--add Microsoft.VisualStudio.Component.Windows11SDK.22000 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
    
  3. Install Swift and other dependencies:

    Install the latest Swift developer package, as well as compatible Git and Python tools if they don’t exist.

    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
  1. Install general dependencies:

    scoop bucket add versions
    scoop install python39
    
  2. 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 2022 Community installer. You may change the Visual Studio edition depending on your usage and team size.

    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
    
  3. 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:

  1. Download a latest Swift release (5.10) or development snapshot installer.

  2. 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.

  1. Install GPG from GnuPG.org

  2. 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.

  3. 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.

  1. The Windows binaries are built against Python 3.9 

  2. You may install a newer SDK instead.