15 November, 2014

How to install Cygwin for windows?


So you have windows as your installed OS on your dektop/pc.

Now you may have your own reasons for that and I am not gonna Harp you on that matter!

So here's the deal, the command line is your friend but the windows command line! Uggh. NOT REALLY!

It is the kind which will ditch you the moment
  • you are most vulnerable.
    or 
  • when you most need him.

And if you are coming from a UNIX background, it can pretty much feel like moving from a Ferrari to Fred Flinstone's car!

So if you are a Linux or Mac fan and you want to overclock the windows command prompt, then Cygwin is for you mate!

After reading this article and  you will be able to install cygwin and use it according to your needs in windows.


What the heck is Cygwin anyway?


Cygwin(pronounced as SIG-win) =  GNU + Cygnus + Windows

It is nothing but the windows command line running on steroids which runs tons of well known, age old, useful Unix commands.

To quote the original developers 
a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows
a dll (cygwin1.dll) which provides substantial POSIX API functionality.

Wondering what POSIX is ?

For starters, it is just an acronym for "Portable Operating System Interface" and is a set of standards set by IEEE for maintaining compatibility between various Operating systems.

Biggest advantage of all is that all the commands which you remember from UNIX will run beautifully in Cygwin!


Installation

Step 1: Download Setup

Download the setup program "setup.exe" from www.cygwin.com.

Step 2: Run Setup to Select, Download & Install Cygwin Packages

Run "setup.exe" ⇒ Install from Internet ⇒ select a directory (avoid installing in "Program Files" because of that "blank" character) ⇒ choose "Local Package Directory" which saves the downloaded installation files ⇒ select your Internet proxy setting ⇒ choose a download mirror site. (If "choose download site" box is empty, add "ftp://mirror.averse.net/pub/cygwin" in the "User URL". You can find all the mirror sites from http://cygwin.com/mirrors.lst.)
Select the packages that you wish to install.
Important: For programmers, you certainly need to open the "Devel" (Development) category and select "gcc", "g++", "gdb", "make", and others, which are not part of the default selection.
Browse thru all the categories. Complete the installation process. You can always re-run "setup.exe" to install additional packages later.

Step 3: Setup PATH

Include the Cygwin Binary directory (bin) in the PATH environment variable.
Suppose that your Cygwin is installed in directory "c:\cygwin". From "Control Panel" ⇒ System ⇒ (Vista only) Advanced System Settings ⇒ Advanced ⇒ Environment Variables ⇒ System Variables ⇒ Select variable named "PATH" ⇒ Edit ⇒ Add "c:\cygwin\bin;" in front of the existing PATH entry. Note that the semi-colon serves as the directory separator to separate Cygwin from the rest of directory paths.

Step 4: Verify Cygwin

Start the Cygwin Command shell (bash or sh) by running "cygwin.bat". You shall see the command prompt "$". You may need to create the users' group and password files by running the following commands:
$ mkpasswd –l > /etc/passwd
$ mkgroup –l > /etc/group
Try out some Unix commands (you need to read a Unix book - there is no short-cut in learning), e.g.,
$ ls
$ dir
$ pwd
$ cd newdir
$ cd ..
$ cd /
List the current directory
Similar to "ls"
Print (or display) the current working directory
Change current working directory to newdir
Change current working directory to its "parent" directory
Change current working directory to its "root" directory
Need help? Try:
$ man command
$ man –k keyword
$ man –f command
$ whatis command
$ info command
$ help
Display the manual pages for command
Display commands containing keyword
Display a brief description of command
Same as "man –f command"
Display the information pages for command
Display the help menu
On bash shell, after setting the directory to the the "root" (via "cd /"), you could find a directory called "cygdrive" (via "ls" or "dir"), where all the hard disks are mounted. "cd cygdrive" and "ls" lists all the hard disks, e.g., "c", "d", etc.
You may mount your C drive ("c:") as "/c" instead of the default "/cygdrive/c" via this command:
$ mount c: \c
$ mount
Mount Drive "C:" as "\c"
Display the current mounts
You could invoke the Cygwin programs and utilities via the Windows' Command Prompt ("cmd.exe") instead of bash shell (provided the PATH is set properly), e.g.,
> ls -alR
> man gcc


Now Cywin has its own drawbacks per se!



Say you have compiled something for Cygwin and lets say that you want to distribute the resulting application. You must also distribute the cygwin runtime environment (provided as cygwin1.dll).
But the alternative, MinGW provides quite a little(as in barely anything there!) as compared to Cygwin.

But hey, nothing is perfect!

Happy coding!


REFERENCES & RESOURCES
  1. Cygwin Mother Site @ www.cygwin.com.


No comments:

Post a Comment