Struggles and Success With Cygwin
While PowerShell is a great thing for Windows management, it still has a long way to go to catch up with the sheer flexibility of Bash and the staggering array of tools centered around manipulating simple streams of text.
This post on StackOverflow contains a few great bits from different perspectives: even from the creator of PowerShell itself.
I just wanted to share some of the problems that came up with my attempts to integrate various open-source tools into our Windows-based development environment. Finally I’ll share some tips/observations that led to an enjoyable environment.
Problems
Permissions
Easily the most frustrating part of Cygwin is when it attempts to imitate POSIX permissions on NTFS volumes by manipulating the ACLs. Frankly, Cygwin does a terrible job at this. It only serves to cause massive headaches.
TURN THIS OFF before you do anything else in Cygwin.
You can avoid permissions issues by setting up your NTFS mount points with the “noacl” option. This is easily accomplished by configuring them in fstab with the “noacl” option, like so:
none /cygdrive cygdrive binary,posix=0,user,noacl 0 0
This line will cause Cygwin to simply leave the default Windows permissions alone. They are good enough in 99% of cases, and I’ve found that they are better than what Cygwin does to permissions (it’s not pretty) in nearly 100% of cases.
Forking
This is a problem that can be harder to work around, due to the fact that Windows doesn’t allow easy forking of processes. Cygwin’s version is very slow (by necessity). The maximum forking performance of Cygwin is about 2% of my comparable Mac OS X machine’s speed when executing Bash commands in a loop. Here’s a useful mini-benchmark to see for yourself:
while true; do date; done | uniq -c
One way around this limitation is to use a programming language like Perl or Ruby for scripts that need to iterate over large numbers of files, etc.. Ruby has a very handy standard library with good file handling utilities.
Rebasing
Sometimes, after an update, Cygwin programs are not linked correctly anymore. This is solved with a rebase. This operation will update your Cygwin binaries/libraries to be able to find the right functions in linked libraries (like the all-important cygwin.dll).
Background Tasks
The cygrunsrv tool lets you install any cygwin program (script or .exe) as a Windows service. This is a godsend, as you can easily get useful servers like rsyncd, git --daemon, simple Ruby web servers, or any other background task up and running with little trouble.
Ruby
Arguably the best part of Ruby is the RubyGems packaging system. Many of the best gems, however, require native extensions to be built. While some gems have pre-built Windows binaries, many do not. Cygwin makes this easy by making GCC and many of the dependent libraries available. I’ve never run into a gem that couldn’t be built under Cygwin with anything more than grabbing the right libraries through the package manager.