Jesil's Notes a human's blog on life and everything in it

#D1 Swift Development in Windows with WSL

#

It’s been a while since I wrote anything on the blog about my life and recent events. It has been a very critical period of time in my life and I am still finding my footing running the company, programming, and having a personal life. I have had the idea of writing posts about development and tutorials and tips since I started the blog but I never got around to actually doing it. Until now.

Swift is a general-purpose, multi-paradigm, object-oriented, functional, imperative and block-structured language. It is the result of the latest research on programming languages and is built using a modern approach to safety, software design patterns by Apple.

Even though it was proprietary and required Mac OS and XCode in the beginning, Apple open-sourced Swift and made it available on Linux after 2015. And Swift has made a place in the hearts of developers everywhere in the shortest time ever. Its beautiful syntax, speed, and gentle learning curve have gotten developers flocking to it. It was even recognized by StackOverflow as one of the most developer-friendly languages available now.

And now, web frameworks are being developed and used that use Swift for both front-end and back-end programming. So, naturally, I had to check it out and without a Mac at hand, the options I had was to install it in Ubuntu or Set it up in WSL. I have been favoring windows lately due to the fact that it has improved a lot in terms of developer friendliness (and the fact that it is faster since it’s installed in the SSD while I have ubuntu on an HDD).

And I kinda found it hard to find a tutorial that helped so I decided that If I got mine working, I’d post one. So here goes.

The system I am using is running Windows 10 Home 1903 with WSL (Ubuntu 18.04 LTS).

Step 1: Open Bash and move to the root

  • To open bash open Run (Windows Key + R) then type bash and hit enter.
  • Move to Root: Type cd and hit enter

Step 2: Install the required dependencies

$ sudo apt-get install clang libicu-dev libpython2.7 libatlas3-base

libpython2.7 and libatlas3-base are optional and may be skipped if you don’t encounter any errors during runtime but it is highly recommended that you do.

Step 3: Download the latest Swift Binary Release

Head over to https://swift.org/download/ and download the latest binary release for Linux. You should be getting a tar.gz file from there.

Then,

  • Create a folder with name Swift in C drive or any drive of your choice. I am going to put mine in E.
  • Copy downloaded swift binary in this folder
  • Type this command to change directory:

cd /mnt/e/ProgramData/Swift

I used /mnt/e/ProgramData/Swift because that is where I copied the binary file I downloaded, You guys have to cd to the folder you moved your binary file to.

Step 4: Install Swift

Once you have changed directory into the location of the binary file, it is time to install it. You are to use the tar command for this purpose.

$ tar -zxvf swift-5.0.2-RELEASE-ubuntu18.04.tar.gz

This is the command I used because the name of the binary file I downloaded was swift-5.0.2-RELEASE-ubuntu18.04.tar.gz . Replace that with the name of the file you have downloaded.

Your basic install is almost complete at this point. Now we are going to declare the PATH and make the swift command known to the system.

Step 5: Setting PATH variable

If you installed the Swift toolchain on Linux to a directory other than the system root (which we have), you will need to run the following command, using the actual path of your Swift installation:

$ echo 'export PATH=/mnt/e/ProgramData/Swift/swift-5.0.2-RELEASE-ubuntu18.04/usr/bin:$PATH' >>.bashrc

$ source .bashrc

And you are done. Your swift installation on WSL is complete. You can now head over to https://swift.org/getting-started/ and start your journey in Swift.

You can check if your installation is successful by running swift --version

You do however need to keep in mind that as of August 2019, WSL does not contain a full Linux kernel and has its drawbacks. One of those drawbacks that affect our journey is that the Swift REPL does not function in WSL. It is a known and reported issue and the only thing we can do is wait for the fix. But it is not a hindrance and it does not stop you from learning of programming in Swift through WSL.

You can write your Swift programs in Visual Studio Code in Windows 10 by setting up a remote connection with WSL. That way you can use the in-built bash shell in vscode for running the app. It is very easy to set up. If you are finding it hard to get it working, leave a comment below and I will get back to you.

Now get to work.

Vincere Impedimenta !

About the author

Jesil Jose

Add Comment

By Jesil Jose
Jesil's Notes a human's blog on life and everything in it

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 576 other subscribers

Categories

Me Elsewhere

Blog Stats

Recent Posts

Member of The Internet Defense League