Installing and configuring cygwin for beginners. Installing Git on Windows from Cygwin Packages

After the article by Chris Kaspersky "How to make Unix from Windows" in KG? 3 dated 01/23/01, I was eager to tell Windows users about what Cygwin is. I have been using it for a long time and I can no longer work effectively in Windows without Cygwin installed.

The word Cygwin is made up of two components: Cygnus is the name of the company, and Windows, but it would be wrong to say that everything in Cygwin was written by the guys from Cygnus. Cygwin is a Windows port of the Gnu utilities, and Gnu (www.gnu.org) is a project of the Free Software (Free Software Foundation, or simply FSF), which aims to create a non-commercial Unix system that does not belong to anyone in particular and is free from licenses restricting the freedom to distribute and modify software. As part of this project, almost all standard UNIX utilities were rewritten. The three most significant FSF contributions are gcc (the Gnu C Compiler, or Gnu Compiler Collection), Bash (the Bourne Again Shell), and Emacs. Without gcc, there would be no Linux, and Bash is the standard shell for many modern Unix systems. Experienced people say that the first thing sysadmins do after installing commercial Unixes is to install Gnu utilities. In principle, GNU and FSF in themselves are a vast topic and deserve a separate detailed article.

The entire set of Gnu utilities is a set of small (usually) programs that cover most of the tasks that a Unix system user (and not only Unix) faces on a daily basis, each such program does one task, and does it well. These programs can then be combined to solve various problems.

Attempts to port Gnu to other non-Unix platforms have been made more than once, which, by the way, testifies to their popularity.

It is worth mentioning the project for porting utilities under DOS - DJGPP. Go to http://www.delorie.com/djgpp/, it's really interesting.

Cygnus did not compile each utility separately, tormenting each time to solve the same problems, instead, a kind of "gasket" was written between the GNU utilities and operating system. This shim - cygwin1.dll (1 - version number) - provides emulation system calls UNIX, which allows Unix programs to be compiled and executed with little or no modification source code. In principle, this dll is Cygwin itself, and everything else is software packages GNU compiled to work with Cygwin.

The presence of gcc and libraries makes it possible to port a wide variety of applications under Windows and makes Cygwin a complete platform - you can sometimes find the expression "Cygwin platform". Since the first beta versions of Cygwin, various people have been compiling under Cygwin what they lacked under Windows, the standard distribution of Cygwin has grown gradually, including through these self-made compilations. For example, during beta versions 20 I had to download the vim editor separately, and now it is installed along with the whole set.

How to install it all

Cygnus has written a handy package management program, slightly reminiscent of some similar programs from Linux OS distributions. The first step is to download it from the Cygnus website http://sources.redhat.com/cygwin/setup.exe. By running it, you will be able to download a standard set of packages from one of the many mirrors, and you can choose to do this selectively, skipping individual packages.

For the future - by running this program later from the same directory, you will be able to see what new packages have appeared or new versions of existing packages.

The same program will install Cygwin for you, again offering to decide for yourself what to install and what not. The installation will create directories for you that are common to the Unix file hierarchy - bin, usr, sbin, etc., so it's convenient to put them all in one directory so they don't get confused with your Windows folders.

And how to use it all

When you start Cygwin, you will see a console window similar to the regular Windows console, command.com on Win9x, or cmd.exe on NT. But no! You have launched a glorious descendant of Unix command interpreters on Windows, which command.com tried to imitate with its BAT files. Bash and its older brother sh are the glue that binds the Unix system together, it can rightfully be called a programming language, that is, you can write on it.

A few basic commands and their counterparts in Windows

ls = dir - view the contents of a directory;
cd = chdir - go to another directory;
cp = copy - copy a file;
mv = mv - move/rename file;
rm = del - delete file;
mkdir = mkdir - create a directory;
pwd - display the current directory.

Remember - a big "A" is no longer equal to a small "a", the \ character must now be replaced with /. The cd / command in Cygwin will take you to the directory where bin, usr, etc. are located. In Unix, there is nothing above /, but in Cygwin, in order to travel through Windows partitions, you can use the cd //c/ command (cd //d/MyDir, etc.).

One of the most convenient features of Bash is autocompletion. Let's create some files with the cat command:

cat > first_file ENTER

type something then ctrl-c,

and the same for another file:

cat > second_file ENTER.

Make sure the files exist:

Now type any command like ls followed by the first letter of the first file. Press TAB. Bash will append the filename itself. If the files start the same way, such as file_one and file_two, Bash will only append file_ and wait for you to type another letter to disambiguate.

A few examples of using some utilities.

Let's say you have text file in.txt. You can count the number of words in it like this:

Number of lines:

Find lines containing Larry character sequence:

grep "Larry" in.txt

Split lines into words, replacing spaces with end-of-line characters:

cat.txt | gawk "gsub("+","\n")"

The gawk command "gsub(" +","\n")" means to replace one or more spaces ("+") with an end-of-line character ("\n").

Do the same, but with the possibility of convenient viewing (PageUp, PageDown, exit - q)

cat.txt | gawk "gsub("+","\n")" | less

Sort lines (words):

cat.txt | gawk "gsub("+","\n")" | sort | less

Remove duplicate lines (words):

cat.txt | gawk "gsub("+","\n")" | sort | uniq | less

cat.txt | gawk "gsub("+","\n")" | sort | uniq | wc -l

Remove identical lines (words), counting their number:

cat.txt | gawk "gsub("+","\n")" | sort | uniq --count | less

Sort again, thus obtaining the frequency dictionary of the text:

cat.txt | gawk "gsub("+","\n")" | sort | uniq --count | sort-r | less

The same, with the output of the results to a text file:

cat.txt | gawk "gsub("+","\n")" | sort | uniq --count | sort -r > out.txt

The same, with intermediate results saved in the intermediate.txt file:

cat.txt | gawk "gsub("+","\n")" | tee-intermediate.txt | sort | uniq --count | sort-r | less

Now, using the power of Bash, you can repeat this command for multiple files. Type the script directly in the console, moving to a new line as it is printed in the article - Bash will understand that the command is not finished and change the prompt to ">":

for file in *.txt; do

cat $file | gawk "gsub("+","\n")" | sort | uniq --count | sort -r > $file.out

Like this. Simple problems - simple solutions.

To find out how a particular command works, you can run it with the --help key or use the man (manual) command - man awk, man grep. You can exit man with q.

WHAT ELSE IS IN CYGWIN

Compiler

A simple (people say - 1 day of training) programming language for word processing, one of the ancestors of Perl

stream editor

C parser generator

C parser generator

Programming language. Actually, it has no direct relation to Gnu utilities, it was supported by Sun corporation for some time. You can cd /usr/share/tk8.0/demos and run widget -./widget. You'll see a demo of Tk, a Tcl extension for creating GUIs.

Archiver

Powerful archiver

File comparison program

And a lot more. Just go to bin and see what you have there. Package deposits can be found at http://www.hirmke.de/software/develop/gnuwin32/cygwin/porters/Hirmke_Michael/GNUWin32-contents.html. There is also a lot of information and links on the topic on the Cygnus website http://sources.redhat.com/cygwin/.

How to set up CYGWIN

First, you don't have to run Bash if you're afraid of the console. You can use all the programs from Far, Windows Commander, etc., you just need to set the paths to the bin directory. On Windows 9x this is done in the autoexec.bat file, on NT in My Computer / Properties / Environment you need to add the path to bin to the PATH environment variable.

For more convenient work in Bash, I advise you to do the following: if your Cygwin directories are located in c:\cygwin, create the c:\cygwin\root directory (mkdir /root) and add a line to the cygwin.bat file, which is located in c:\ cygwin:

HOME=d:\cygwin\root

In the root directory, you should create 2 files starting with a dot: .inputrc and .bashrc. Both files are executed by Bash at startup, .inputrc is responsible for ensuring that all keys work correctly, and .bashrc contains various information. As an example, I will give my .bashrc:

export PS1="\w > "

export PATH=".:$PATH"

alias ls="ls --color"

alias untar="tar xvf"

echo Welcome to CygWin!

The first line specifies the Bash path. This is how Unix treats all interpreters. For example, if you have the Perl script hello.pl and perl itself in /usr/bin, you can write on the first line:

and run it like this:

Thus, it is possible to run programs without worrying about what they are written in.

PS1 is a variable that stores the Bash prompt, the job prompt, as it is also called. \w is the current directory.

After this addition to PATH, you can do it the way Windows users are used to:

Next, I use synonyms, or alias "s. For example, the ls command does not colorize its output by default depending on what the files are, for this you need to run it with the --color key. This is inconvenient. With the alias ls="ls command --color" I solve this problem. Now ls means ls --color. It is not necessary to use the same command name, you can do ll="ls --color" - and use the new ll command. Something like this I do when creating the untar command for unpacking tar archives, instead of typing tar xvf every time. Pipes (pipes, pipelines) can also be placed in alias: alias sort_un_sort=" sort | uniq --count | sort -r ".

In fact, the scope for arranging the workplace is limitless, and my examples are primitive and simple. There are more functions, interactive commands in .bashrc, functions that run from a prompt...

Cygwin (Cygwin) is a set of Unix programs and libraries compiled under the Windows OS and hosted in file system in the same way as in real Unix. Thanks to this, we get a complete equivalent of the Unix environment from bash to gcc compilers, which can build projects for execution on Windows without much porting of the source code (a fairly large number of cross-platform applications use this approach, since it is the simplest and fastest) .

Installing Cygwin

You can download Cygwin for 32x or 64x - bit version on the website https://cygwin.com/install.html. Installation is very simple - you can just click "Next" to the Select Packages window. Here, a database of packages will open in front of you, and some of them will already be marked for stopping (basic), others you can mark yourself. In order to mark a package for installation, you need to enter its name in the "Search" field, then expand the categories and find this package. Then click "Skip", as a result, instead of Skip, the version that will be installed should appear. Check the package for further work wget, the rest can be left untouched for now. Packages can be installed or removed at any time by simply re-running the installer, but this is not very convenient, so later in the article I will tell you how to install packages from command line(for this we need wget).

By default, cygwin runs in a standard Windows terminal, which is not very convenient.

Terminal Console

Installing packages for python with pip

Packages in python are often installed using pip, which is not found in the sigwin repositories.

Therefore, it must be installed separately:

MAN pages for libc functions

Cygwin already contains man pages for standard commands, however man for libc functions can be installed separately:

By the way, Cygwin is somewhat related to embedded systems, as it uses Newlib libc implementation, which is known to be widely used in different ARM toolchains.

vim in cygwin

Installation:

The configuration is done in the .vimrc file in your home directory:

I use these settings:

set backspace=indent,eol,start

Syntax enable

set shiftwidth=4

set tabstop=8

set softtabstop=4

set expandtab

set number

set show cmd

set cursorline

filetype indent plugin on

set wildmenu

set lazyredraw

set show match

set incsearch

Using the "native" Cygwin Terminal

The standard Cygwin installer provides its own mintty terminal (launched via the Cygwin Terminal icon). Compared to Console, it is slightly inferior in functionality (for example, it does not have tabs), but it also has good functionality, and there are fewer gestures. One of the nice features is support for 256-you bit colors in terminal:

This allows you to use convenient syntax highlighting themes for vim, such as badwolf:

To activate it, add to .vimrc:

It will look like this:

How to save command history in bash cygwin?

In the .bashrc file you need to find add:

The first indicates the size of the history file (10 thousand commands), the second includes removing duplicate commands (if the entered command is already in the history, then the old one is deleted to save space), and the third includes bash history keeping.

How to navigate to a Windows-style path in Cygwin?

You can use the cygpath utility to turn a win-like path into a unix-style path.

This will turn the path into "/cygdrive/d/projects/some/src" and pass it as an argument to cd.

Cygwin is a unix-like environment for Windows. It is often needed to run programs that were developed for unix-like operating systems. Many of these programs can be installed without Cygwin, but it provides convenient centralized installation and management. With Cygwin you can easily install programs such as OpenSSL , GnuPG , ImageMagick , gvim , gcc , bash , tcsh , emacs and many more.
So let's move on to the installation. First you need to download the installer. This is just a program that will download all the necessary packages and environment, and then install them. Installation is quite simple:




With this menu you can select the proxy settings if you are using one.


The program will download a list of mirrors with packages for installation, after which it will allow you to choose a mirror from which the packages will be downloaded.


Now you can select packages to install. For ease of searching, they are grouped according to their purpose. You can also search by package name. Using this menu, you can install both a binary package (already compiled) and source code (an uncompiled package). The Bin column contains the version of the selected binary package, the Src column (source code) can be selected if a binary package is already selected. The source code will be the same version as the binary package. In order to select a package version in the New column, click on it several times.
Once you have selected all the packages you need, you can click next and the installer will download and install them. When choosing packages, I would recommend you these -

Simple and generally good. Only here is the version of Git, it's not the latest, at least not yet. But it is quite enough for everyday work with Git. If we look at the version, we will see:

$ git --version
git version 1.9.5.msysgit.0

But if you suddenly need something more recent, then you can install Git from the Cygwin packages. To do this, of course, you need to install Cygwin itself. There is nothing complicated in this. Go here and download the installer. This is exactly installer, a not a distribution. Since it downloads all packages from the network. And besides, it must be used to update installed packages or install new ones.

And so we download

And run the installer

Do one, two, three

In any case, if you need something later, you can download and install it. As you can see, the Git version in this package is 2.1.4, which is clearly fresher than 1.9.5. Although under Linux and Mac OS X 2.3.1 is already available.

Just in case, I will give a couple more fast servers to download

This one is just a fairy tale.

Well, that's all set.

We start and see that at the first start we are told where the configuration files are located:

The picture on the right shows where the user's home directory is located. This is the installation folder (in my case C:\cigwin64), then the folder home, then username folder and it already contains config files .bashrc, .bash_profile, .inputrc and .profile.

All terminal configuration is done in these files. I will not describe it here, as this is a large separate topic.

I will only note that the main bash settings are made in the file .bash_profile.

It can also be noted that the Git settings file, .gitconfig, will also be placed in the home directory.

Also, set up appearance terminal can be accessed by clicking on the terminal icon in the upper left corner and selecting Options.

If you need any additional packages for Cygwin, you can search for them.

After all the settings, my Cygwin terminal window looks like this. And then let's see the version of the installed Git.

Well, here we have a full-fledged Git. Now (quickly) let's test it on a real repository.

Everything is working.

P.S. What is worth noting again is that the global and system (global, system) settings of msysGit and Git installed from Cygwin are stored in different places, and they do not interfere or overlap each other in any way, in my opinion this is convenient, since all Windows tools try to write their settings to the global settings file.gitconfig and this can sometimes create inconvenience and confusion.

What is CYGWIN After Chris Kaspersky's article "How to make Unix out of Windows" in CG #3 dated January 23, 2001, I was eager to tell Windows users a little more about what Cygwin is. I have been using it for a long time and I can no longer work effectively in Windows without Cygwin installed.

The word Cygwin is made up of two components: Cygnus is the name of the company, and Windows, but it would be wrong to say that everything in Cygwin was written by the guys from Cygnus. Cygwin is a Windows port of the Gnu utilities, and Gnu (www.gnu.org) is a Free Software Foundation (FSF) project that aims to create a non-commercial Unix system owned by no one in particular and free from licenses restricting the freedom to distribute and modify the software. As part of this project, almost all standard UNIX utilities were rewritten. The three most significant FSF contributions are gcc (the Gnu C Compiler, or Gnu Compiler Collection), Bash (the Bourne Again Shell), and Emacs. Without gcc, there would be no Linux, and Bash is the standard shell for many modern Unix systems. Experienced people say that the first thing sysadmins do after installing commercial Unixes is to install Gnu utilities. In principle, GNU and FSF in themselves are a vast topic and deserve a separate detailed article.

The entire set of Gnu utilities is a set of small (usually) programs that cover most of the tasks that a Unix system user (and not only Unix) faces on a daily basis, each such program does one task, and does it well. These programs can then be combined to solve various problems.

Attempts to port Gnu to other non-Unix platforms have been made more than once, which, by the way, testifies to their popularity.

It is worth mentioning the project for porting utilities under DOS - DJGPP. Go to http://www.delorie.com/djgpp/, it's really interesting.

Cygnus did not compile each utility separately, tormenting each time to solve the same problems, instead, a kind of "gasket" was written between the GNU utilities and the operating system. This shim - cygwin1.dll (1 - version number) - provides emulation of UNIX system calls, which allows you to compile and run Unix programs with little or no change to the source code. Basically, this dll is Cygwin itself, and everything else is GNU software packages compiled to work with Cygwin.

The presence of gcc and libraries makes it possible to port a wide variety of applications under Windows and makes Cygwin a complete platform - you can sometimes find the expression "Cygwin platform". Since the first beta versions of Cygwin, various people have been compiling under Cygwin what they lacked under Windows, the standard distribution of Cygwin has grown gradually, including through these self-made compilations. For example, during Beta 20 I had to download the vim editor separately, but now it comes with the whole set.

How to install it all

Cygnus has written a handy package management tool, slightly reminiscent of some similar programs from Linux OS distributions. The first step is to download it from the Cygnus website http://sources.redhat.com/cygwin/setup.exe. By running it, you will be able to download a standard set of packages from one of the many mirrors, and you can choose to do this selectively, skipping individual packages.

For the future - by running this program later from the same directory, you will be able to see what new packages have appeared or new versions of existing packages.

The same program will install Cygwin for you, again offering to decide for yourself what to install and what not. The installation will create directories for you that are common to the Unix file hierarchy - bin, usr, sbin, etc., so it's convenient to put them all in one directory so they don't get confused with your Windows folders.

And how to use it all

When you start Cygwin, you will see a console window similar to the regular Windows console, command.com on Win9x, or cmd.exe on NT. But no! You have a glorious descendant of Unix command interpreters running on Windows, which command.com tried to imitate with its BAT files. Bash and its older brother sh are the glue that binds the Unix system together, it can rightfully be called a programming language, that is, you can write on it.

A few basic commands and their counterparts in Windows

ls = dir - view the contents of a directory;
cd = chdir - go to another directory;
cp = copy - copy a file;
mv = mv - move/rename file;
rm = del - delete file;
mkdir = mkdir - create a directory;
pwd - display the current directory.

Remember - a big "A" is no longer equal to a small "a", the \ character must now be replaced with /. The cd / command in Cygwin will take you to the directory where bin, usr, etc. are located. In Unix, there is nothing above /, but in Cygwin, in order to travel through Windows partitions, you can use the cd //c/ command (cd //d/MyDir, etc.).

One of the most convenient features of Bash is autocompletion. Let's create some files with the cat command:

cat > first_file ENTER

type something then ctrl-c,

and the same for another file:

cat > second_file ENTER.

Make sure the files exist:

Now type any command like ls followed by the first letter of the first file. Press TAB. Bash will append the filename itself. If the files start the same way, such as file_one and file_two, Bash will only append file_ and wait for you to type another letter to disambiguate.

A few examples of using some utilities.

Let's say you have a text file in.txt. You can count the number of words in it like this:

Number of lines:

Find lines containing Larry character sequence:

grep "Larry" in.txt

Split lines into words, replacing spaces with end-of-line characters:

cat.txt | gawk "gsub("+","\n")"

The gawk command "gsub(" +","\n")" means to replace one or more spaces ("+") with an end-of-line character ("\n").

Do the same, but with the possibility of convenient viewing (PageUp, PageDown, exit - q)

cat.txt | gawk "gsub("+","\n")" | less

Sort lines (words):

cat.txt | gawk "gsub("+","\n")" | sort | less

Remove duplicate lines (words):

cat.txt | gawk "gsub("+","\n")" | sort | uniq | less

cat.txt | gawk "gsub("+","\n")" | sort | uniq | wc -l

Remove identical lines (words), counting their number:

cat.txt | gawk "gsub("+","\n")" | sort | uniq --count | less

Sort again, thus obtaining the frequency dictionary of the text:

cat.txt | gawk "gsub("+","\n")" | sort | uniq --count | sort-r | less

The same, with the output of the results to a text file:

cat.txt | gawk "gsub("+","\n")" | sort | uniq --count | sort -r > out.txt

The same, with intermediate results saved in the intermediate.txt file:

cat.txt | gawk "gsub("+","\n")" | tee-intermediate.txt | sort | uniq --count | sort-r | less

Now, using the power of Bash, you can repeat this command for multiple files. Type the script directly in the console, moving to a new line as it is printed in the article - Bash will understand that the command is not finished and change the prompt to ">":

for file in *.txt; do

cat $file | gawk "gsub("+","\n")" | sort | uniq --count | sort -r > $file.out

Like this. Simple problems - simple solutions.

To find out how a particular command works, you can run it with the --help key or use the man (manual) command - man awk, man grep. You can exit man with q.

WHAT ELSE IS IN CYGWIN

Compiler

A simple (people say - 1 day of training) programming language for word processing, one of the ancestors of Perl

stream editor

C parser generator

C parser generator

Programming language. Actually, it has no direct relation to Gnu utilities, it was supported by Sun corporation for some time. You can cd /usr/share/tk8.0/demos and run widget -./widget. You'll see a demo of Tk, a Tcl extension for creating GUIs.

Archiver

Powerful archiver

File comparison program

And a lot more. Just go to bin and see what you have there. Package deposits can be found at http://www.hirmke.de/software/develop/gnuwin32/cygwin/porters/Hirmke_Michael/GNUWin32-contents.html. There is also a lot of information and links on the topic on the Cygnus website http://sources.redhat.com/cygwin/.

How to set up CYGWIN

First, you don't have to run Bash if you're afraid of the console. You can use all the programs from Far, Windows Commander, etc., you just need to set the paths to the bin directory. On Windows 9x this is done in the autoexec.bat file, on NT in My Computer / Properties / Environment you need to add the path to bin to the PATH environment variable.

For more convenient work in Bash, I advise you to do the following: if your Cygwin directories are located in c:\cygwin, create the c:\cygwin\root directory (mkdir /root) and add a line to the cygwin.bat file, which is located in c:\ cygwin:

HOME=d:\cygwin\root

In the root directory, you should create 2 files starting with a dot: .inputrc and .bashrc. Both files are executed by Bash at startup, .inputrc is responsible for ensuring that all keys work correctly, and .bashrc contains various information. As an example, I will give my .bashrc:

export PS1="\w > "

export PATH=".:$PATH"

alias ls="ls --color"

alias untar="tar xvf"

echo Welcome to CygWin!

The first line specifies the Bash path. This is how Unix treats all interpreters. For example, if you have the Perl script hello.pl and perl itself in /usr/bin, you can write on the first line:

and run it like this:

Thus, it is possible to run programs without worrying about what they are written in.

PS1 is a variable that stores the Bash prompt, the job prompt, as it is also called. \w is the current directory.

After this addition to PATH, you can do it the way Windows users are used to:

Next, I use synonyms, or alias "s. For example, the ls command does not colorize its output by default depending on what the files are, for this you need to run it with the --color key. This is inconvenient. With the alias ls="ls command --color" I solve this problem. Now ls means ls --color. It is not necessary to use the same command name, you can do ll="ls --color" - and use the new ll command. Something like this I do when creating the untar command to unpack tar archives, instead of typing tar xvf every time.. Pipes (pipes, pipelines) can also be placed in alias: alias sort_un_sort=" sort | uniq --count | sort-r".

In fact, the scope for arranging the workplace is limitless, and my examples are primitive and simple. There are more functions, interactive commands in .bashrc, functions that run from a prompt...

I hope you have the desire to experiment with Cygwin. Send your comments to