For those who need to run software that is only available for Windows, or those who simply haven't tried anything else yet, there are options for getting to know Unix while still using Windows for your daily work.
One option is to remotely log into a Unix system using a terminal application such as PuTTY on your Windows machine.
There are virtual machines (see Chapter 40, Running Multiple Operating Systems) that allow us to run Windows and Unix on the same computer, at the same time. This is the best option for those who need a fully functional Unix environment on a Windows machine.
Cygwin is a compatibility layer that allows Unix software to be compiled and run on Windows. A compatibility layer is generally easier to install, but as of this writing, Cygwin has performance limitations in some areas. Purely computational software will run about as fast as it would on a real Unix system, but software that performs a lot of file input/output or other system calls can be much slower than a real Unix system, even one running in a virtual machine.
For example, installing the pkgsrc package manager from scratch, which involves running many Unix scripts and programs, required the times shown in Table 3.2, “Pkgsrc Build Times”. Cygwin, and the Hyper-V virtual machine were all run on the same Windows 10 host with a 2.6 GHz Core i7 processor and 4 GiB RAM. The native FreeBSD and Linux builds were run on identical 3.0 GHz Xeon servers with 16 GiB RAM, much older than the Core i7 Windows machine.
Table 3.2. Pkgsrc Build Times
|FreeBSD Virtual Machine under Hyper-V||21 minutes|
|CentOS Linux (3.0 GHz Xeon)||6 minutes, 16 seconds|
|FreeBSD (3.0 GHz Xeon)||5 minutes, 57 seconds|
I highly recommend Cygwin as a light-duty Unix environment under Windows, for connecting to other Unix systems or developing small Unix programs. For serious Unix development or heavy computation, obtaining a real Unix system, even under a virtual machine, will produce better results.
Cygwin is a free collection of Unix software, including many system tools from Linux and other Unix-compatible systems, ported to Windows. It can be installed on any typical Windows machine in about 10 minutes and allows users to experience a Unix user interface as well as run many popular Unix programs right on the Windows desktop.
Cygwin is a compatibility layer, another layer of software on top of Windows that translates the Unix API to the Windows API. As such, performance is not as good as a native Unix system on the same hardware, but it's more than adequate for many purposes. Cygwin may not be ideal for heavy-duty data analysis where optimal performance is required, but it is an excellent system for basic development and testing of Unix code and for interfacing with other Unix systems.
Cygwin won't break your Windows configuration, since it is completely self-contained in its own directory. Given that it's so easy to install and free of risk, there's no point wasting time wondering whether you should use Cygwin, a virtual machine, or some other method to get a Unix environment on your Windows PC. Try Cygwin first and if it fails to meet your needs, try something else.
Installing Cygwin is quick and easy:
Download setup-x86_64.exe from https://www.cygwin.com and save a copy on your desktop or some other convenient location. You will need this program to install additional packages in the future.
Run setup-x86_64.exe and follow the instructions on the screen.
Unless you know what you're doing, accept the default answers to most questions. Some exceptions are noted below.
Unless you know what you're doing, simply choose "Install from Internet".
Select where you want to install the Cygwin files and whether to install for all users of this Windows machine.
Select where to save downloaded packages. Again, the default location should work for most users.
Select a network connection type.
Select a download site. It is very important here to select a site near you. Choosing a site far away can cause downloads to be incredibly slow. You may have to search the web to determine the location of each URL. This information is unfortunately not presented by the setup utility.
When you reach the package selection screen, select at least the following packages in addition to the basic installation:
This will install the ssh command as well as an X11 server, which will allow you to run graphical Unix programs on your Windows desktop. You may not need graphical capabilities immediately, but they will likely come in handy down the road.
The rsync package is especially useful if you'll be transferring large amounts of data back and forth between your Windows machine and remote servers.
Click on the package categories displayed in order to expand them and see the packages under them.
Cygwin can also enable you to do Unix program development on your Windows machine. There are many packages providing Unix development tools such as compilers and editors, as well as libraries. The following is a small sample of common development packages:
Many of these programs are easier to install and update than their counterparts with a standard Windows interface.
By running them under Cygwin, you are also practicing use of the Unix interface, which will make things easy for you when need to run them on a cluster or other Unix host that is more powerful than your PC.
Most users will want to accept the default action of adding an icon to their desktop and to the Windows Start menu.
When the installation is complete, you will find Cygwin and Cygwin/X folders in your Windows program menu.
For a basic Terminal emulator, just run the Cygwin terminal:
If you'd like to change the font size or colors of the Cygwin terminal emulator, just right-click on the title bar of the window:
Within the Cygwin terminal window, you are now running a "bash" Unix shell and can run most common Unix commands such as "ls", "pwd", etc.
If you selected the openssh package during the Cygwin installation, you can now remotely log into other Unix machines, such as the clusters, over the network:
If you want to run Unix graphical applications, either on your Windows machine or on a remote Unix system, run the Cygwin/X application:
Depending on your Cygwin setup, this might automatically open a terminal emulator called "xterm", which is essentially the same as the standard Cygwin terminal, although it has a different appearance. You can use it to run all the same commands you would in the standard Cygwin terminal, including ssh. You may need to use the -X or -Y flag with ssh to enable some remote graphical programs.
Unlike Cygwin Terminal, the xterm supplied with Cygwin/X is preconfigured to support graphical applications. See the section called “Graphical Programs on Windows with Cygwin” for details.
Once you are logged into the remote host from the Cygwin/X xterm, you should be able to run graphical Unix programs.
You can also run graphical applications from the standard Cygwin terminal if you update your start up script. If you are using bash (the Cygwin default shell), add the following line to your .bashrc file:
You will need to run source .bashrc or restart your bash shell after making this change.
If you are using T shell, the line should read as follows in your .cshrc or .tcshrc:
setenv DISPLAY unix:0.0
Again, Cygwin is not the ideal way to run Unix programs on or from a Windows machine, but it is a very quick and easy way to gain access to a basic Unix environment and many Unix tools. Subsequent sections provide information about other options besides Cygwin for those with more sophisticated needs.
Windows Subsystem for Linux (WSL) is the latest in a chain of Unix compatibility products provided by Microsoft. It allows Windows to run a Linux environment under Microsoft's Hyper-V virtual machine monitor. As of this writing, the user can choose from a few different Linux distributions such as Ubuntu, Debian, SUSE, or Kali.
Differences from Cygwin:
WSL is a virtual machine, based on Microsoft Hyper-V. It requires a substantial amount of memory and requires that virtualization features are enabled in the PC BIOS. If your Windows installation is running in a virtual machine, you must also have nested virtualization installed, and WSL performance will suffer.
Describe three ways we can use Unix software on a Windows machine.
What is the advantage of Cygwin over a virtual machine?
What is the risk of using Cygwin?
What are two advantages of a virtual machine over Cygwin? Explain.
What is an advantage of Cygwin over WSL?