Cygwin

From PeformIQ Upgrade
Jump to navigation Jump to search

References

* http://en.wikibooks.org/wiki/Cygwin 
* http://www.soe.ucsc.edu/~you/notes/cygwin-install.html

Notes for installing and using Cygwin.

Extracted from http://www.soe.ucsc.edu/~you/notes/cygwin-install.html

I use Cygwin for a lot of my work because my laptop is more versatile running Windows XP as its main operating system but I would still like to use Unix programs like X11, Emacs, LaTeX and gcc. The Cygwin X11 server also runs much faster than running X11 on VMware even though they are built from very similar X11 (XFree86 or X.org) sources. Also, SSH in the Cygwin environment is nearly identical to the way it is used on Unix, allowing me to use xterm and ssh instead of PuTTY, a fine SSH/terminal standalone application.

Updated: March 13, 2005

   * <#comment>Installing Cygwin on Windows 2000/XP
         o Quick Start
         o User name and the home directory
         o Installing more packages
         o Staying up-to-date (updating packages)
         o Cygwin quirks
               + Terminal program: setting the terminal type to TTY
               + Terminal program: using rxvt instead of command.exe
               + Line termination (end-of-line) characters: Unix (0x0A) vs. DOS (0x0D/0x0A)
               + Unix file mode bits/file permissions (chmod)
   * Using Cygwin with X11
         o Cygwin/X User's Guide
         o Using the X11 server (XFree86 or X.org) on Cygwin
               + Mouse
               + SSH X11 Forwarding: Using the DISPLAY environment variable
               + SSH X11 Forwarding: Why use "ssh -Y" instead of ssh -X"?
               + Automatically starting WindowMaker when executing the "startx" script
               + Integrating X11 windows with Windows windows
               + Switching between windows (shortcut)
         o Killing the X11 server (using XWin -unixkill/-nounixkill)
         o Other Useful X11 Applications
               + xterm (window title)
               + XWinClip
               + WindowMaker Dock Applications: CPU and Memory Monitor
   * Using Cygwin (Non-X11 Applications)
         o LaTeX
         o Emacs Spell Checking: aspell, an ispell replacement
         o rsync: staying in sync
         o Perforce
         o Jam
         o Launching or Opening Windows Applications from a Cygwin shell (e.g. Bash)
               + Cygstart
               + Explorer.exe
               + Aliases
               + ~/bin, PATH, and Soft Links
   * Top 10 Tips for Using Cygwin

Installing Cygwin on Windows 2000/XP - Quick Start

Basically here are the steps I used to get started:

* Prerequisite: Windows XP or Windows 2000
* Use the Quick Start Guide from the Cygwin web site or use my instructions here. These instructions are also useful.
* Create a directory where you want the entire installation. I chose to use C:\cygwin, a folder on the Windows boot disk. I will call this the Cygwin directory from now on. This will also contain the user home directories within it. You should be able to use either an NTFS disk or FAT32 disk.
* Download the setup.exe program from http://cygwin.com/ and place it in your Cygwin directory. This program is a simple installer and does not use the Windows XP "Add/Remove Programs" feature. So just put setup.exe in C:\cygwin and use it from there.
* Choose the Install from Internet option. This will download the pre-built Cygwin binary packages and cache them in a local directory on your hard disk. If you prefer, you can first download the binary packages and then install them later. In some cases
* Use C:\cygwin as your root (Cygwin) directory, install for All Users, and use Default Text File Type of Unix (which is the 0x0A line termination character instead of the Windows convention of using two characters, 0x0D 0x0A).
* Use C:\cygwin\Latest for the local package directory. This is a cache directory of binaries. You can always clean it out once you've installed a package.
* Use Direct Connection for the internet connection, unless you are required to use a proxy.
* Choose a Download Site. This is a sticky setting which you will see again if you run the program again. I initially selected the http://mirrors.rcn.net for no particularly strong reason. It has been reliable over the last couple years, so I'm continuing to use that. RCN is an large ISP/connectivity provider in the U.S. so they should be well-connected.
* Next, Select packages. The user interface is terse, but usually you use the Curr view which shows you the current packages that you have installed or elected to install. The next time you use the installer, like I do about once a month, you can upgrade the packages, in place, without disturbing your existing installation. The View button shows you alternative views. Click Partial to see what will be updated or installed. You can just click Next for the default set to get you up and running. This will not install commonly desired packages, such as the X11 server or Emacs.
* First, the binary packages will be downloaded from the internet. Next, each pre-built binary package will be installed into the Cygwin directory root (C:\cygwin). You can elect to Create Icons, but I usually get rid of it. The only front-end that I use is are C:\cygwin\cygwin.bat and C:\cygwin\usr\X11R6\bin\startxwin.bat. I created a shortcut to those scripts in my Windows XP Quick Launch bar.
* After the installation process completes (all packges are downloaded), start up using the Cygwin icon or cygwin.bat and you will see a Bash shell. The program will not appear in any of the Start menus listing programs, so put a shortcut there if you like.
* At this point you have a base Cygwin install which includes the Bash shell that will run in the Windows "Command" window, and a few other built-in commands.

User name and the home directory

Your home directory is different from the Windows My Documents directory and should be located in C:\cygwin\home\username. Your username is likely to have a space in it because XP will use "firstname lastname". You can usually use symbolic or Windows links (I'm not sure which) to get around this problem. After I discovered this quirk, I found out that it was better to first create a Windows XP user using a single name which is my preferred Unix login/home directory name without spaces. After the step of completing the Windows XP setup or adding a new Windows user was complete, I renamed my Windows user world-visible name to my full name. You can do this by going to Start>Control Panel>User Accounts>Change an account>Change my name.

I also created some symbolic links within Cygwin for often-used directories like this:

ln -s "/cygdrive/c/Documents and Settings/username/My Documents/" ~/My_Documents
ln -s "/cygdrive/c/Documents and Settings/username/Desktop" ~/Desktop
ln -s "/cygdrive/c/" /c

Installing more packages

The more elaborate installation involves adding the packages like emacs, X11, OpenSSH, etc.

   * Quit all existing Cygwin programs/shells (to make sure shared libraries are not in use).
   * Re-run setup.exe, select packages you would like to install, and then install them.

Staying up-to-date (updating packages)

I upgrade packages every two to three months when it is convenient. Sometimes bugs are fixed; less frequently, bugs are introduced for a short period of time. In general, small improvements are made all the time. I choose to upgrade when I have the time to make a quick backup and a possible (temporary) revert to known packages if I sense a problem.With the Cygwin installer use the "Partial" view to see what packages have been updated.

After you have upgraded your packages, you might find it useful to learn what has changed. You can find a Cygwin-specific README in /usr/share/doc/Cygwin. A simple command to see the most recent READMEs is

ls -lt /usr/share/doc/Cygwin | head

Or if you are an Emacs user,

emacs /usr/share/doc/Cygwin

and then press "s" to sort files by modification dates in the dired buffer.

If you are interested in reading notes from the original source package, they are usually included in the Cygwin binary packages. Typically you will need to first use the cygcheck command, find the package-specific README file and then locate the file manually. You might use something like this:

cygcheck -l packagename

Cygwin quirks

Some man pages are missing, for instance, "tar". I don't know where they are or why they don't get installed. Another friend of mine who has been using Cygwin for about as long as I have discovered the same but we never had time to figure out what to do to fix it.

Cygwin works pretty well. I have been doing lots of work on it as a client system instead of using a separate Linux or FreeBSD machine. One drawback is that you depend on the underlying file system, so sometimes there is behavior that is not like Unix. For intance, files often get created with "chmod 777" even though they are not executable and it's more reasonable for them to be 666 or 644.

I have not needed to build any programs from source, but the installer gives you the option to download and build them from source instead downloading and installing them as a pre-built binary package.

Terminal program: setting the terminal type to TTY If you are using Emacs in the clumsy Windows "Command" window (command.exe), you might benefit from setting the terminal type so that more control characters work. Do this by changing the startup script, cygwin.bat, to contain the following commands, setting the CYGWIN tty and binary modes. For example:

@echo off

C:
chdir \cygwin\bin

set CYGWIN=tty binmode
bash --login -i

Some answers can be found in [Google] Terminal program: using rxvt instead of command.exe Even better, if you would rather not use the TTY mode in the "Command" window (command.exe), you can use the rxvt VT102 terminal emulator.

To use rxvt for your terminal program for use with Cygwin simply do these steps:

   * install rxvt from setup.exe
   * copy the cygwin.bat startup script in your Cygwin root directory, e.g. C:\cygwin\cygwin.bat to C:\cygwin\cygwin-rxvt.bat
   * Make the following change to cygwin-rxvt.bat
@echo off

C:
chdir C:\cygwin\bin

set SHELL=/bin/bash
rxvt --loginShell -sr
#bash --login -i

You can set the font using the rxvt "-fn" option (see man rxvt) or change them on the fly using Shift-keypad-plus and Shift-keypad-minus.

To use the Windows clipboard with rxvt:

   * Click mouse button 2 pastes into the terminal
   * Press the Enter key on the numeric keypad.

This is a FAQ. You can search for the words cygwin.bat rxvt.

Line termination (end-of-line) characters: Unix (0x0A) vs. DOS (0x0D/0x0A) I prefer to use Unix line termination characters (LF/0x0A), also known as the newline character. This is a setup.exe configuration option. If you're using Unix-like tools and move files between your Cygwin directories and a Unix machine, keeping the Unix line termination characters is easier than dealing with the DOS convention (CR LF/0x0D 0x0A). If you need to view a Unix file on Windows, use anything but NotePad. WordPad works well. Use "unix2dos [--help]" or "dos2unix [--help]" to convert between the two formats. Also see Emacs Text Files and Binary Files or Emacs Specifying a Coding System. A good Windows editor that has little difficulty moving between different file formats (including comparing files with different formats) is the CodeWarrior IDE.

To change the current Emacs buffer to Unix (0x0A):

C-x f unix

To change the current Emacs buffer to DOS (0x0D/0x0A):

C-x f dos

Unix file mode bits/file permissions (chmod)

When files are created by Cygwin applications on an NTFS, they usually have the owner and permissions that you would expect. But if you create a file from a Windows program, data files will often have their "x" (executable) bits set even though they are not executable. Clearing the "x" bit (e.g. chmod -x document.txt) will fix the problem and leaving it that way does not seem to interfere with NTFS behavior. (This is most annoying when I accidentally check in source files with Perforce; the files have a type of "xtext" instead of "text".)

I haven't used Cygwin with FAT32.

Using Cygwin with X11

The rest of this document includes hints that come from an email I sent to someone else who set up their X environment. As of early 2004, there has been a number of small but significant changes to improve the X11 server.

Update (4/2004): The X11 server used on Cygwin is no longer XFree86; it is now based on the x.org sources.

Cygwin/X User's Guide This is a good guide from the Cygwin site. It probably has answers to most of your questions:

FAQ:

And there are probably others... [Google]

Using the X11 server (XFree86 or X.org) on Cygwin If you want to run programs remotely but display the user interface locally, then you would use this configuration: the X11 server runs locally, for instance on your Windows XP laptop running Cygwin, and the X11 client program runs remotely, for instance, Mozilla on Linux. Mouse I recommend using a 3-button wheel mouse. If your wheel works with Windows, it should automatically work with X11. Some applications like X11 Emacs might need a customized configuration.

SSH X11 Forwarding: Using the DISPLAY environment variable Programs running remotely but displayed locally will need to start up with an environment that includes the DISPLAY environment variable. This question is asked frequently. [Google]

Someone asked me:

> I have installed cygwin with all packages in my home machine.
> I got a few questions about the X:
>
> 1. I start the X by using command "startx". It works and shows
> a desk with several terminals. However, when I login in
> cse account and using xterm or gv, it says "Unable to open
> the display. How to config it?

When you say "login in a cse account" you probably are wondering how to use X11 forwarding so that you can view windows on your local (Cygwin) machine that is running its X11 server while executing the programs remotely on the remote Unix host. Normally you have to set up your DISPLAY environment variable so that the X client program (e.g. xterm/gv) knows which X11 server to use. You can use "export DISPLAY=my-windows-xp-hostname:0.0" if you use bash (or setenv if you use csh/tcsh). This can be a nuisance because you have to do this each time you log in on the cse machine.

Also, you must set up your X11 server to enable remote hosts, so you say "xhost +" (all machines can open a window on your server) or if you're more paranoid you can use something like "xhost + someworkstation.cse.ucsc.edu". I don't think it is necessary to be so specific so I just use the "xhost +" form.

When I work off campus I have to use ssh in order to connect to cse machines, so I use something like this:

cygwin> xhost +
cygwin> ssh -Y someworkstation.cse.ucsc.edu
someworkstation> xterm & # this opens a window on cygwin's X11 server

SSH X11 Forwarding: Why use "ssh -Y" instead of ssh -X"?

If you get an error message that says

X protocol error: BadWindow (invalid Window parameter) on protocol request 38

then read this part of the Cygwin/X Frequently Asked Questions ("X11Forwarding does not work with OpenSSH under Cygwin"). [Google]

Automatically starting WindowMaker when executing the "startx" script Before I started using the rootless version of X11, someone asked me about the X11 desktop I was using, i.e. with a root window that covered the entire Windows desktop. The standard X11 desktop is the same one that has been around ever since I can remember. It looked the same when I first used X11 on MicroVAX and Sun workstations as it does now. I used to use a "rooted" X11 with WindowMaker but today (summer 2004) the standard Cygwin version starts rootless by default. X11 rootless windows are each displayed as individual Windows (GDI) windows.

> 2. The default desk is ugly. What package are you using
> now? I remember it looks pretty good. Are there any window
> managers that can be used under cygwin? Or we need a special package
> for cygwin?

I agree, the default (rooted) desktop is ugly. I use WindowMaker... I used to use the default package for the WindowMaker window manager (desktop) It is available for installation if you run the Cygwin setup.exe program and here are instructions for using that window manager if you want to have an X11 desktop mode that you can switch in and out of. (Recently, I have switched to using the -multiwindow option, which implements X11 windows as Windows (Win32 GDI) windows.)

Once you install the package (binaries) you will either need to start wmaker. This is a simple startup script that will get executed as a side-effect of using the startx command:

create a file called ~/.xinitrc:

#!/bin/sh
exec wmaker

Then when you startx it will launch the WindowMaker desktop instead of fvwm (the default and antiquated X11 desktop).

The last thing I do is to use startx with the following server options: "-nowinkill -nodecoration". You might also consider '-rootless' or '-multiwindow' if you want to mix X11 windows with Windows 2000/XP windows.

To start with the options more easily, I use an alias which is set in .bashrc looks like this:

alias startx='startx -- -nowinkill -nodecoration'

You can find out more about the X11 server command line options under XWin.exe (this is the Windows-specific application binary that contains the XFree86 or x.org server). The man page can be viewed with the "man XWin" command.

I choose to use WindowMaker over KDE or Gnome because it is fast, lean, and does not require a lot of extra goofy libraries.

It took me a little while how to customize the WindowMaker desktop. There are a couple features that I find useful:

multiple desktops: use the icon in the upper left corner to switch back and forth or use "ctrl-alt-leftarrow" and "ctrl-alt-rightarrow"

If you like having some of the applications open when you launch the desktop, use the Workspace>Save Session command.

Integrating X11 windows with Windows windows

As of spring 2004, the "-multiwindow" option is now the default. You can see a screenshot here. This option should be the default now when you run startx or startxwin.bat. Make sure that you do not try to start another window manager in ~/.xinitrc. Also, remove any aliases that you might use to set the window options.

Switching between windows (shortcut)

Normally you can use the Windows Alt-Tab shortcut to switch between recent windows, including X11 windows (if you are using the rootless mode). Unfortunately you might not have enough context from the window title alone. See the section on setting your xterm window title to your current directory.

Better yet, the Windows XP Power Toy called "Alt-Tab Replacement" will let you see a small thumbnail image of the window (much like Command-Tab on OS X) . It works great with Cygwin/X11.

Killing the X11 server (using XWin -unixkill/-nounixkill)

By default, you can easily kill the X11 server by using Control-Alt-Backspace. Sometimes this is desirable behavior and other times the accidental keypress can terminate your session inadvertently. The XWin server behavior has changed during 2004 and -nounixkill may not do exactly as you would expect. It used to be that this would prevent the server from being killed. But the keypress can be intercepted by other layers separate from the X11 server. Searching for "xmodmap" and "keycode 22 = BackSpace" might be helpful: [Google].

My solution is to use the XWin command-line option, "-unixkill" instead of the default "-nounixkill". With the current rootless X11 server, when Control-Alt-Backspace is pressed, a dialog box will be displayed first, before killing the server. To set this up, modify the script that starts XWin to include "-unixkill" e.g.

/usr/X11R6/bin/startxwin.bat (or type which startxwin.bat to find this):

run XWin -multiwindow -clipboard -silent-dup-error -unixkill


Other Useful X11 Applications

xterm (window title)

The default window title is "xterm". If you are using the bash shell, add the following line to your .bashrc file. It will display username@hostname: /current/bash/directory instead.

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'

XWinClip

Another trick I use is to start "xwinclip" in an xterm if you want to copy and paste between X11 and Windows. It is not perfect but it works pretty well. (This feature is now built into the Cygwin/X11 server.)

WindowMaker Dock Applications: CPU and Memory Monitor

When I used WindowMaker for my desktop (before the rootless X11 server became very useful), I installed a couple dock applications that were useful, "wmcpuload" and "wmmemmon". These give you an idea of CPU and memory usage. I downloaded these in source form and used "make install" to build and install them.



Using Cygwin (Non-X11 Applications)

Cygwin has a lot of features and packages that make it useful as a substitute for a Unix or Linux environment. I have been using these tools to write papers and run experiments on my laptop. LaTeX Installing LaTeX on Cygwin can be slightly different from the site installations of LaTeX.

If you want to use TeX on Cygwin, it works great. Just install all of the teTeX packages. The only thing you need to do is to make sure you use the texconfig program and set up the paper size to be 'letter' otherwise you will end up generating pages that are 'a4' paper size.

At one time, I had trouble getting texconfig to work with the Cygwin terminal. This doesn't seem to be a problem anymore. Here's what I wrote:

Before starting texconfig, modify the script so that it will get the proper terminal capability information for our Cygwin terminal, called "cygwin". This is similar to vt100 and ansi but not the same.

> which texconfig # should be /usr/bin/texconfig > cp -p /usr/bin/texconfig /usr/bin/texconfig.dist > vi `which texconfig`

/usr/bin/texconfig:

  1. Add the following lines before "progname=`basename $0`":

DIALOG_TERM=${TERM:-unix} DIALOG_TERMINFO=${TERMINFO:-/usr/share/terminfo}

This hint was gleaned from

Emacs Spell Checking: aspell, an ispell replacement

I use the "ispell" spell checker on other platforms, but it is not available as a binary package. Instead, I use "aspell" on Cygwin, an easy-to-install replacement. From http://aspell.net/man-html/manual.html

"The easiest way to use Aspell with Emacs or Xemacs is to add this line:


   (setq-default ispell-program-name "aspell") 

to the end of your .emacs file."

rsync: staying in sync

I use the rsync program to keep a local directory containing HTML in sync with a remote machine's directory (~/.html) that is readable from a web server. My local directory name is ~/www. My remote directory name is (~/.html) I use the following command to sync to the remote directory:

alias rsync-get-www='rsync -avuz -e ssh --delete xxxx.cse.ucsc.edu:/csl/grads/you/.html/ /home/you/www/'

and the following alias to sync from the remote directory to my Cygwin directory:

alias rsync-put-www='rsync -Cavuz -e ssh --delete /home/you/www/ xxxx.cse.ucsc.edu:/csl/grads/you/.html/'

With my Cygwin copy being the master, I copy up my local changes to the remote by using "rsync-put-www". If I make changes remotely, I use "rsync-get-www". I use the "--delete" option which will force deletion on the destination directory. You might not want this type of behavior. Read the rsync man page to understand how this works.

Perforce

I use the command-line version of Perforce ("p4") with Cygwin. I have found it best to keep Perforce clients on Cygwin separate from Perforce clients on Windows. The reason is that the Unix-like tools work best on Cygwin and Windows-like tools work best on Windows. More importanly, there are a couple problems that make life difficult if you try to switch between tools in the two environments on a regular basis:

   * Cygwin paths, which you need to specify in your Perforce client spec, will not work if you use P4Win on Windows; the two are non-interoperable.
   * P4Win and other Windows development tools like to use Windows line termination characters (0x0D/0x0A). The p4 command and Unix development tools like Unix line termination characters (0x0A). For Cygwin clients, setting the "LineEnd: unix" field will cause text files to be synced to your local client with the Unix convention.

Jam

Jam, a free make replacement tool from the people at Perforce, is a great program that works well in multiple environments. There might be pre-built binaries available, or you can build it from source code. Building Jam on Cygwin

These instructions are for p4 (Perforce client) users:

   * Using p4, sync to the public.perforce.com server, getting the source from //public/jam/src/...
   * cd into the src directory
   * Keep a copy of the original Makefile (cp -p Makefile Makefile.dist)
   * Make your Makefile writeable (chmod u+w Makefile)
   * Uncomment the "CC = gcc"; "CFLAGS = -D__cygwin__" flags (per README).
   * make
   * install jam somewhere, e.g. cp -p bin.cygwinx86/jam.exe ~/bin/jam.exe

If the bin.cygwinx86 directory was not created, then it means your version is not built specifically for the Cygwin environment. The Jam tool will still work, but it will not be aware of some idiosyncracies of Cygwin.

Using Jam on Cygwin To test for the Cygwin platform in a Jamfile, test for $(OS) = CYGWIN. The following example says to use "g++" as the linker which seems to be necessary for linking C++ programs.

if $(OS) = CYGWIN
{
LINK = g++ ;
}

Note that $(UNIX) is true, but $(NT) is not. You can verify which OS is set by Jam by using the -d 7 command-line option. If it says UNKNOWN then the version you are using is not aware of the Cygwin environment and it can lead to strange problems with $(SUFEXE) not being set.

Linking with Cygwin/cc (ld), produces files with .exe suffixes. You can set the SUFEXE explicitly:

SUFEXE = .exe ;

and then make sure to set the list of libraries against which to link in this manner (assumes HelloWorld is C++ and uses the crypto library):

LINKLIBS on HelloWorld$(SUFEXE) += lstdc++ -lcrypto ;

I found a bug in Jam that prevented Cygwin libraries from being re-linked property. When a single object file changed, the entire library would be recompiled even though all of the other object files worked. The Perforce change on the public depot is here. As of 2005-03-13 it had not been integrated into the main line. Launching or Opening Windows Applications from a Cygwin shell (e.g. Bash) There are a few ways to start Windows applications from a Cygwin shell. I prefer the "cygstart" method but experimented with the others until I learned about the command. Cygstart If you want to open a document, use cygstart documentname.extension for example, cygstart 'User Guide.pdf'

For cross-platform compatibility with Mac OS X which has an "open" command, put this into your .bashrc:

alias open='cygstart'

Explorer.exe Another method is to let the Windows Explorer program, explorer.exe, try to open your files. For instance, explorer 'User Guide.pdf' or explorer.exe 'User Guide.pdf' will work. This does not seem to work as well if the application (such as Acrobat Reader) is already running. Aliases Another way to run a program is to just use an alias to the application. From Bash you might use something like this:

alias acroread='/cygdrive/c/Program Files/Adobe/Acrobat 6.0/Acrobat/Acrobat.exe'

This is obviously awkward.

~/bin, PATH, and Soft Links

To add ~/bin to your command path, in ~/.bash_profile (or ~/.bashrc, depending on how you have this set up):

export PATH=$HOME/bin:$PATH

Then make a soft link to your program:

ln -s '/cygdrive/c/Program Files/Adobe/Acrobat 6.0/Acrobat/Acrobat.exe' ~/bin

Top 10 Tips for Using Cygwin

Here's a list of tricks and tips for using Cygwin.

  1. Backup your home directory. The only data that I need to backup is my personal home directory. I do not keep any customizations outside of /home. Your mileage may vary.
  2. Keep a copy of your Cygwin binary packages handy. I store the setup.exe installer and binary packages in "C:\Cygwin\INSTALL". Before a big Cygwin upgrade I make a temporary copy of this directory in case I have a problem with the latest set of packages. Because the packages are not archived on the internet the way you might find FreeBSD packages or Linux RPMs, keeping a set of known binaries is a good way to ensure that you can go back to a working environment if your install fails or there is a package that is not working. My INSTALL directory is less than 300MB, making it very easy to archive (copy) onto a CD-R.
  3. Upgrade regularly, but not too frequently.
  4. Use Unix line termination characters (LF/0x0A).
  5. Use rxvt. It is a better console than the Windows "cmd.exe" terminal window.
  6. Use X11. I find it easier to use graphical programs like xterm and (X11) emacs.
  7. Use SSH. The OpenSSH package for Cygwin is virtually the same as the ones used on Unix. It includes features such as port forwarding (set up a port on the host named "localhost" and tunnel to a port on a remote secured host for HTTP, POP3, IMAP, SMTP, or other services that are only available on the other side of a firewall) as well as X11 forwarding.
  8. Customize X11 applications. For xterm, I like having a scroll bar. So I use "alias xterm='xterm -sb'" in .bashrc. Set up the latex paper size correctly.
  9. Put ~/bin in your path. If you are building programs from source locally, try to install them into ~/bin and add it to your path. By not installing into /bin, /usr/bin, or even /usr/local/bin, I don't have to worry about backing up those directories.
 10. Use rysnc to stay in sync. Keep a copy locally and update to a remote Unix site.


You at cs.ucsc.edu

 http://www.zieg.com/faqs/cygwin/


Mark's Cygwin FAQ

   * Installation
         o How do I install Cygwin on a networked computer?
         o How do I install Cygwin on a NON-networked [for instance, classified] computer?
         o Why am I called "Administrator"?
         o I just installed Octave, and now my Cygwin's hosed\! 
   * Usage
         o What's this Bash thing I keep hearing about?
         o How do I [...] in vi?
         o How do I find out what packages are installed, etc?
         o How can I make csh my default Cygwin login shell? 
   * Display
         o Windows/Cygwin telnet bites. Is there anything better?
         o This dinky 80-col DOS window is crap. How can I improve it?
         o This still isn't as good as a real X terminal. Why can't I just run X?
         o Okay, X is too much. I don't need the overhead. Can I just run an X-like terminal window, but not X itself? 
   * Other Sources of Information 

Installation How do I install Cygwin on a networked [internet] computer?


   The online installer is pretty much automated.
   If you are on an NT Domain (as is the case for all unclassified LM computers, for instance), then you should furthermore see the section on Cygwin and NT Domains.
   Improve your classified Cygwin installation by properly configuring bash and rxvt\! 

How do I install Cygwin on a NON-networked [for instance, classified] computer?


      1. Make an install CD on an unclass box
            1. Use IE to go to cygwin.com, and pick "Install Cygwin Now\!"
            2. Save setup.exe to your local hard drive (I put mine in ./My Documents/Received/Apps/Cygwin)
            3. From Windows Explorer, run Setup.exe
                  1. On the welcome screen, note the version number in case of problems (these docs were written for Cygwin Setup ver. 2.249.2.5), then click "Next-->"
                  2. On the screen titled "Choose a Download Source" (which should have been labeled, "Choose an action"), select "Download from Internet" then click "Next-->"
                  3. On the screen titled "Select Local Package Directory", the default should be the same directory holding setup.exe. Accept the default, then click "Next-->"
                  4. On the screen titled "Select Your Internet Connection", select "Use IE5 Settings", then click "Next-->"
                  5. On the screen titled "Choose A Download Site", pick any mirror you like (I like to hammer [1]), then click "Next-->"
                  6. On the screen titled "Select Packages", pick what you like. I typically select something like the following:
                         * devel
                               o gcc
                               o cvs
                               o make 
                         * doc
                               o cygwin-doc 
                         * editors
                               o vim 
                         * graphics
                               o opengl 
                         * interpreters
                               o perl 
                         * Net
                               o inetutils
                               o openssh 
                         * Shells
                               o rxvt 
                         * Utils
                               o bzip2
                               o patch 
                         * XFree86
                               o XFree86-base 
                     then click "Next-->"
                  7. At the dialog "Download complete", click [OK]
                  8. Setup should now exit 
            4. At this point, three things will be different about your computer:
                   * You will now have a directory populated with Cygwin installer stuff (in my case, ./My Documents/Received/Apps/Cygwin), which should be around 50MB.
                   * Your registry, should you care to check (don't bother), will have some empty "Cygnus Solutions" nodes. These could be deleted with no effect (but don't bother).
                   * You will have a C:\cygwin directory, which will contain nothing but some /etc/setup log files. This is not a working Cygwin installation (you haven't actually installed Cygwin yet, only downloaded the pieces-parts), and could be deleted at this point with no effect (but don't bother). 
            5. Burn your Cygwin installer directory (./My Documents/Recieved/Apps/Cygwin, or wherever your setup.exe is) to a CD-ROM.
                   * Before burning the CD, you may wish to drag other files on there as well, such as any custom Cygwin files you'd rather not have to manually recreate on the target machine(s), like your .bash_profile, .vimrc, .Xresources, etc.
                   * I use Adaptec Easy CD Creator 4 ("data CD"), and simply drag my desired folder into the CD layout window, click "Create and Close CD", and I'm done.
                   * Adaptec Easy CD Creator gives me a warning dialog saying that I have a directory titled something like "ftp%2F%3A%3Amirrors.rcn.net%3A/blah-blah-blah" needs to be renamed according to Joliette naming standards, or something. I renamed that directory, using the dialog provided, to a simpler "mirrors.rcn.net" and had no further problems. 
            6. Once the CD-ROM is burned, closed, confirmed, and virus-checked, set it aside. You should be able to use it on your classified machine (later). 
      2. Use the CD to install on a classified box
            1. Take the CD-ROM to the classified computer
            2. copy the directory containing setup.exe, and it's contents, to the local [classified] hard drive
                   * I used "C:\downloads\cygwin", for no particular reason
                   * It may be possible to run the installer from the CD. I wasn't immediately successful with that approach, and didn't bother finding a way to make it work. 
            3. run setup.exe
            4. On the welcome screen, click "Next-->"
            5. On the screen titled "Choose a Download Source", select "Install from Local Directory", then click "Next-->"
            6. On the screen titled "Select Root Install Directory", I recommend accepting the default (C:\cygwin), then click "Next-->".
            7. On the screen titled "Select Local Package Directory", the default should be the same directory holding setup.exe. Accept the default, then click "Next-->"
            8. On the screen titled "Select Packages", observe the following procedure:
                  1. Next to the top-level category "All", locate a little loopy-loop icon.
                  2. Click it once
                  3. hold your breath for 15-30 seconds
                  4. all categories should change to "Install"
                  5. Click "Next-->" 
            9. When the installation process is done, click "Finish".
           10. A whole bunch of empty black rectangles will flash across the screen. This is apparently normal. The longer they flash, and the more of them you see, the better a chance that you have a successful installation :-)
           11. Test your local Cygwin install by running C:\cygwin\cygwin.bat (or any of the various links and icons to that file). 
      3. improve your classified Cygwin installation by properly configuring bash and rxvt\! 

Why am I called "Administrator"?

   Cygwin has a very messy relationship with NT security. The simple fact is that NT security is very different from Unix security, and a one-to-one mapping just isn't possible. Cygwin does the best it can. You can explore the details if you wish.
   First of all, be assured that whatever Cygwin may call you, you are not logged in as administrator, and have no access rights beyond what you had before you installed Cygwin. Still, if you leave yourself logged on with an incorrect username such as "administrator", you'll have all kinds of problems using chmod and other tools. Moreover, even the label of "administrator" is disconcerting to many admins, so it's best to fix it using the process outlined below.
   Therefore, if you are on an NT Domain, such as is the case for all LM PC's on the unclassified network, then you must make an extra few steps when installing Cygwin to manually map your login rights.


      1. Install Cygwin as described above
      2. "launch" Cygwin (open a bash or tcsh shell)
      3. add the variable "CYGWIN=ntsec" to your environment, using either:
             bash $ export CYGWIN=ntsec 
         or
             csh % setenv CYGWIN ntsec 
      4. Type these commands to configure your /etc/passwd:
             mkpasswd \-l > /etc/passwd
             mkpasswd \-u username \-d domain >> /etc/passwd 
      5. logout from Cygwin (ctrl-D usually works)
      6. open a new Cygwin shell and make sure you're no longer called "Administrator":
             $ echo $USER 
      7. add the above "CYGWIN=ntsec" command to your permanent .bash_profile or .cshrc, if you haven't already done so 
   In the second call to mkpasswd, above, use the username and domain name you use to log into Windows PC. For me, that's "ziegm" and "ACCT03". For many LM employees, their username will be the same as their badge number. Also, do not reverse the order of the "-u username" and "-d domain" options\! Positional sequence matters in that case, unfortunately.
   As far as I know, if your PC is not on an NT domain, you do not have to do these steps. In particular, that means that this section does not apply to many classified PC's, which are often not connected to NT domain controllers. 

I just installed Octave, and now my Cygwin's hosed\!

   Yeah, it does that. Just re-run the Cygwin setup.exe program, and manually replace the "C:\Program Files\Octave" path (or whatever) with C:\cygwin (or wherever you put your Cygwin).
   Apparently Octave overwrites some Cygwin registry key or other, and makes Cygwin think its "root" is under Octave. Once you fix the Cygwin path, both programs continue to work correctly (AFAIK). 


Cygwin Usage Windows/Cygwin telnet bites. Is there anything better?


   Absolutely. I can't stand them myself. All kinds of buggy issues with changing window size, vi sessions getting scrambled formatting, etc.
   I use PuTTY, from [2]. It's free, it does SSH as well as telnet (if you're into that), it lets you resize windows easily, lets you configure meta-keys for those apps that use them...it's pretty darn good.
   About the only terminal apps that I might prefer to Putty are CRT and SecureCRT from VanDyke ($35 and $99, respectively). Still, PuTTY is PlenTY good enough for government work, as it were :-) 

I understand that 'bash' is becoming a default on many platforms from Linux to Cygwin, and I have decided that I need to use it more to learn about it. How do I set it up so I can start working productively?

   Here is my Cygwin .bash_profile, as a start (Linux users can check \~mzieg/.bash_profile on cvs-oa for an almost-identical Linux example)...
   # .bash_profile
   # set colors and prompt
   export PS1="\[\e\]2;peter:\w\007\e\[1;36m\]peter \[\[\e\[1;35m\]\w\[\e[1;36m\]] \u $ \[\e\[1;33m\]"
   # configure history editing
   set \-o vi
   export HISTSIZE=1000
   export HISTFILE=~/.history
   export HISTFILESIZE=1000
   export EDITOR=vi
   # set aliases for colors
   alias vi=vim
   alias dir='ls \-lav \--color=auto'
   # winshit
   export CYGWIN="ntsec"
   # display
   # export DISPLAY=localhost:0
   # place nice
   umask 022
   # cvs
   export CVSROOT=":ext:mzieg@cvs-oa.orl.lmco.com:/usr/local/cvsroot"
   export MAKEFLAGS="--no-print-directory"
   # construct path
   unset PATH
   for i in                \
   \~/bin               \
   /bin                \
   /usr/bin            \
   /usr/local/bin      \
   /sbin               \
   /usr/sbin           \
   /usr/X11R6/bin      \
   /cygdrive/c/WINNT/MS/SMS/CORE/BIN           \
   /cygdrive/c/WINNT/system32                  \
   /cygdrive/c/WINNT                           \
   /cygdrive/c/WINNT/System32/Wbem             \
   /cygdrive/c/Program\ Files/Support\ Tools   \
   /cygdrive/c/NTRESKIT                        \
   /cygdrive/c/stuff                           \
   /cygdrive/c                                 \
   /cygdrive/c/S11/DLL                         \
   /cygdrive/c/MMCSW/BISNET
   do
   if \[ \-d "$i" \] ; then
   if \[ \-z "$PATH" \] ; then
   PATH=$i
   else
   PATH="$PATH:$i"
   fi
   else
   echo "Warning: can't append $i to PATH because it doesn't exist."
   fi
   done
   export PATH
   # PRISM variables
   export DATA_HOME=~/PRISM/BaseData
   export MAKE_HOME=~/PRISM/BasePrograms
   export PATH="$PATH:$MAKE_HOME/config/bin:$MAKE_HOME/config/cygwin/bin"
   And just to complete the magic, here's the corresponding \~/.vimrc to make text editing every bit as enjoyable as command-line navigation :-)


   set autoindent
   set softtabstop=4
   set tabstop=4
   set shiftwidth=4
   set showmatch
   set ignorecase
   set background=dark
   set hlsearch
   set incsearch
   set number
   syntax on
   # only set this last one if you understand the implication re: Makefiles\!
   set expandtab

How do I [...] in vi?

      1. vim (Vi IMproved) is available under Linux, Cygwin, SGI, and Solaris, so why not use that instead?
      2. there are some great vim docs here:
             * pdf docs
             * online docs
             * FAQ 

How can I make 'csh' my default Cygwin login shell?

   Don't bother editing /etc/passwd and changing your "login shell" to /bin/tcsh; it doesn't work :-)
   Instead, use the Windows Notepad (or Textpad, or whatever) to create the following file, called "tcsh.bat", in C:\cygwin:
   @echo off
   c:\cygwin\bin\tcsh \-l
   This will be analogous to the default C:\cygwin\cygwin.bat, which basically does the same thing to launch the bash shell. Why not simply edit cygwin.bat and point it to tcsh instead? You can try that, but it may not be preserved between Cygwin updates/reinstalls/package additions, etc.
   Then you'll need working .cshrc and .login files in your home directory. Here are working samples:
   # .cshrc
   \#
   # this file gets executed with every subshell
   # is this an interactive shell?
   if ( $?prompt ) then
   # yes, we're in an interactive shell
   # prompt
   set prompt = "%
   {\033[1;36m%}peter %{\033[1;35m%}[%~] %{033[1;36m%}
   }%n %%
   {\033[1;33m%}
   "
   # history
   set history         = 1000
   set savehist        = 1000
   set EDITOR          = vim
   set filec fignore = (.o)
   # cmd-line bindings
   bindkey \-v          ; # use vi key bindings
   # display
   set DISPLAY         = localhost:0
   # cvs
   # set MAKEFLAGS     = "--no-print-directory"
   set CVSROOT         = :ext:mzieg@cvs-oa.orl.lmco.com:/usr/local/cvsroot
   # aliases
   alias vi            vim
   alias dir           'ls \-lav \--color=auto'
   alias nslookup      host
   endif
   # .login
   \#
   # this file gets executed ONCE when the user first logs in
   # construct path
   setenv PATH "~/bin"
   foreach i (             \
   /usr/local/bin      \
   /usr/bin            \
   /bin                \
   /usr/sbin           \
   /sbin               \
   /usr/X11R6/bin      \
   )
   if ( \-d "$i" ) then
   if ( \-z "$path" ) then
   setenv PATH $i
   else
   setenv PATH $
   {PATH}
   :$i
   endif
   else
   echo "Warning: can't append $i to PATH because it doesn't exist."
   endif
   end
   # terminal options
   stty \-istrip            ; # allow 8-bit chars for input
   # share our files with the group
   umask 002
   (I'll give a nickle to whomever can explain why that gives a "grep not found" message whenever I login :-) 

How do I find out what packages are installed, etc?

   Play with 'cygcheck \-c' (see 'cygcheck \--help' for options) 

Cygwin Display

This dinky little 80-col DOS window is crap. How can I improve it?

   Yes, you're running bash or tcsh, and thus your commands are being interpreted by a Unix shell, but the window containing the shell remains nothing more than a DOS window. Microsoft never provided much in the way of widgets and controls to those windows, and it can feel a little cramped.
   Before you settle on the following tips for improving the DOS window, you may want to replace it altogether using the built-in X Server, complete with xterm, or just run rxvt without the overhead of X. However, any of the three options will work fine for most people. It's all a matter of preference.
   To make the DOS window wider:
      1. Open a Cygwin window
      2. Right-click on the title bar
      3. Choose "Properties"
      4. Select the "Layout" tab
      5. Edit the Screen Buffer Size and Window Size with better values (these are what I use):
             * Screen Buffer Width: 100 or 120
             * Screen Buffer Height: 3000 (RAM is cheap)
             * Window Size Width: 100 or 120
             * Window Size Width: 50 (or whatever) 
      6. When you click "OK", select "Modify shortcut that started this window". Then your settings will be used for all subsequent Cygwin invocations. 
   To pick a better font (the default is fuggly):
      1. Follow most of the instructions for resizing the window above, then...
      2. Select the "Font" tab
      3. Pick whatever you want (I like Lucida Console 14pt) 

This still isn't as good as a real X terminal\! Why can't I just run X?


   You can\! If you've installed the recommended PRISM developer Cygwin package set, then you can already start a minimal X-Windows GUI just by typing "startx".
   However, it's ugly and only barely functional. For a more aestheticly pleasing and practical configuration, I suggest you follow a variant of these steps:
      1. add relevant Cygwin/XFree86 packages:
             * Shells
                   o rxvt 
             * XFree86
                   o fvwm (this looks way better than the default window manager\!)
                   o Xaw3d
                   o XFree86-doc
                   o XFree86-man (to help you find your way around)
                   o (I don't know how important these are, but I also have libPropList, openbox, and WindowMaker, plus XFree86-fenc, \-fnts, \-fscl, \-fsrv, \-lib, \-prog, \-startup-scripts, and \-xserv) 
      2. create an .xinitrc file in your Cygwin home directory, like this:
         \#\!/bin/sh
         userresources=$HOME/.Xresources
         usermodmap=$HOME/.Xmodmap
         sysresources=/usr/X11R6/lib/X11/xinit/.Xresources
         sysmodmap=/usr/X11R6/lib/X11/xinit/.Xmodmap
         # merge in defaults and keymaps
         test \-f $sysresources   && xrdb \-merge $sysresources
         test \-f $sysmodmap      && xmodmap $sysmodmap
         test \-f $userresources  && xrdb \-merge $userresources
         test \-f $usermodmap     && xmodmap $usermodmap
         # spawn x
         fvwm2 &
         exec xterm \-geometry 120x30
      3. create an .Xresources file in your Cygwin home directory, like this:
         XTerm.VT100.font: *-\-lucidatypewriter-medium{-}{*}{-}14-\*
         XTerm.VT100.boldFont: *-\-lucidatypewriter-bold{-}{*}{-}14-\*
         XTerm.VT100.scrollBar:      True
         XTerm.VT100.visualBell:     True
         XTerm.VT100.loginShell:     True
         XTerm.VT100.background:     Black
         XTerm.VT100.foreground:     White
      4. run "startx"
      5. right-click in the gray desktop background
      6. select "2. Setup Form" from the "Builtin Menu"
      7. put "X"s in every checkbox, then click "F2 - Copy Config File(s)" and finally click "F3 - Restart fvwm" 
   Now, whenever you type "startx" from a Cygwin window, you'll get a full X-Windows display, more-or-less comparable to what you're accustomed to on "normal" Unix systems like SGI & Solaris.
   If you want to adjust the fonts to whatever suits you, type "xfontsel" (from within X Windows) to launch a graphical font selector. After you find a font/size combination that works for you, edit your .Xresources file to configure xterm (or whatever) to use it. 

Okay, X is too much. I don't need the overhead. Can I just run an X-like terminal window, but not X itself?


   It turns out that this too is possible :-)
   If you've installed the rxvt package, you can run it from Windows without having a full X-server running, as long as you don't have a DISPLAY variable set in your environment.
   Suggested procedure:
      1. Create an \~/.Xresources file like this:
         \! rxvt.font: *-\-lucidatypewriter-medium{-}{*}{-}14-\*
         \! or...
         rxvt.font:            Lucida Console-14
         rxvt.boldFont:        Lucida Console-14
         rxvt.scrollBar:       True
         rxvt.visualBell:      True
         rxvt.loginShell:      True
         rxvt.background:      Black
         rxvt.foreground:      White
         rxvt.saveLines:       3000
         rxvt.cursorColor:     Green
         rxvt.scrollBar_right: True
      2. create a shell script like this one, so that you can pop up a new window whenever you want from within an existing shell:
         # \~/bin/win
         unset DISPLAY
         rxvt \-e bash \-login &
      3. create a DOS batch file like this one, so you can likewise create a new window by clicking an icon from Windows:
         @echo off
         REM place in C:\cygwin\rxvt.bat and put
         REM a shortcut on the desktop :-)
         c:\cygwin\bin\rxvt \-e /bin/bash \-login

Other Sources of Information

       * O'Reilly Unix Bookshelf
       * Cygwin
             o manual (not very good)
             o faq (okay)
             o list archives (searchable\!)
             o web newsgroup interface
             o usenet interface