Cygwin Makes Microsoft Windows Usable

Cygwin is essential for any serious computing on a Microsoft PC, enabling you to overcome some of the inherent disadvantages of all Microsoft Windows operating systems.

Table of Contents

  • What is Cygwin?
  • Important Preparation
  • Get, Install and Run Cygwin
  • X-Windows
  • Non-Cygwin Applications
  • Running Active State Perl Within Cygwin
  • Running MikTeX2.7 Within Cygwin
  • Calling latexmk Within Cygwin
  • Deleting Cygwin from Microsoft Windows XP
  • Change the Default Shell from Explorer to Blackbox
  • Further Reading
  • What is Cygwin?

    Cygwin is free software that provides a Unix-like environment, within a Microsoft-Windows operating system (95/98/ME/NT/2000/XP/Vista). Cygwin consists of a Unix system call emulation library, cygwin1.dll, together with a remarkable assortment of free software applications, organized into a large number of optional packages.

    You cannot run dedicated Unix binary executables using Cygwin. In order to run such software, it first must be compiled from its sources. However, most POSIX-compliant software, including X11 applications, can be compiled using Cygwin.

    Important Preparation

    Before you begin, the very first thing to do is to ensure your PC user name (also called a login name) contains no spaces. If your name does contain a space then the easiest (and best!) solution is simply to delete it and create a new name without spaces. The reason is that cygwin will create a directory username as your home directory and unix-like shells, which is what cygwin is, uses the space-character as a word delimiter. Consequently, there will be severe problems if a space is in your username.

    The cygwin Setup FAQ gives two methos of correcting the problem. I have never succeeded in getting either solution to work, so in my opinion, it is best to avoid the problem arising in the first place and work with only a no-space user name. To be safe, it is best to adopt this rule also for directory names.

    DO NOT USE SPACES IN USERNAMES OR DIRECTORIES!

    Get, Install and Run Cygwin

    This should be starightforward if you have followed the Important Preparation work above.

    Use any internet browser, go to Cygwin and download the file setup.exe to a directory (folder) on your PC. It does not matter what the directory is called (but no spaces!) or where it is located on your PC, but we will use C:\cygwin_setup as its name.


    Figure 1

    To open the Cygwin installer (Figure 1 : Cygwin Net Release Program), connect to the internet and run setup.exe from Windows Start. Using the installer is intuitive, but detailed guides are available from An Introduction to Cygwin and Cygwin itself, if required.

    The main problem is to decide what packages to download. You will need all the Base packages, so it is best to start there. You will also need a shell, so get Bash. Other useful packages include

      inetutils ncurses openssh perl python ruby vim
    You also need
      gcc g++ make mingw-runtime subversion
    for compiling programs.

    The Cygwin installer will automatically get the required libraries for each package. This is very useful, but it also means that you may be downloading many more files that you had manually selected.


    Figure 2

    To determine the total number of files scheduled for downloading at any time, click through View (Figure 2: Select Packages) until the word Category changes to Partial. You will now see a list of the total number of files scheduled for downloading. This is also how you update packages: simply run the setup and select Partial — any updated packages will then be in view and you can proceed to download and install it.

    You should always select the default Cygwin installation settings, with C:\cygwin as the upper directory, assuming C is your drive letter. Once Cygwin is installed then you should run

      mkpasswd -l > /etc/passwd
    and
      mkgroup -l > /etc/group
    from the cygwin bash shell. If you are a domain user then you will need the -d switch as well.

    X-Windows

    Some users have the view that it is pointless to download and use the Cygwin X-Windows facility. You already have a windows management system so why import another one? However, I find X-Windows to be useful for running xpdf and xgraph. The former is better than an Adobe Reader for the simple reason one can write to an opened file, which, annoyingly Adobe will not allow, and the latter is useful to receive pipes from R or Perl.

    Cygwin X-Windows is also useful if you want to run more than one desktop. The easy way is to use the Cygwin Windowmaker package. However at this stage, you are probably better off installing a real unix operating system.

    Non-Cygwin Applications

    In my opinion, there are a number of applications, available as Cygwin packages, that nevertheless are better in their MS-Windows versions. For me, these include gvim, emacs and Ghostscript. I also prefer MikTeX to the TeTeX package available in Cygwin. An excellent alternative editor to gvim or emacs is Notepad++.

    It is best not to select the default location C:\Program Files when installing these non-Cygwin applications. Remember, Cygwin does not like spaces. I install my non-Cygwin programmes in a new directory C:\programs, making certain also to remove all spaces that may occur by default in the programme names.

    To get the fullest benefit of emacs, one should add the environment label Home and point it to your Cygwin home directory, e.g. C:\cygwin\home\username. In MS Windows XP, use System, which you will find under Control Panel, and select Advanced. Add the environment label to the User variables. THE FOLLOWING IS NOT REQUIRED UNDER THE LATEST CYGWIN (1.7.5). While at the Environment Labels, you should also add the environment label CYGWIN to the System variables and point it to server. This will be necessary if you wish to run Apache 2 (click here for more details).

    Running Active State Perl Within Cygwin

    If you use Active State perl instead of the cygwin perl package then you have the problem of being unable to run perl scripts from the shabang. To get round this, put this script - call it perl - in the /usr/bin directory of cygwin. The script points to your Active State perl executable C:\perl\bin\perl.exe. (Change it to suit your own path - if different.) You are now able to run perl scripts (with no extension to their filenames) from the perl shabang line #!/usr/bin/perl. Check out this example .bashrc file. Obviously, your configuration may be different.

    Running MikTeX2.7 Within Cygwin

    Care must be taken if you decide to run MikTeX2.7 (or 2.6 & 2.5) from a cygwin bash or xterm. By default, MikTeX2.7 installs into a directory whose name contains a space! Of course, cygwin does not like spaces in file or directory names. To get round this, change your MikTeX2.7 installation directory from its default position to a new position of C:\miktex2.7. Then put the MikTeX executables into your cygwin path - again check this example .bashrc file. This issue does not occur with the older 2.4 version of MikTeX.

    Calling latexmk Within Cygwin

    The MikTeX distribution contains a miktexmk executable in its bin directory. MikTeX also contains a miktex.pl perl script in path_to_miktex2.7\scripts\perl. Put this alias
      mklatex='/usr/local/bin/latexmk.pl'
    in your .bashrc file. You will now be able to run latexmk in a bash shell by typing “mklatex” or in a dos command-box by typing “latexmk”.

    Deleting Cygwin from Microsoft Windows XP

    The procedure depends on whether you have installed cygserver and openssh. These applications should first be stopped.

    1. Stop cygserver

    In a bash shell, enter:
      cygrunsrv -E cygserver
      cygrunsrv -R cygserver
    The first command stops the cygserver and the second commands removes the cygserver. Note, we are using the option -E and not -s to stop the application.

    2. Stop openssh

    In a bash shell, enter:
      cygrunsrv -E sshd
      cygrunsrv -R sshd
    The first command stops the ssh daemon and the second commands removes the ssh daemon.

    3. Delete the cygwin directory

    Depending on where you have installed cygwin (e.g. C:\cygwin) you can now manually delete the cygwin directory and all its contents from your hard drive.

    4. Remove any Environment labels

    These could include the system variable CYGWIN and user variable HOME.

    5. Delete Registry items

    Delete the two registry trees:
      HKEY_CURRENT_USER_Software_Cygnus Solutions
      HKEY_LOCAL_MACHINE_Software_Cygnus Solutions

    6. Delete sshd user

    This will only apply if you had installed openssh. In Start → Run type compmgmt.msc. Then delete the sshd user if it exists in System Tools → Local Users and Groups → Users.

    Change the Default Shell from Explorer to Blackbox

    Microsoft Windows Operating Systems (including Vista and Windows 7) use Explorer as the default shell (not to be confused with the file manager of the same name). The Explorer shell is frankly rubbish: it is notoriously heavy in the use of computer resources; it is often responsible for corrupted files, particularly on FAT32 systems; and to cap it all, it has a limited range of features. I recommend changing the default shell to Blackbox; in particular, to bbLean.

    Further Reading

    Although written for UNIX, almost all of this excellent tutorial is applicable to Cygwin.