perm url with updates: Installing Cygwin Tutorial
Installing Cygwin Tutorial
Xah Lee, 2009-06-03
This page is a short guide on installing Cygwin on Windows (Vista), based on my personal experience, and some commentary.
Cygwin Base Installation
First, download the cygwin installer “setup.exe”.
Run it. Accept the default parameters, unless you really have a need to change things.
When in the dialog to choose what programs to install, simply accept the default. Once you done installation of the base packages, you can come back to it and install other packages you need. If this is your first time, i highly recommend you follow this.
The above should be smooth. When finished, you can test run cygwin by clicking the icon on desktop, and the cygwin terminal should come up. That means bash is running, and you've installed cygwin successfully.
Installing Packages You Want
Now, find out what other programs you need. For example, cygwin does not install ssh by default. Let's say you want to install ssh.
Run “setup.exe” again. Accept the same defaults, in particular, try to stick with the mirror site you used before.
The installer may give you a warning: “This setup.ini is older than the one you used last time you installed cygwin. Proceed anyway?”. When this happens, be very careful. I accepted it a few times that resulted in reinstalling lots of packages, and that often screwed up things that i ends up deleting the whole cygwin dir and reinstall everything. (The warning is very ambiguous. It is not clear which setup.ini it is talking about. If it means the one from the mirror site, then of course it will be older than the one on my harddrive. If it means the file on my harddrive is older than the one on mirror site, then, it is not clear why should i care. It does not point out what setup.ini is doing or how it is used, or if installer is relying on the one on my drive or the mirror site, or if the installer is going to do a copy from the mirror site to my disk then use the one on my disk. I can't see how useful this warning is.)
Here's what to do when the Select Packages dialog comes up.
The Select Packages dialog in Cygwin installer.
The Select Packages dialog has a very confusing interface. To understand it, first, understand about the check boxes (shown as “n/a” by default). For each program, there are 2 check boxes. One is for installing binary, the other is source. When a check is marked, that means you are telling cygwin to install that package. To toggle the checkbox, you have to click on that circular arrow icon to the left of the “Skip” or “Keep” word. (i'll call it the “cycle” icon)
Here's how the cycle icon works. Click it does several things, and what it does depends on whether you already have that package installed.
For packages you have already installed, it shows “Keep” by default. Clicking on it cycles you thru “Keep”, “‹version number›”, “Reinstall”, “Source”, “Uninstall” options, and will toggle the checkboxes if apropriate.
For packages you have not yet installed, it shows “Skip” by default. Clicking on it cycles you thru “Skip”, then older version, then other older versions if available, then back to “Skip”, and each click update the checkboxes as appropriate.
It does not hurt to click the cycle icon, but you have to be careful, because if you click without paying good attention, you may get yourself installing older version, or uninstalling your software. If you made too many clicks and you forgot what is the original, you can click on Cancel button to exit the installer and restart again.
There are also some view options at the top. The interface is badly designed in that it is very confusing. I recommend not to use it unless you know Cygwin well. If you did click it just for curiosity, make sure at the end you don't have all checkboxes in your packages. Otherwise, you might restall the whole of cygwin.
(WARNING: When you run the “setup.exe”, best to quit any cygwin processes you might have running, because that might interfere with install when the installer wants to access the same files or dll. Also, be sure you didn't by mistake have the checkbox on for all your installed packages. If you do, it'll reinstall all your packages, which may run into problems if you have ran cygwin in your Windows session. Because, for example, the installer may tell you: “Unable to extract /usr/bin/cygiconv-2.dll -- the file is in use.”. The dll is a library, so you can't really quit it. When this happens, cancel the installation. Then, start setup again.)
This installer name “setup.exe” is very stupid. It is a generic name, doesn't indicate what program it is a setup for. They should at least put cygwin into the name, so it is easy to identify.
Also note, the installer first download the packages, then install them. The downloaded packages are all kept in a dir that you specified in the installer. You can view these with Explorer. For example, on my machine the path is: “C:\Users\xah\Downloads\http%3a%2f%2fwww.goh4.com%2fcygwin%2f”. (note the unreadible percent signs there.) You should not delete this folder, because when you install things again, it may need some packages you've already installed, saving you the time to download them all again.
To uninstall cygwin, you can simply delete the whole cygwin dir. On my machine, it's “C:/cygwin/”. (make sure you quit all cygwin processes first)
Some Notes About Using Cygwin
Some random notes to myself about using cygwin.
Cygwin and EmacsW32
If you are using emacsW32, then you can go to the cygwin shell by calling the command cygwin-shell. First, you need to set the cygwin-shell path. This you can do by pulling the menu under “Options‣Customize emacsW32”. Or, you can put the following line in your .emacs: “(setq w32shell-cygwin-bin "C:\\cygwin\\bin")”.
Once you have the w32shell-cygwin-bin set, the command “shell” will also invoke cygwin-shell. If you want run plain Windows's “cmd.exe” shell, you can call cmd-shell. EmacsW32 also has msys-shell, which is for those who are using MinGW.
Note, when using cygwin shell in emacsW32, if the $PATH env var is not set correctly, it can cause Window to mistakingly popup a dialogue saying some program crashed. For a example, see: http://xah-forum.blogspot.com/2009/06/cygwinimagemagickemacsw32-causes-vista.html.
To fix shell env var in emacs, you can use the following:
(when (string-equal system-type "windows-nt") (setenv "PATH" "/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin") )
To do: find out how emacsW32 inherit its shell env var from cygwin. Is it from “c:/Users/xah/.bash_profile”?.
PATH environment variable
It is important to set the $PATH Environment variable correctly.
In cygwin terminal, my $PATH env var by default is:
/usr/local/bin /usr/bin /bin /usr/X11R6/bin /cygdrive/c/Windows/system32 /cygdrive/c/Windows /cygdrive/c/Windows/System32/Wbem
By default it also has these:
/cygdrive/c/hp/bin/Python /cygdrive/c/Program Files (x86)/ATI Technologies/ATI.ACE/Core-Static /cygdrive/c/Program Files (x86)/QuickTime/QTSystem/
that comes after the Wbem. I'm sure they are no good.
- Find out what's the “C:/Windows/System32/Wbem” is for. Consider removing it from my path.
- Study what “C:/Windows/system32” and “C:/Windows” are good for. Probably ok.
- Find out how cygwin by default set the $PATH env var. Note that some path i had in my default is prob bad, such as the HP and ATI and QuickTime stuff.
Cygwin Path Issues
The filename path issue between unix and Windows can be complex.
In general, i think, when you are in cygwin, always use path of this style: “/something/something”. When you need for example “C:/Users/mary/notes.txt”, use “/cygdrive/c/Users/mary/notes.txt”.
For example, when i started to use cygwin, had a problem that caused me few hours. I have a python program that makes a system call of imagemagick's “convert” command. This all works fine in OS X. When trying to run it on Windows with cygwin, i simply changed the input paths from “/Users/xah/web/” to “C:/Users/xah/web/”. This does not work. After some hours of looking, here's some detail:
When in cygwin terminal, the following does not work:
# cygwin complains cannot find the second file # convert: unable to open image `/Users/xah/x2.jpg': No such file or directory. convert C:/Users/xah/x.png C:/Users/xah/x2.jpg convert "C:/Users/xah/x.png" "C:/Users/xah/x2.jpg" # complains cannot find the first file convert /Users/xah/x.png ~/x2.jpg convert "C:/Users/xah/x.png" /Users/xah/x2.jpg convert /Users/xah/x.png /Users/xah/x2.jpg convert /Users/xah/x.png x2.jpg
The following creates the image, but the result image is bad.
# creates image, but bad img data convert C:/Users/xah/x.png "C:\Users\xah\x2.jpg" convert C:/Users/xah/x.png C:\\Users\\xah\\x2.jpg # this one creates image in the in current dir as Usersxahx2.jpg convert C:/Users/xah/x.png C:\Users\xah\x2.jpg
The following works:
convert "C:/Users/xah/x.png" ~/x2.jpg convert C:/Users/xah/x.png ~/x2.jpg convert C:/Users/xah/x.png /cygdrive/c/Users/xah/x2.jpg convert /cygdrive/c/Users/xah/x.png /cygdrive/c/Users/xah/x2.jpg