How to Install Cygwin

<< Back

On This Page

Cygwin!

Introduction

This document provides instructions for setting up the programming environment we use in CS-11. The environment is called Cygwin and is freely available from cygwin.com. 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 http://cygwin.com/ and click on the "Install Cygwin now" link (circled)

    Install Cygwin link

  2. Download the setup.exe program and save it to a convenient place like the Desktop
  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. Also, leave the default text type as Unix/binary.

  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.gz files after the installation. 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: Look in the list of Mirror Sites to find a close one. Speeds may vary considerably for different sites. Also, note that if you choose an FTP site, you may need to adjust your firewall. I used mirrors.kernel.org, since it is an HTTP site and Palo Alto is geographically close. 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 packages listed below. Click on the + sign next to each package name to see the individual programs. Then for all the following programs, check to see if the word "Skip" shows up. If it does, click it once to select the most recent (highest numbered) version of the program.

    • Devel
      • astyle
      • binutils
      • gcc-g++
      • gdb
      • make
      • splint
    • Editors
      • nano
      • VIM
    • Text
      • less
      • util-linux

    Once you have selected all the required programs listed above, click the Next button. Do NOT unselect any default packages and do NOT select all the packages and programs.

  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.

    Cygwin progress

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

  12. Installation Complete: You may see the following dialog window after the installation completes:

    Cygwin finishes

    However, you 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 command window, or sometimes as the terminal 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, "g++: no input files" will appear if you were successful.

If you do not see the message, "g++: no input files", then you did NOT install Cygwin correctly. You will need to uninstall Cygwin and reinstall it. Please make sure you followed the Select Packages step exactly. If you still have difficulty after reinstalling, then please contact the instructor for help.

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

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

In Case of Trouble

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...
  2. In the text box, type:
    • command for Windows 95/98/ME
    • cmd for Windows NT/2000/XP
  3. At the command prompt type:
    C:\cygwin\cygwin.bat

Cygwin will report any errors it has while starting.

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, You can search your computer for any directory name containing "cygwin".

If your are having difficulty 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 better yet, ask a classmate to help you. Make sure you include any error messages with your description of the problem.

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.

  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 command window, you can use commands like cd to change directories, ls to list files and pwd to print the working directory.

  4. In the command window, use the ls command to list all your files. You should see hello.cpp in the command window like the following:

    Cygwin ls

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

    Cygwin compiled

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

    Cygwin saying hello

<< Back

Last Updated: February 21 2009 @14:19:56