Getting started with Cygwin

What is cygwin?

Here's the description available at the project homepage http://www.cygwin.com/ :

"Cygwin is a Linux-like environment for Windows. It consists of two parts:

  • A DLL (cygwin1.dll) which acts as a Linux emulation layer providing substantial Linux API functionality.
  • A collection of tools, which provide Linux look and feel."

     Cygwin provides a very nice environment once it is up and running, but the installation can be confusing to new users. Hopefully this step-by-step installation will be useful.

    Installation

    Start off by going to the project homepage (http://www.cygwin.com/ ) and clicking on the installation icon:

    This will bring up the following  File Download page:

    You can save the application anywhere you like, but I highly recommend creating a separate top-level directory such as C:\cygwin.

    Clicking on Open brings up the installation wizard:

    Clicking Next provides you with the following download options. If you have a reasonably fast and reliable Internet connection, accepting the default Install from Internet is probably the best option. Alternatively, you can first Download from Internet, then when this is finished, rerun Setup.exe and select Install from Local Directory.

    Selecting Install and clicking Next brings up the following dialog window:

    I highly recommend that you install in a high-level directory without spaces in the name (i.e. not in C:\Program Files\...). The remaining two issues reflect personal preferences. Default Text File Type refers to the end-of-line format to be used (CR/LF for DOS or LF for Unix). If you will be exchanging files with a Unix system you may want to choose Unix, otherwise DOS is just fine.

    Select your options, then click Next to bring up the following:

    The Local Package Directory should correspond to the directory in which you downloaded the Setup.exe file. You can keep things simple by always using one directory for everything.

    The next window allows you to Select Your Internet Connection. For most users this will be a Direct Connection. If you connect to the Internet via a proxy server, select Use HTTP/FTP Proxy and enter the relevant information.

    Click Next and Choose A Download Site from the list of sites, preferably one close to your own country.

    A setup window will pop up notifying you that it is downloading a file called setup.bz2 after which you will be presented with a dialog window similar to the following ( this and following snapshots will change as the available packages are updated ):

    From the cygwin home page:

    "The setup.exe utility, which is downloaded when you click on the above link, tracks the versions of all installed components and provides the mechanism for installing or updating everything. Run this program any time you want to update or install a cygwin package.

    Note also that, by default, setup.exe does not install everything. Only the base cygwin distribution is installed by default. When running setup.exe, clicking on categories and packages in the package installation screen will provide you with the ability to control what is installed or updated. For instance, clicking on the "Default" field next to the "All" category will provide you with the opportunity to install every Cygwin package. Be advised that this will download and install hundreds of megabytes to your computer. The best plan is probably to click on individual categories and install either entire categories or packages from the categories themselves."

    There is a very large and growing number of packages available; I suggest that you browse through the various categories and see what's available. If you have sufficient disk space you may wish to install all the tools. Here we'll download a fairly minimal set of tools for C++ developers. You can go back at any time and install additional packages, or remove those you don't need or want.

    Expand the developer's menu by clicking on the + sign next to Devel:

    Clicking on the View button will bring up various views of the menu (e.g. Category, Full, Partial, Up To Date, Not Installed). This is most useful for updating an installation. For most users, the default current version (Curr) is most appropriate.

    We'll need the following packages:

    binutils, for the GNU assembler, linker and binary utilities.

    Scroll down to binutils. Click on the icon to bring up the latest version. Repeated clicking will bring up various options. In my case, since I have already installed binutils, the default is to keep the current installation (20030307-1).

    Next, we'll install the Gnu Compiler Collection, gcc:

    (Note that I have installed gcc-mingw and ggc2 as well, but normal developers should only need gcc.)

    We'll also need make, so scroll down and select it as well:

    This is a minimal set, you may also want to install an editor (emacs), debugger (gdb), documentation generator (doxygen), source control software (cvs), etc.

    Once you have selected the packages you would like to have installed, click Next. A progress window will open, similar to the following, where you can follow the download.

    Once all the files have been downloaded, they will be installed, with the accompanying progress window:

    A successful installation will end with the following dialog box, providing you the option to install convenient access to the cygwin command line shell.

    You may see a post-installation window pop up briefly as Setup.exe performs its post build steps.

    Congratulations! You have now successfully installed cygwin with a minimal set of C++ developer's tools.

    Usage

    You normally bring up a cygwin bash shell by clicking on the cygwin icon you installed above.  You can also use the cygwin.bat file located in your installation directory.

    If you want to access cygwin functionality from a DOS Command Prompt, you need to add the Cygwin bin directory (e.g. C:\cygwin\bin) to your PATH.

    Customization

    If the system variable HOME is defined, the bash shell will open in that directory and will look for the following  initialization files and execute them if found:

    .bashrc contains bash commands and is executed each time an interactive bash shell is launched. Use it to define and export environment variables, aliases etc. Here is an example file:

    # User dependent .bashrc file
    # Don't put duplicate lines in the history.
    export HISTCONTROL=ignoredups

    alias h=history
    alias more='less -EFX'
    alias ls='ls -F'
    alias cp='cp -i'
    alias mv='mv -i'
    alias which=type
     

    .inputrc controls how programs using the readline library behave. The following example enables the Home, End, Delete and Insert keys, as well as enabling accented characters to be displayed.

    # This file is read by the 'readline' library
    # (the library which bash uses for its command-
    # line editing facility)

    # Make Home work
    "\e[7~": beginning-of-line
    # Make End work
    "\e[8~": end-of-line
    # Make Delete work
    "\e[3~": delete-char
    # Make Insert work
    "\e[2~": paste-from-clipboard

    # Ignore case for the command-line-completion functionality.
    set completion-ignore-case On

    # Make Bash 8bit clean (i.e able to display 8-bit characters)
    set meta-flag On
    set convert-meta Off
    set output-meta On

    set horizontal-scroll-mode On

     

    Additional information can be obtained by typing info bash or info readline.

    You can customize your cygwin window by clicking on the icon in the upper left corner and selecting Properties.

    This will bring up the following window:

    To enable cut-and-paste operations, check the QuickEdit Mode.

    The Layout tab controls the size and position of the window. Selecting a large value for the Screen Buffer Size Height will give you a nice "scrollable" history of your session commands.

    The Font and Colors tabs allow you to further personalize the appearance of your window.

    Updates

    You can update your cygwin installation at any time by going to your installation directory and rerunning setup.exe. When you get to the Select Packages panel you will be given the option to Keep, Uninstall, Reinstall, or (sometimes) install a previous version.

    Problems?

    The cygwin project provides many helpful resources for users of all levels, including a FAQ and the User's Guide. Please check these out before sending email to a mailing list , and, if you're new at this, please follow the bug reporting guidelines.

    Contact

    If you have any comments, suggestions, or contributions, please contact me at Norman.Graf@slac.stanford.edu .