Still Need Windows? Don't Panic!

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 41, 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

PlatformTime
Cygwin71 minutes
FreeBSD Virtual Machine under Hyper-V21 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: Try This First

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:

  1. 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.

  2. 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.

  3. Unless you know what you're doing, simply choose "Install from Internet".

  4. Select where you want to install the Cygwin files and whether to install for all users of this Windows machine.

  5. Select where to save downloaded packages. Again, the default location should work for most users.

  6. Select a network connection type.

  7. 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.

  8. When you reach the package selection screen, select at least the following packages in addition to the basic installation:

    • net/openssh
    • net/rsync
    • x11/xhost
    • x11/xinit

    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:

    Note

    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.

    • devel/clang (C/C++/ObjC compiler)
    • devel/clang-analyzer (Development and debugging tool)
    • devel/gcc-core (GNU Compiler Collection C compiler)
    • devel/gcc-g++
    • devel/gcc-gfortran
    • devel/make (GNU make utility)
    • editors/emacs (Text editor)
    • editors/gvim (Text editor)
    • editors/nano (Text editor)
    • libs/openmpi (Distributed parallel programming tools)
    • math/libopenblas (Basic Linear Algebra System libraries)
    • math/lapack (Linear Algebra PACKage libraries)
    • math/octave (Open source linear algebra system compatible with Matlab(r))
    • math/R (Open source statistical language)
  9. 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:

Note

If you forgot to select the openssh package, just run the Cygwin setup program again. The packages you select when running it again will be added to your current installation.

If you want to run Unix graphical applications, either on your Windows machine or on a remote Unix system, run the Cygwin/X application:

Note

Doing graphics over a network may require a fast connection. If you are logging in from home or over a wireless connection, you may experience very sluggish rendering of windows from the remote host.

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.

Caution

Use of the -X and -Y flags could compromise the security of your Windows system by allowing malicious programs on the remote host to display phony windows on your PC. Use them only when logging into a trusted host.

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:

export DISPLAY=unix:0.0
            

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: Another Compatibility Layer

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 runs actual Linux binaries (executables), whereas Cygwin allows the user to compile Unix programs into native Windows executables. Programs built under WSL can be run on a compatible Linux distribution and vice-versa. They cannot be run on Windows outside WSL. Which one you prefer depends on your specific goals. For many people, including most of us who just want to develop or run scientific programs, it makes no difference.
  • WSL provides direct access to the native package collection of the chosen Linux distribution. For example, WSL users running the Debian app can install software directly from the Debian project using apt, just as they would on a real Debian system. The Debian package collection is much larger than Cygwin's, so if Cygwin does not have a package for software you need, WSL might be a good option.
  • 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.

  • Cygwin is an independent open source project, while WSL is a Microsoft product. There are pros and cons to each. Microsoft could change or even terminate support for WSL, as it has done with previous Unix compatibility products, if it no longer appears to be in the company's interest to support it. Support for Cygwin will continue as long as the user community is willing to contribute.
Practice

Note

Be sure to thoroughly review the instructions in Section 2, “Practice Problem Instructions” before doing the practice problems below.
  1. Describe three ways we can use Unix software on a Windows machine.

  2. What is the advantage of Cygwin over a virtual machine?

  3. What is the risk of using Cygwin?

  4. What are two advantages of a virtual machine over Cygwin? Explain.

  5. What is an advantage of Cygwin over WSL?