How to use Swift on Windows

Tutorial

Tim Nazar
2 min readDec 9, 2018

Step 1 — Installing Ubuntu Shell from Microsoft Store

  • Before installing any distros for Windows Subsystem for Linux, you must open PowerShell as Administrator and run:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Step 2 — Installing Swift

First, ensure you have the latest list of packages on you system, then install Swift’s prerequisites, which include clang and Python 2.7 components:

sudo apt-get update
sudo apt-get install clang libicu-dev libpython2.7

Now you will need open Ubuntu Shell and create user account in Ubuntu System.

  • Next, download latest Swift Snapshot from swift.org.
wget https://swift.org/builds/swift-4.2.1-release/ubuntu1804/swift-4.2.1-RELEASE/swift-4.2.1-RELEASE-ubuntu18.04.tar.gz
  • Unzip downloaded archive.
tar xzf swift-4.2.1-RELEASE-ubuntu18.04.tar.gz
  • Make sure where you downloaded archive by typing pwd. I downloaded the archive to /home/timnazar/downloads and moved the unpacked files to /etc/swift-4.2.1.
  • Then add the Swift toolchain to your PATH:
export PATH=/etc/swift-4.2.1/usr/bin:"${PATH}"

Entering this command will only add the swift command to your path for your current shell session. to make sure that it is added automatically in future sessions, add it to the .bashrc file.

Open the .bashrc file:

nano ~/.bashrc

Add the following lines at the end of the file:

# Importing the Swift Toolchain
export PATH=
/etc/swift-4.2.1/usr/bin:"${PATH}"

Save and exit the file.

To make sure everything works, run the swift --version command:

swift --version

Screenshots of my example project:

Step 3 — Getting Windows files from Ubuntu Shell

All of your Windows Drives (Local Disks) mounted in /mnt. You can check it by typing:

ls /mnt

Thus, you can write code in VSCode/Sublime/etc, and compile it in your Ubuntu Shell.

If you’re writing some Server Side code, you can access to it from Edge/Firefox/etc.

Enjoy Swift! ❤️

--

--