Installation and use of Cygwin

Source: Internet
Author: User

Cygwin is a UNIX-like shell environment for Windows. It consists of two components: a UNIX API library that simulates many of the features offered by the UNIX operating system, as well as a rewrite version of the Bash shell and many UNIX utilities that provide a familiar UNIX command-line interface. The previous component is a Windows dynamic-link library (DLL). The latter component is a set of programs based on the Cygwin DLL, many of which are compiled with unmodified UNIX source code. They all come together to provide a familiar UNIX environment.

In this article we will install Cygwin, discuss its command line interface (CLI), and build an open source that is not included in the standard Cygwin release to realize how easy it is to migrate UNIX applications (at least a subset of UNIX applications) to this simulated environment.

1. Download and run the installation Wizard file
At the beginning of the download method, know Cygwin people know: is to http://www.cygwin.com first as a setup Wizard file Setup.exe, this is Cygwin official download of the Installation wizard files, and only through it to properly download the latest Cygwin version. setup.exe Download complete, double-click Run, the Program Installation Wizard interface as shown in

  

Click Next to go to the next screen and select the type of installation you want to perform.

Click Install from the Internet.

Click Next, and then select an installation directory.

2. Cygwin Installation Options

  

In most cases, the recommended installation options are appropriate and can be customized, but note the following:

Do not install Cygwin in the root directory of the Windows system (for example, C:). It is best to install Cygwin in its own subdirectory, such as the default directory (C:\cygwin) or C:\Program Files\cygwin. (The target directory you select will be the root of the emulated UNIX environment.) For example, if you install in C:\cygwin, the virtual/usr/bin is actually C:\cygwin\usr\bin).

For the Install for option, do not select Just Me.

Set the default Text file type to Unix to maximize compatibility with existing files stored on other Unix machines.

Click Next. In the next window, select a directory that stores the data required for Cygwin. Do not select the Cygwin directory that you selected in the previous step. If possible, create or select a directory on a drive with at least 1GB of free space.

Click Next again to select the type of Internet connection you are using. You should usually choose Direct Connection.

Click Next again.

Wait a moment, Cygwin will download the current list of mirror sites, allowing you to select a mirror site, as shown in Figure 3. If you are unsure which site you should choose, choose a site that is near your location.

3. Select the installation site that you think is reliable or geographically close

  

After a brief delay, the installer displays a complete list of available categories and packages. Figure 4 shows some of the contents of a category. Click the plus sign (+) to expand the corresponding category, and click the loop flag to cycle through skip (ignoring this package) and all available versions of the package. If Cygwin provides multiple versions of a utility, you should choose an instance that meets your needs. By the way, if you choose Column B, you will download the binary package, and select S to download the source code.

4. Select the package and instance that best suits your needs

  

There are more than 1,000 packages available in Cygwin, so you should only select the categories and packages you need. (Installing all Cygwin packages consumes more than 800MB of disk space.) You can add an entire category or a separate package at any time later: simply rerun the Cygwin Setup program. (You can also delete or update the package at any time with the same setup program). Search for a list of Cygwin packages (see resources) to check if your preferred UNIX utility is available in Cygwin. After the installation list file is downloaded, the wizard displays the contents of the list so that the user can freely choose which packages to download. How to choose? Just click on the loop arrow icon that follows the name of each installation package: The text behind the icon indicates what kind of download/installation is being taken on the package, and as the click Changes, there are a few categories:

(1) Default: This is the defaults option, which means to download/install only the default installation of the package (click the + sign to the left of the package to see what the default installation is).
(2) Install: Indicates that you want to download/install the entire contents of the package. The space required is also the largest.
(3) Reinstall: The content of the package is re-downloaded/installed (whichever is selected at the time of normal download/installation). This option is useful and will be explained later in the next article.
(4) Uninstall: This doesn't have to be explained.
  Users can according to their actual needs, to determine exactly what content to download/install. It is recommended to choose the "Install" mode, one step, so as not to be troubled by a variety of such problems in the future.
As for the "Keep", "Prev", "Curr", "EXP" and so on at the top of the window, it is only used to change the way the current tree structure is displayed, which has no effect on download/installation. The user can use the default "Exp". Then click "Next" to start the official download.

  

Finally, the installer installs the software and (optionally) adds a shortcut to the Start menu and to the desktop. Click Finish

5. Start Cygwin by using the Start menu or by double-clicking the Cygwin icon (if you have added these shortcuts), or you can execute Cygwin scripts (such as C:\cygwin\Cygwin.bat) in the Cygwin directory.

Figure shows the first time you start Cygwin: It creates your home directory, executes the shell startup file, and displays a hint. Now it's time to run UNIX commands! You can now use UNIX commands in Windows!

    

For example, try ls-a or type touch. The latter command indicates that touch is an executable file/usr/bin/touch.

The benefits of UNIX in Windows

Cygwin simulates a UNIX shell almost completely in Windows. In fact, it combines the two operating systems nicely together. For example, you can run the df-h command to display free disk space on the UNIX machine. Figure 7 shows the results.

is the image a UNIX file system on Windows or a Windows file system on UNIX?

  

As mentioned earlier, the Cygwin installation directory acts as the root directory for the virtual UNIX system. Cygwin maps subdirectories in the installation directory to UNIX directories. It provides Windows drives in the form of a separate volume, such as/CYGWIN/C. You can use such a virtual path to start a Windows program. Please try entering

/cygwin/c/program\ files/internet\ Explorer/iexplore. Exe

Start Windows Internet Explorer® from the command line. (You can also use the Tab key to automatically expand the elements of the path.)

By the way, if you want to convert the Windows pathname to an equivalent UNIX pathname or vice versa, you can try the built-in command

Cygpath. By default, Cygpath produces a UNIX pathname. Use the-w option to produce a Windows path.

$ cygpath-w/cygwin/c/program\ files/internet\ Explorer/iexplore. EXE C:\Program files\internet Explorer\iexplore. Exe

There are other features that help communicate these two environments:

Cygwin provides its own LPR (/USR/BIN/LPR instead of Windows LPR. EXE), which can be printed directly from a simulated UNIX environment. Just set the PRINTER environment variable to a Cygwin UNC such as \\server\printer_name or//server/printer_name, both forward and backward slashes, as well as elsewhere in Cygwin.

Symbolic links created in Cygwin with ln-s are interpreted as shortcuts in Windows. Similarly, Windows shortcuts are interpreted as symbolic links in Cygwin. Therefore, you can use Windows shortcuts to start UNIX commands with parameters.

Because Cygwin provides a full Bash shell, you can use all of the above compatibility features (and other features) to write UNIX shell scripts to maintain windows!

For example, you can use the UNIX find

Search for data on the drive. Note One thing: spaces are often used in Windows filenames. In order to maintain the full file name (remember that UNIX parameters are separated by a space), be sure to use find-print0 and xargs-0.

See Figure 4. Expand the Devel category and use the loop control to select the highest version of the following packages:

autoconf2.1

automake1.10

Binutils

Gcc-core

Gcc4-core

Gdb

Pcre

Pcre-devel

After making a selection (in order to satisfy the dependency, other packages may be selected automatically), click Next to start the update. As before, the download and installation process takes some time (the development package is often quite large). Resources

Conclusion

Cygwin is not a perfect UNIX simulation environment, but it's pretty good. The documentation for the core components is perfect and particularly handy, and they describe the limitations and security risks in the emulated DLLs.

Perhaps the best feature of Cygwin is its integration with Windows. Using Cygwin and its UNIX command line to manipulate the system can greatly increase productivity. It is recommended that you include subdirectories in Windows program Files in your shell path variable, so that you can start any binaries in the path by simply entering the name of the application.

Even better, Cygwin can manage multiple jobs in the same window. Press Control-z to pause a running job, enter BG and FG to run the job in the background and foreground, and enter the jobs management job list. Of course, the Cygwin can also redirect inputs and outputs, which can be piped to send the output of one command to another command.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.