Cygwin brings Unix to Windows

54

Author: Jeffrey L. Vagle

It’s a common story: You leave the comfortable confines of the
university computer lab, where you’ve become accustomed to your
Unix/Linux cocoon over the past four years. You’re
been thrust into the cold, hard reality of your first real job, where
you are left to fend for yourself in the unfamiliar, and subjectively
unfriendly, environment of Windows. Your handy shell scripts no
longer do your bidding, all the useful tools to which you’ve become
accustomed are nowhere to be found, and just where the heck do they
hide /usr/bin on these machines, anyway?

For those of us who prefer our slashes forward and our source open,
Cygwin offers a Linux-like environment for the Windows platform. Cygwin gives you both that Linux look and feel, and an API that provides POSIX system call functions. This allows you not only to raise your environmental
comfort level, but also gives you the ability to port existing Linux
applications to your Windows/Cygwin system, or write new
applications that take advantage of the best from both worlds.

The Cygwin Project was started by Cygnus Solutions, continued under Red
Hat (where a commercial
version
is available), and is now maintained by
individual developers as an open source project. It is available under the GNU GPL,
with options for proprietary use through

Setting up Cygwin

Cygwin installation is fairly painless. Simply click on the “Install or Update Now!
link on Cygwin’s Web site and download the 280KB setup file to your system. Running this application starts the Cygwin Setup GUI, which provides a
straightforward method for obtaining the Cygwin packages (or updating
existing packages).

The Cygwin setup GUI gives you three options for installation: download and install from the Internet, download only, or
install from a local directory (which assumes that you’ve previously
downloaded the required packages). The easiest method for
download is via the Internet, but if you plan to install Cygwin
on multiple machines, it may be advantageous to first download the
packages (option two), then install them later by using the Cygwin
setup GUI on the target machines.

Figure 1: Selecting packages in Cygwin setup

After you’ve chosen your installation method, the setup GUI asks the
location of the Cygwin root directory (the equivalent of “/” in your
Unix filesystem), whether to make the installation available to
all users on your Windows system, and the default text file type. In most cases, the default choices presented by the GUI should work.

Next, the program guides you through a set of questions necessary to enable the
mechanics of a networked install — where to put the downloaded
packages, how to connect to the Internet, and where to find a package
server. Once you’ve answered these questions, you will be asked to select which packages you want to download as part of your Cygwin install (see figure 1).

The Cygwin tools are organized by category, and you can browse them through
the Cygwin GUI’s hierarchical interface. The setup GUI automatically selects a default set of packages to install, but this set may not suit your needs, so I recommend walking through the entire package list to ensure your favorite Unix
applications are installed (see figure 2).

The Cygwin setup GUI also lets you not only download the binary packages for installation, but also obtain the source packages at the same time.

Figure 2: Selecting individual packages

Once you’re satisfied that you’ve selected the right set of packages
for your needs (or maybe you’ve simply selected the full installation, as disk space is cheap), click the Next button, and you’re off. Installation may take a while, depending on the
packages you’ve chosen.

After a successful installation you’ll see a Cygwin icon on your desktop or your Start Menu. Double-click
on this icon to bring up the Cygwin bash shell. You can
customize the behavior of the Cygwin shell through environment
variables and registry settings. See the Cygwin
guide
for more details on this.

You can use the Cygwin setup GUI to manage your
existing Cygwin install. Using the same interface, you can
perform common configuration operations, such as uninstallation and
updating of packages. The GUI presents you with the
appropriate choices by package, and you can select the required action
by individual package, just as in the original installation process.

Using Cygwin

As you saw from the installation process, Cygwin is not a monolithic
application, but a large collection of tools and libraries, many
of which you may recognize from your Unix environment. However,
Cygwin is not an operating system: Windows provides the operating
system, and Cygwin provides a layer on top of that OS. This means
that while Cygwin does a nice job of providing the look and feel of
a Unix system, it must use the Windows OS to accomplish this. This, in turn, means that you can’t forget about the Windows environment.

An example of this is Cygwin’s use of the Windows NT security model,
which uses access control lists (ACL) for authorization and
authentication purposes. Cygwin’s chmod application,
a utility that allows users to modify permissions on files or
directories, uses an under-the-covers mapping between the Unix
permissions you see in the Cygwin environment and the actual Windows
permissions implemented by the underlying operating system. Further, Cygwin provides tools and utilities to help set up your overall environment, including the initialization of /etc/passwd and /etc/group files. For details on these
Cygwin/Windows tools and interactions, see this Cygwin Web page.

Beyond the basics

Those who crave a deeper Unix environment can use Cygwin/X, a
port of the X Window System, which you can install through the Cygwin setup GUI. Cygwin/X adds to the
standard collection of Cygwin packages an X server, the X
libraries, and the usual collection of X clients, such as xterm and xclock. With Cygwin/X, you not only have the command-line environment of choice, but you can also use the Unix GUI
environment of choice. X environments for Windows are nothing new, but Cygwin/X provides an open source alternative to the closed source commercial packages out there.

Installing Cygwin/X is as simple and straightforward as using
the Cygwin installation process. Simply select (at a minimum) the
xorg-x11-base package from within the X11 category. If you’ve already installed Cygwin, you should run the Cygwin setup.exe utility again, and select the X11 packages you wish to use.

The current version of Cygwin/X includes
many popular X packages beyond the base X system, ranging from the
WindowMaker and FVWM window management systems to the gtk+
libraries to the xfig drawing package and library. If you’re looking to complete your desktop transformation, a port of KDE for Cygwin is available that runs on top of the Cygwin emulator.

Conclusion

Cygwin is a great alternative for those who feel constrained by working with the Windows environment. Because Cygwin isn’t an operating system and relies on Windows for its
file system and system calls, you’ll have to remain at least somewhat
cognizant of the nuances of Windows. Nevertheless, Cygwin lets
you employ the best parts of each environment to fit your
needs, whether through porting and development of
applications, or simply using the applications in this
flexible, powerful system.