Cygwin: a Linux-like Environment for Windows

Emulate Linux on Windows by using Cygwin

© Mark Alexander Bain

Sep 4, 2008
Install Cygwin now!, Cygwin
Linux and Windows don't mix - or at least they didn't before Cygwin. This article shows how to set up a Linux emulator running on Microsoft Windows.

In a recent blog Ian Douglas from the Daily Telegraph stated that 0.97% of the 13 million user's of the newspaper's web site used Linux, and many hardened Linux users may well wonder why that's so low,

Undoubtedly part of the answer is the fact that moving from Windows to Linux is a major step. Well, not anymore - any Windows user can now incorporate Linux into their own PC just by installing a single application - Cygwin.

What is Cygwin?

Cygwin is a Linux emulator for Microsoft Windows, and as such does not support native Linux applications - in order for them to run they need to be ported to Windows, and this normally normally means rebuilding the application using Cygwin.

Fortunately there have been a lot of very busy people and so the list of Linux tools and applications available to Cygwin is extensive.

Installing Cygwin

Cygwin installation is very simple and straightforward - the installation program can be found on the Cygwin web site - http://cygwin.com/; and then it's just a matter of doing the following:

  • click on "Install Cygwin Now"

Then, follow the on screen installation instructions.

At the end of the process a 'default' system will have been installed - this consists of the minimum set of applications that is needed to emulate Linux.

Starting Cygwin

Once installed Cygwin can be started in any one of three ways:

  • double click on the Cygwin desktop icon
  • click on Start | Programs | Cygwin | Cygwin Bash Shell
  • start a new MS-Dos prompt and type "C:\WINDOWS\COMMAND.COM /E:4096 /c H:\cygwin\Cygwin.bat" (changing "H:\cygwin" to the location defined during the installation process)

The user will now be using Linux.

An Example of Working with Linux in Cygwin

There are far too many Linux tools to cover here, but one powerful element worth mentioning is Linux's file processing abilities. For example, the struture of one file - /etc/passwd/ - is quite complex:

$ cat /etc/passwd

admin:use_crypt:500:544:Administrator:/home/admin:/bin/bash

bainm:use_crypt:552:544:bainm:/home/bainm:/bin/bash

However, Linux tools such as gawk can extract data very easily:

$ gawk -F: '{print $1,$6}' /etc/passwd

admin /home/admin

bainm /home/bainm

In this example gawk has been instructed to use the colon as a field separator and then print the first and sixth fields.

Adding Cygwin Applications

Cygwin will have been installed in it's 'default' configuration - that's to say with the minimum number of tools needed to simulate a basic Linux system. However, more tools can be added as necessary, for example a few useful tools that are not installed by default are:

  • ssh - allows access to any Linux machines on the network
  • X-server - any Linux applications with a GUI (Graphical User Interface) can be run once this is installed

If any other tools are require then the user only has to rerun the installation program (setup.exe will have been downloaded during the installation process), and then selecting the appropriate files.

Accessing Windows Files with Cygwin

Every Windows user knows that the main drive in their PC is C: - but such a concept does not exist under Linux - on Linux there is no C: drive. However, this isn't a problem - Cygwin uses it's own mapping - C: is simply refered to as /cygdrive/c thereby allowing access to all files on the system.

Conclusion

Cygwin, of course, is not Linux - it can't be; however, for anyone that has to stay with Microsoft Windows but still wants to benefit from the power of Linux then Cygwin is the perfect compromise.


The copyright of the article Cygwin: a Linux-like Environment for Windows in Computer Programming is owned by Mark Alexander Bain. Permission to republish Cygwin: a Linux-like Environment for Windows in print or online must be granted by the author in writing.


Install Cygwin now!, Cygwin
Cygwin is easy to install, Mark Alexander Bain
Running Linux under Windows, Mark Alexander Bain
   


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo