Web Development on Windows Does Not Need To Suck

Posted by
on under

Microsoft Windows has long been considered a subpar platform for web development not based on a Microsoft technology, or in more general terms, for any kind of open source work. If you are looking for tutorials online on any open source related topic and happen to be on a Windows PC, you are going to have a lot of trouble in finding material that does not assume you are on a Linux or Mac system with access to Unix-based tools.

I mostly work on a Mac computer these days, but I own and regularly use a Windows PC as well. In this article I'm going to introduce you to the open source project that I use to bridge the gap between Windows and the Unix world. This project allows me to work on my open source projects on the PC, using the same tools I use on the Mac, or on a Linux PC. The image above is a screenshot of my terminal, running on Windows 10 (click on it to see it in its actual dimensions). There you can see I have three independent very Unixy-looking console sessions. Not the type of terminal window you associate with Windows, right?

Unix on Windows: What Are Your Options

Fortunately, as a developer on a Windows machine, you have a few options to create a Unix friendly environment appropriate for open source work.

The most obvious is to create a virtual machine using VirtualBox and install your favorite Linux distribution in it. This is a great option if your have a PC with lots of RAM, because you can set up a decent VM for Linux and leave enough RAM for the Windows side to remain usable. Sadly, for many PCs this option may be too resource intensive and result in a poor user experience.

Another good option is to rent a cloud server and provision it with the Linux distribution of your choice. You can then use putty, an awesome remote shell client for Windows, to open a remote console and work on your cloud server from the comfort of your own PC. This is a very good alternative, but it costs money.

The goal of this article is to introduce you to a third option that does not have the disadvantages of the first two: the open source project Cygwin.

What is Cygwin?

Cygwin is an open source project that has been around for a very long time. It was already a well established project when I was introduced to it in 2005. According to their own description, Cygwin "is a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows", and "a DLL (cygwin1.dll) which provides substantial POSIX API functionality".

What does this mean? It basically means that you can install and use hundreds of Unix utilities on your Windows PC. The list of ported applications includes the most common Unix shells, bash and zsh, so you can replace your Windows prompt with a Unix-like console window. The gcc suite of compilers is also ported, so if you come across a Unix based application in source code form, you have a good chance of being able to compile it and run it on your PC, exactly like you would on Linux or OS X. If you want to see what packages are available, here is the complete list of ported applications.

Several scripting language interpreters have been ported and have a Cygwin version. Python 2.7 and 3.4 are available, and so are Ruby and Perl. These are different versions than the official Windows versions of these languages, as they have been compiled as Unix tools. For example, the Cygwin versions of these languages have access to POSIX subsystem calls not available on regular Windows, such as fork(), which Cygwin implements. They are also free of the problems caused by the Windows backward slash separator for pathnames. Any tools compiled under Cygwin use the standard Unix forward slash as path separator.

It is important to note that Cygwin does not use virtualization. The utilities that come with the project are 100% native Windows executables, so there are no VMs to set up, and more importantly, no outrageous RAM requirements. This is made possible by the cygwin1.dll library, which translates POSIX calls into Windows native API calls on the fly.

Cygwin comes with a Windows interactive installer, which you must run when you do your first install, and also when you want to add or remove packages from your installation. Having to use an interactive installer to manage the installed packages is not ideal, but luckily there is a third party command-line package manager called apt-cyg that is inspired by the package managers of Linux distributions such as Debian and Ubuntu.

To make things more consistent with Unix, the Cygwin installer creates a proper Unix-like directory structure that includes the standard /bin, /dev, /etc, /usr and /home directories. And not only that, you also get a home directory under /home/username.

Is Cygwin perfect? No, it isn't. If you are used to working on Unix based systems, you'll find that Cygwin has some quirks. Most of the problems are minor though, and usually occur when you combine native Windows tools with Cygwin tools. A very common issue occurs when sharing text files, because native Windows applications use the CRLF sequence to end a line, while Cygwin uses the Unix standard of just a LF character. Another inconvenience I experience is that the Windows version of PyCharm is incompatible with the Cygwin version of Python, but in any case, using vim to edit Python code, and pudb to do interactive debugging work really well anyway.

I hope this gives you a good overview of Cygwin, which in my opinion provides a fairly decent environment for doing software development, or also to become familiar with the Unix way of doing things, something that I think is very useful in itself. If you are learning from online tutorials, using Cygwin you will be able to follow instructions for Linux or OS X with little or no modifications.

Installing Cygwin

If you are comfortable working with an interactive installer, and don't mind having to select what packages to install from an overwhelmingly long list, then you are pretty much ready to go. There are two official installers available: setup-x86.exe for a 32-bit install, and setup-x86_64.exe for 64-bit. I strongly recommend that you use the 64-bit installer if you have the 64-bit version of Windows. Only use the 32-bit version if you can't run 64-bit code on your system.

I don't find the Cygwin installer very friendly myself, so I have created a little batch file that invokes the installer and automatically selects a small set of basic packages appropriate for an initial install. My batch script also installs the apt-cyg command line package manager, which you can then use to customize your packages.

The script is hosted on github. You can open the script in your browser by clicking the following link:

Click to open: install-cygwin.bat

Once you have it in a browser window, you can use your browser's Save As function to write it, for example, to your desktop.

To use this installer batch file, simply double click its icon, or open a command prompt and run it. The script does not take any options, it will install the 64-bit version of Cygwin in a directory called cygwin, inside your Windows profile directory (normally C:/Users/username). The first few lines in the script can be edited to change the installation directory, or to switch to the 32-bit version.

The batch file will ask for confirmation before starting the install. If you give it the okay, it will download and launch the official Cygwin installer, which will run for a few minutes without requiring any actions from you. Once the installation is complete the batch file will create a desktop icon with the label "Cygwin" that you can use to start a bash console. This installer does not require administrator rights, and does not touch anything in your C:\Program Files area. Everything is installed inside the root directory selected at the top of the file.

If everything goes well, when you double click the Cygwin icon you should see a bash console window like this one:

If for any reason you want to uninstall Cygwin, simply delete the root folder, which is C:\Users\your-username\cygwin, and then also remove the desktop icon. Cygwin does not come with an interactive uninstaller.

What's Next?

My batch file performs a very basic installation of Cygwin. You can now start a bash console, and that will give you access to a variety of unix tools, which include vim, Python 2.7 and the gcc compiler, among many others. Now comes the fun part of adding more packages. What packages to install and how to configure them is something that is key to making you productive in this environment. We are all different, so we like things configured in different ways. On Windows this level of openness is not common, you'll have to get used to it.

To add packages you can use the apt-cyg installer. For example, if you wanted to install Python 3.4, you would run this command at the bash prompt:

$ apt-cyg install python3

The awesome thing is that now you can go out and research how people set up their development environments on OS X or Linux and do the same on your Windows PC!

I have decided not to include detailed instructions on how I set up my personal development environment as part of this article. There are literally hundreds of people that share their setups in blogs and YouTube videos, so you have plenty of material to research. If you need something to start with, I recommend that you look into tmux, the nifty utility that I show in the screenshot at the top of this article that allows you to split your terminal window in panels, among other things. You may also want to switch your shell from bash to zsh, which has extremely useful extensions such as oh-my-zsh, with support for command prompt themes and plugins. For code editors, vim is installed as part of the first install, but it is a plain install without any plugins. You can opt to learn vim and add plugins that make it more useful, or you can install emacs, nano or any other editor that you like. As far as languages, Perl and Python 2.7 are in the initial install, but you can add Python 3.4, Ruby and others.

If there is enough interest, I can write a follow up article in which I describe the setup pictured in the screenshot, which is based on zsh, oh-my-zsh, tmux, vim, and a number of vim plugins.

I hope you find Cygwin useful. Do you have questions? Write them below in the comments!

Become a Patron!

Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!

31 comments
  • #26 ogah said

    i love cygwin. but i am find it difficult to configure it with vim for my python/flask tutorial. pls write article on it

  • #27 Yusak said

    For now, you can use WSL (Windows Subsystem Linux), it will install Bash shell from Canonical (Ubuntu). So far it work perfectly, my vim+tmux run well on WSL

  • #28 Miguel Grinberg said

    @Yusak: Yes, that is a new option that did not exist when I wrote this article. I am also using it now, and it is fairly usable. The two main issues I have found are: 1) it has a crappy terminal that only supports 16 colors. This is easily solved by using wsl-terminal, a replacement terminal built on top of mintty (https://github.com/goreliu/wsl-terminal); and 2) it is not possible to modify files in the Linux filesystem from Windows apps. The workaround is to use the Windows files system (mounted on /mnt/c) for files that need to be accessible to windows applications.

  • #29 jiho said

    Thanks good article.

  • #30 Erwin said

    I used to do web development using everything that you mentioned. The problem with cygwin is that you're is still in fact running app in Windows and there are lots of frameworks that seize to function on Windows. ex. Celery Framework is not supported anymore on windows.

  • #31 Miguel Grinberg said

    @Erwin: I don't think this is correct. I can't really say about Celery, but Gunicorn is another popular package known to be incompatible with Windows. But it works great under Cygwin.

Leave a Comment