How to Install Cygwin

<< Back

On This Page



This document provides instructions for setting up a programming environment for use in CS-11. The environment is called Cygwin and is freely available from Cygwin is already installed on CTC and lab machines. You can access the program in the labs from the Start button and by following the menu tree to CS & CIS courses.

If you need more help installing and using Cygwin, consult the Cygwin User's Guide. Or better yet, ask a class mate if they were able to set it up. If you are looking for instructions on setting up g++ for Mac OS X, see: How to Install g++ on the Mac

Installation Instructions

  1. Go to the site

    Install Cygwin link

  2. Download the setup-x86.exe program and save it to a convenient place like the Desktop.

    Note for Windows 64 users: make sure you install the standard version (32 bit) and NOT the 64-bit version.

  3. Run the program and you will see a startup screen like the following. If you get a security warning then ignore it and run the program anyway. Click on the Next button to continue the installation.

    Opening Cygwin screen

  4. Choose A Download Source: Choose "Install from Internet" and click the Next button.

    Cygwin source screen

  5. Select Root Install Directory: Accept the defaults ("C:/cygwin", All Users, Unix) and click the Next button.

    Cygwin root directory

    Important: The default root directory for Cygwin applications is C:/cygwin. You may change it if you wish (using '/' rather than '\' as a directory separator), but do NOT choose a location that contains spaces anywhere in its path name.

  6. Select Local Package Directory: Accept the default or change it to any temporary directory of your choice. However, make a note of where you saved the files so you can delete the .tar.xz files after the installation to save disk space. Click the Next button to continue.

    Cygwin temporary directory

  7. Select Your Internet Connection: Use the default setting unless you run into problems. Press the Next button to continue.

    Cygwin connection

  8. Choose A Download Site: Any site that you can connect to is fine. Some sites are more stable or faster than others. Try to pick one that works for you. For a nearby site, look in the list of Mirror Sites and find a geographically close one. Press the Next button after selecting the download site.

    Cygwin download sites

  9. Select Packages (important!): The installer will show you a list of packages like those in the following image:

    Cygwin packages

    You will need to install all the programs listed below. Do NOT unselect any packages that are already selected by default and do NOT select all the packages and programs. Here is a suggested process:

    1. Change the View drop down box to "Category".
    2. Type or copy each package listed below into Search, such as "gcc-g++".
    3. Click the + sign to expand the category for Devel, Editors or Utils only.
    4. In the Package column, find the package name for the package that is an exact match. For example "gcc-g++".

      Do not install packages that have only a partial name match.

    5. Verify the New column for the package row does NOT show "Skip". If it does show "Skip", click the New field for the row repeatedly until is shows the highest numbered version.
    6. If the Bin? column does not show n/a, make sure it is checked as shown in the image above.

    Repeat the above process for all the packages listed below.

    • + Devel category
      • astyle
      • binutils
      • gcc-core
      • gcc-g++
      • make
    • + Editors category
      • nano
      • VIM
    • + Utils category
      • dos2unix

    Once you have selected all the required programs listed above, click the Next button.

    If the installation program asks to install other programs to resolve dependencies, accept the additions.

    Accept resolving dependencies

  10. Progress: This step will take some time that depends on the speed of your Internet connection and the speed of your computer. While the setup runs, you can view the progress of the installation.

    Sometimes you may get a download incomplete and the setup application will return to step 8. Simply select another server and continue the installation process.

    Cygwin progress

  11. Postinstall script errors: You may see a window like the following. If so, press Next to continue.

    Cygwin postinstall

  12. Create Icons: You can install on the Desktop or the Start menu. Press the Finish button after you decide where you want them.

    Cygwin icons

  13. As a final step, set windows to show filename extensions.

    Though the installation is complete, you still need to go through the next section to be certain you installed Cygwin correctly.

Starting, Testing and Stopping Cygwin

Cygwin installs both icons on the Desktop and in the Start menu, if you accept the default settings. To start Cygwin, simply double-click the Cygwin! icon on the Desktop or select the Cygwin Bash Shell entry from the Start menu. You should see a window like the following. This is known as the terminal window, or sometimes the command window.

Cygwin console

To verify that your installation was successful, type g++ in the window at the command line like shown in the above image. The message, "no input files" will appear if you were successful.

If you see the message, "no input files", then you installed Cygwin correctly. For example, you may see, "command not found". If so, you will need to uninstall Cygwin (by deleting the folder) and reinstall it. Please make sure you followed the Select Packages step exactly. If you still have difficulty after reinstalling, then please get help from a classmate or the instructor.

To stop Cygwin, type logout or exit in the console window.

For more information, see the Cygwin User"s Guide.

In Case of Trouble

  1. If you try to compile and see a message like, "fatal error: stddef.h: No such file or directory", the error is because your gcc-core and gcc-g++ packages are not of the same version. Rerun the Cygwin install and make sure in step 9 that you select the highest numbered versions of gcc-core and gcc-g++.

    After the update, verify you can compile and run.

  2. If you try to compile and see the message, "bash: g++: command not found", then you probably made a mistake selecting the packages on step 9. Go through the installation process again reading carefully. On step 9, make sure you are expanding the tree by clicking the [+] sign as shown in the image. Also make sure to select all the packages that are listed below the image.
  3. If you see a message such as, "bash is not a recognized command..." you should completely remove your Cygwin installation and reinstall. To remove your Cygwin installation, delete the install folder at C:\cygwin and the download folder wherever you saved it. To help find the download directory, search your computer for any directory name containing "cygwin".
  4. If you try to start Cygwin and it appears only briefly and then disappears, try starting Cygwin from the command line.
    1. From the Start menu, Select Run...
      (In Windows 7 or later, use the search box.)
    2. In the text box, type:
      • command for Windows 95/98/ME
      • cmd for Windows NT/2000/XP/Windows 7/8
    3. At the command prompt type:

    Cygwin will report any errors it has while starting.

  5. If you see the following error:
    Error: could not fork child process: Resource temporarily unavailable.
    DLL rebasing may be required. See 'rebaseall / rebase --help'.

    First try restarting your computer. If that does not help the try reinstalling by rerunning the Cygwin setup.exe program without installing/updating.

    If the above does not work, then check if you have incompatible software installed on your computer. Sometimes these problems can be worked around, by temporarily or partially disabling the offending software.

    If the above does not work then switch from 32-bit Cygwin to 64-bit Cygwin, if your OS and CPU support that.

  6. If you have other problems installing or using Cygwin, try looking through the Cygwin FAQ. If this does not help, then email the instructor with a description of the problem or ask a classmate to help you. Make sure you include any error messages with your description of the problem. Screen shots are also helpful.

Compiling and Running Programs

In this section we look at how to compile and run C++ programs using your Cygwin installation.

  1. Copy the following program into a text editor like TextPad or Notepad.
    #include <iostream>
    using namespace std;
    int main()
        cout << "Hello, World!\n";
        return 0;
    } // end of main function

    Note that MS Word, or any other word-processing program, is NOT a good choice for a text editor. You can make them work but they are too cumbersome and error prone for working with source code.

  2. Save the program file as hello.cpp in your Cygwin home directory using the name: hello.cpp.

    The Cygwin home directory is C:\cygwin\home\username, where username is your login name on your computer. Make certain that you save the program with the correct file extension of cpp. Windows will automatically add the wrong file extension, unless your text editor is showing the Save as type: "All files (*.*)" in the box under the file name.

    Cygwin finishes

  3. Start Cygwin by double-clicking the Cygwin! icon on the Desktop or selecting the Cygwin Bash Shell entry from the Start menu.

    In the terminal window, you can use commands like cd to change directories, ls (el-es, not one-es) to list files and pwd to print the working directory.

  4. In the command window, use the ls (el-es, not one-es) command to list all your files. You should see hello.cpp in the terminal window like the following.

    Cygwin ls

    If you do not see the file listed, then you did not save the file in the same folder that Cygwin is viewing. Type pwd and press the Enter key to show the current folder and then resave the file into the correct folder.

  5. Compile the hello.cpp program by typing the following command at the command prompt and then pressing the Enter key:
    g++ -Wall -Wextra -Wpedantic -o hello hello.cpp
    After running the command, you should see a window like the following:

    Cygwin compiled

  6. To run the program you type:
    After running the command, you should see a window displaying, "Hello, World!", like the following:

    Cygwin saying hello

<< Back

Last Updated: February 14 2018 @16:12:01