Emulate Linux on Windows by using Cygwin

Words
544
Reading
3 min
9y
Listen to this post
~4 min

Linux and Windows don't mix - or at least they didn't before Cygwin. This tutorial shows how to set up a Linux emulator running on Microsoft Windows.

Any Windows user can 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.

image.png

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.

image.png

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.



Posted on Utopian.io - Rewarding Open Source Contributors

Emulate Linux on Windows by using Cygwin | Ecency