cygwin · Linux · Server · Windows

Cygwin Walkthrough and Beginners Guide – Is it Linux for Windows or a POSIX Compatible Alternative To PowerShell?

Linux in Windows?

Cygwin is an awesome tool for agnostic operating system users who regularly use both Windows and Linux but want the power of a Linux shell and its tools running within Windows. It is a great replacement to the primitive Windows command prompt without the need to learn a new collection of commands or a new scripting language. A requirement which is needed for the Microsoft developed and recommended command prompt alternative PowerShell.

Cygwin is POSIX (Portable Operating System Interface for uniX) compliant which basically means it shares a common API with all the other compliant operating systems. It does not mean applications compiled for other POSIX systems such as Linux software will automatically work within Cygwin. To add new POSIX software you still need to compile the software source code under Cygwin using its own compilers and libraries. This process is a requirement with most POSIX compliant operating systems e.g. software complied for FreeBDS (Unix) will not work under Debian/Ubuntu (Linux).

Cygwin will work on any x86 32-bit or x86-64 editions of Windows NT from NT 4.0 Service Pack 4 (1998) onwards to Windows 7 including 2000, 2003, 2008, XP and Vista. There is no support for the Windows 16/32-bit hybrids such as 95, 98 or ME.


So let’s get started. Visit, download then run the setup.exe. This file is a Windows based package manager for Cygwin. By default it will download and install the latest minimal install of Cygwin but on future launches it will also enable you to add new packages and update your existing Cygwin software. So after you install Cygwin do not delete or loose the location of setup.exe!

Cygwin Net Release Setup Program (setup.exe).
For Choose A Download Source select Install from Internet.
Select Root Install Directory.

By default Cygwin will install to C:\cygwin but you can change this to any directory of your choosing. It is highly recommended that you do not choose a directory path which contains spaces in the name, so both C:\Program Files\cygwin or C:\Program Files (x86)\cygwin are out.

Select Local Package Directory.

Cygwin setup will save all downloaded packages to this folder after it has finished installation. You can then either delete them, leave them in this directory or back them up to a USB stick for future use on this or other computers.

Select Your Internet Connection.

Unless otherwise needed you should leave the Internet connected selection with the default selection of Direct Connection.

Choose A Download Site.

Choose A Download Site lets you select a file repository from where Cygwin setup will download the the packages and files. It is preferable to pick a download location from a site that is physically close to your own. But if you can not determine this from the country codes in the URL or can not find a suitable mirror then simply select the first item.

Selecting Packages

Select Packages.

This Select Packages screen is the most important part to Cygwin setup. It is the Cygwin package manager interface, equivalent to Synaptic Package Manager in Debian and Ubuntu or YUM Extender in Fedora Linux. The screen capture has a number of arrows pointing to features of the interface but as a first time user you can completely ignore all of these and press Next to accept the default installation.

  • The dark green solid arrow points to the search dialogue enabling you to quickly filer packages by name. Unfortunately the search does not work on the package descriptions.
  • The solid black arrow has 4 radio buttons enabling you to mass-apply installation restrictions on all packages.
  • Keep tells Cygwin setup not to update any installed packages.
  • Prev is short for previous which reverts all packages back one version.
  • Curr is the default and recommended option as it installs the current version of all selected packages.
  • Exp will install the most current or experimental version of all selected packages.
  • The red arrows point to the manager categories which can be expanded to reveal individual packages.
  • The purple arrow points to version numbers which belong to packages that are already installed onto Cygwin.
  • Orange arrow enables you to manually override the global package version (black arrow radio buttons).
  • Skip means the package has not been installed and setup will ignore it.
  • Keep means the package has been installed but setup will ignore it.
  • Reinstall will overwrite an existing package installation with the same version from a fresh download.
  • 1.0-1 or some other version number means setup will install this version of the package for the first time.
  • Source means setup will ignore the installed package but will download the source codes.
  • Uninstall removes the installed package from your Cygwin installation.
  • The yellow arrow points to a Binary check-box while the light green points to a Source check-box. These check-boxes only appear only when available to the package New column.
  • The light blue arrow is the package download size in Kilobytes.
  • Dark blue contains the package name and a brief description.

Cygwin setup will now download and install all the default-install packages. Wait until the Progress screen is complete and go onto the Next screen.

Create Icons & Install Complete.

Create Icons enable you to add Desktop and Start Menu shortcuts. Once finished use either shortcut to launch Cygwin.

Bash Terminal

Welcome to Bash.

Welcome to your Bash prompt in Windows! You can test this by running Bash version.

bash --version
Display your version of Bash.

The first thing I’d recommend doing is customising your bash shell to implement some aliases for basic colouring on a few staple Cygwin commands.

dir -A ~

Will reveal some hidden setting files in your home directory which you can edit these using a text editor, but please avoid using the standard Windows Notepad. I use Windows Notepad++ and would edit w:\cygwin\home\Ben\.bashrc but you would probably need to edit c:\cygwin\home\[User name]\.bashrc. Windows may have issues opening a file which it sees as only having an extension but lacking a file name. If this is the case just use the Open With dialogue but make sure you have the Always use the selected program to open this kind of file check-box left unchecked.

The yellow highlights the settings I would recommend to un-comment.
Bash settings file after the comments have been removed.

Once you have finished your changes you can apply them by reloading Bash.

bash --login

Test your new alias and option defaults.

cd /

You now see a colourised directory and file listing of the Cygwin root.

Line list of root.

This is the same directory as you chose during the Cygwin setup installation which by default is c:\cygwin. You can use either Windows File Explorer, Windows command prompt or Cygwin to modify the contents of the root. For more details on how Cygwin handles POSIX permissions within Windows and other potential incompatibilities I’d recommend reading the Using Windows Security in Cygwin chapter in the manual.


By default there is no Cygwin clear command (cls in command prompt) but the easiest way to clean your terminal is to press [Ctrl]  l.

Use the [Tab] key on your keyboard to auto-complete commands, file and directory names. This Bash feature is superior to the basic Tab auto-complete used by Windows command prompt.

Did you also know you can chain 2 or more commands together using a semi-column ; character as the separator.

cd /; echo "Root Directory"; ls; cd ~; echo "My Home Directory"; ls

And if you didn’t realise in the command above, change directory forward-slash cd / takes you to the Cygwin root, while change directory tilde cd ~ takes you to your user home directory.

Drill Down of the Cygwin Root

  • Cygwin.bat is the Windows batch file used to launch a Cygwin Bash prompt within a Windows command prompt.
  • Cygwin.ico is a standard Windows icon file attached to the Cygwin batch file.
  • bin/ is a directory containing binary (execute) applications that have been compiled for use on Windows under Cygwin. In here are all the unique POSIX-like commands and applications that give you all that extra functionality that a bare-Windows install often lacks.
  • cygdrive/ contains a list of mounted Windows drive letters. From here you can access any drive partition that is viewable to Windows. For example cygdrive/c/Windows/ would be the location of most peoples Windows installation.
  • dev/ is short for devices. Traditionally for POSIX this is where your detected hardware devices are listed but in Cygwin its usage is mainly there for software compatibility and can be ignored.
  • etc/ contains all your Cygwin related configuration files. Unlike the Windows registry these should all be plain text files that can be edited within any Windows text editor (such as NotePad++) or a Cygwin editor such as VM or Nano.
  • home/ contains the user directories which are not unlike the Windows User directories. This is where your non-Cygwin files such as documents, file downloads should be stored.
  • lib/ is an abbreviation of library. These are compiled, shared components that are used by various Cygwin commands and applications but you can ignore this directory.
  • proc/ is a virtual directory that allows you to display various aspects of your system using the cat command.
  • cat /proc/cpuinfo Displays your computer CPU details.
  • cat /proc/meminfo Displays your Windows memory information.
  • cat /proc/mounts Lists your disk mounts within Cygwin.
  • tmp/ is the Cygwin temporary directory.
  • usr/ is the bread and butter of your Cygwin install.
  • usr/bin/ is identical to bin/ that was listed previously.
  • usr/include/ are programming header files which are somewhat like shared libraries, you can ignore this.
  • usr/local/ is a location where you can compile applications for yourself, again if this does not interest you it can be ignored.
  • usr/sbin/ contains system binaries and applications tools for Cygwin system administration.
  • usr/share/ are platform independent read-only shared files such as documentation. For example /usr/share/fonts contain a collection of system fonts. /usr/share/doc contains application documents.
  • usr/src/ is a location for storing application source code.
  • usr/ssl/ is a location for storing SSL (Secure Socket Layer) and TLS (Transport Layer Security) certificates which are used for Internet communication encryption and security.
  • usr/tmp/ is the same temporary folder as /tmp.
  • var/ is where variable data files are stored. These are files generated by yourself or applications. For example all log files would go in /var/log. If you ran an Apache HTTP daemon the files it hosted would be contained in /var/www.

POSIX and Cygwin Commands

Now the usage of a Bash shell or POSIX-like commands is out of the scope of this article. You can run dir /bin to see all the .exe execute commands available to you within Cygwin. Like Windows command prompt you do not need to include the file extension when running an application, dir works the same as dir.exe.

If you need quick help on the usage of a command, use [command] –help e.g. dir –help. Many commands share the same options.

If you think the default Cygwin bash shell is a bit ugly then you are not alone. Microsoft does not give the default command prompt much love and unfortunately this is what Cygwin relies on for its own terminal interface. You can easily change this though by again running Cygwin setup.exe. When you are back in the Select Packages screen do a search for mintty. Select to install the mintty binary package and once complete go to your Cygwin start menu. There should be a new mintty option in addition to the Cygwin Bash Shell.

Install Mintty Terminal.
Cygwin under command prompt is not that attractive.
Cygwin under Mintty allows for font smoothing.
From now on use Mintty for a cleaner terminal interface to Cygwin.

Services and Daemons

Want to to implement a service or daemon into your Cygwin install? I will show an basic example using Lighttpd, a light-weight HTTP server that is an alternative to Apache2 HTTP (which also can be installed to Cygwin).

Run Cygwin setup.exe again to search and install lighttpd and make sure you say yes to install any resolving dependencies. Once installed you will find the application residing in the usr/sbin/ directory as lighttpd.exe. An example configuration file lighttpd.conf.default can be found in etc/lighttpd/. We will create an empty configuration file using the touch command.

cd /etc/lighttpd
touch lighttpd.conf

Now use your Windows notepad application to edit c:/cygwin/etc/lighttpd/lighttpd.conf and copy the settings listed below.

The GitHub repository of the code entries used in this article

server.document-root = "/var/www/servers/"
server.port = 80

server.username = "www"
server.groupname = "www"

mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png"

static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )
index-file.names = ( "index.html" )

$HTTP["host"] == "" {
server.document-root = "/var/www/servers/"

This config we are using is taken from the Lighttpd Configuration Tutorial.

Now attempt to launch lighttpd with your new configuration file.

/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

Our attempt will fail because the web server document root directory does not exist, so let’s create that and lets also make an index.html document and try it again.

mkdir /var/www ; mkdir /var/www/servers ; mkdir /var/www/servers/ ; mkdir /var/www/servers/
touch /var/www/servers/

In a Windows notepad application edit c:/cgywin/var/www/servers/ and copy/paste the following HTML code.

<!DOCTYPE html>
        Hello World</title>
    <h1>Hello from Lighttpd running in Cygwin!<h1>

Hello from Lighttpd running in Cygwin!

index.html content.

Let’s retry running Lighttpd again.

/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

Once Lighttpd has loaded you may need to press the Enter key to restore your Bash prompt but Lighttpd will continue to run in the background. Now point your local Windows web browser to or localhost.

Chrome browser viewing our primitive HTML file.

When you want to shutdown Lighttpd run find the PID (Process Identifier) and kill it.

ps -s
kill [PID number]
Discover and shutdown of the Lighttpd service.

Congratulations! You have successfully implemented a Bash shell environment on your Windows operating system that also has a robust but simple HTTP server.

Popular Cygwin Applications

Other popular Cygwin packages that maybe of interest.

Servers services such as Apache, BIND, PostgreSQL, Pure-FTPd, OpenSSH.
Programming languages such as C, C++, Perl, Python, Ruby, TCL.
Remote log-in tools SSH, RSH, Telnet.
File transfer tools FTP, SCP, rsync, unison, rtorrent.
In addition to an extensive range of network, system and file diagnostics tools.

More information on Cygwin can be found in its User’s Guide.

15 thoughts on “Cygwin Walkthrough and Beginners Guide – Is it Linux for Windows or a POSIX Compatible Alternative To PowerShell?

  1. Very useful post but when I re-run setup lighttpd isn’t there. Tried downloading it but I’m not sure what to do with it.

      1. The Services and Daemons example is generating a lot of “Duplicate config variable in conditional 0 global:” I’ve commented out several that were already in the file before pasting the example above. Not sure what I did wrong here….

  2. Am running an IIS Server with Cygwin installed. I went thru this setup for a subdomain and I’m getting unable to bind to port 80, operation not permitted….. tried it again after shutting down IIS…. same issue.

    1. I haven’t used IIS Server in a very long time but I assume its Windows service has locked down port 80 for its own use, even after the server is shutdown.

      Try changing the default port on Lighttpd or IIS Server.

      For Lighttpd in Cygwin:

      nano -B etc/lighttpd/lighttpd.conf

      Change the line

      server.port = 80

      To something unused say

      server.port = 8080

      Save, exit nano and then try running lightttpd again.

      /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

  3. Excellent guide! First one I’ve seen and tried where everything actually worked as expected and described. Now if someone could just do the same for installing and compiling gcc as every guide I’ve seen and followed results in a failed make of gcc in the end (Eventually want to be able to compile latest Apache and run it on top of Windows 8).

    1. Hi Thomas, thanks for the comments and I am glad this 2011 article worked for you. Unfortunately I stopped using Cygwin a number of years ago as I was only using it for its ported POSIX programs and not its compiling abilities.

      1. That’s OK, still one of the better articles I’ve seen on Cygwin. Starting to give up on trying to use it though as hardly ANY source will compile for me, guess I’ll have to go full hog with Linux as it’s likely less trouble in the end.

        1. I think it would be the way to go especially if you run open source web servers such as Apache or Nginx. Personally I use Windows as a desktop and ‘headless’ Linux for a server software. You can use a virtualization environment on Windows such as VirtualBox to run a terminal/shell aka server edition of Linux even with its own IP address. That way you get the best of both worlds. Ubuntu Server is probably a good bet if you are not familiar with Linux as its documentation & support is very extensive.

  4. All through the article, the word “complaint” is used for “compliant”.

    On the first occurrence, I read the sentence 3 times, trying to make sense of it, before realizing what you’d done.

    I searched for a means, such as e-mail, to notify you privately, but found none.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s