Installing Git on Windows from Cygwin packages. What is Cygwin Cygwin run program in windows

This article targets two
types of people: for those who do not understand
Linux, but can't install it on my computer
(there are different reasons), or for those who
little fumbles in penguins πŸ™‚ and do not mind
get to know them on the "neutral"
territory, that is, on Win98 / NT.

The site has already described Cygwin as the best
Linux emulator for take out, but it was not said
nothing about installing, configuring and bugs of Cygwin.
Here I will tell you about it πŸ™‚ In fact, if
think about it, Cygwin is not an emulator at all, but
just a Linux distribution written for Win32 πŸ˜‰

Stop messing around ... Go to http://www.cygwin.com,
take the setup.exe program from here. Her
we will pull already precompiled
binaries (in exe extension), do you remember rpm?
πŸ˜‰ from the developer's site, or from a mirror.
I RECOMMEND this program only to download
these files will be installed manually, since if
you put it using setup.exe, gcc does not work - fig
knows why ... Maybe the developers have already taken into account
this bug, but I don't know about it yet ...

So, download all the main binaries (sources
you can not download), and several
additional - who will refuse wget, lynx,
BitchX, Python πŸ™‚ But you don't need to download Perl ...
was ActivePerl, an advanced Perl emulator. Download
available from http://www.acriveperl.com.
Gluckov did not observe πŸ™‚ (I will tell you how I
implemented it in cygwin).

Customization

And in the file "group" in the same folder "etc":
root: x: 0: root

If you want to encode your password, and
not "password" as I did in my example,
write a Perl script

#! / usr / bin / perl
chomp ($ pass = );
print $ crypt ("SA", $ pass);

Where, SA - salta, which will be used for cryptography
password ... you can make it random, but in
this article will be offtopic.

Now we edit the file "c: \ cygwin \ cygnus.bat" -
in it we change the PATH, just changing the path to
emulator and the path to the login.exe file. Let's run
file.

Log in: in my example "root": "password".
So we got into the emulator itself. I don’t
liked the input prompt. Let's change it
- variable PS1. Open (create) the file "c: \ cygwin \ etc \ profile"
and write there:

# / etc / profile
PROFILE_LOADED = 1
PATH = "/ usr / local / bin: / usr / bin: / bin: / usr / sbin: / usr / local / sbin: $ PATH"
unset DOSDRIVE
unset DOSDIR
unset TMPDIR
unset TMP
export HOSTNAME = test
PS1 = "[\ [email protected]$ HOSTNAME \ W] # "
LOGNAME = $ USER
export PATH PS1 USER LOGNAME

Here ... Then we will re-login, and everything will be on
place and beautiful πŸ™‚ The invitation will be: # - standard, linux πŸ™‚

That's it, the initial installation is complete.
Moving on to installing services πŸ™‚

Tueva hucha is included in the standard delivery
services. You need to run them in this way:
/ usr / sbin / inetd -R /usr/sbin/in.ftpd (example for ftpd).

It's better to put SSHD yourself - it got up with a bang and
I'm running from SecureCRT, legalized on 127.0.0.1 -
a completely different view πŸ™‚

As for working with TCP / IP, I have no shortcomings
noticed πŸ™‚ Everything connects and works like
necessary...

And now a few tips:

1) Access to ALL disks is open. So be
careful. For example, drive d: is located here -
"/ cygdrive / d".

2) For Perl, create a symlink to the file
Perl.exe, for example, like this "ln -s /cygdrive/c/perl/bin/perl.exe
/ usr / bin / perl "

3) If for some reason you do not
linux application is installed -
just correct the C-code. May be,
will be successful .. (this is how I compiled
micq).

4) Stay tuned for Cygwin updates at http://www.cygwin.com
- binaries are updated frequently.

Questions? Write me an E-Mail - I will try
help ...

Developing cross-platform apps is not easy. Especially it is not easy thanks to Windows, in which everything is not like people. Here you have neither a normal terminal, nor normal console utilities, nothing at all! Having faced this problem again, I decided to try Cygwin again. And you know, it turns out, it really does something out of Windows that you can almost use!

You can download the Cygwin installer from here. In fact, this is not so much an installer as a package manager that, when launched, just asks which packages you would like to install. Guys! Batch manager! For Windows! The installer creates a cache in the directory from which it will be launched. Therefore, before starting, it is better to create some special daddy on the desktop and put the installer in it.

What packages, in my opinion, should be delivered:

  • openssh- mastkhev;
  • inetutils, bind-utils, ping, nc and nc6- mastkhev;
  • wget, curl- mastkhev;
  • python and / or python3- I think it's a must;
  • vim, gvim- for editing small files will not be superfluous;
  • diffutils, pwgen, unzip, rzync- let them be just in case;
  • gcc and / or clang, cmake, gdb- if needed;
  • screen, tmux, mc- for lovers;
  • git- under very big question, see below;

Note! To install pip in Cygwin, check the box next to the python-setuptools and / or python3-setuptools package. After installing in the terminal say:

easy_install-2.7 pip

easy_install-3.4 pip

... whichever version or versions of Python you have installed.

So, after installing Cygwin, you can open a terminal:

Guys! A normal terminal that resizes allows you to copy and paste text, and that's it! For Windows! With all the familiar and familiar commands id, ls, pwd, cat, ssh, scp, and others. With a human environment - .bashrc, ~ / .ssh / config, and so on. Plus, unlike the infamous PowerShell hack, Cygwin doesn't drag the .NET Framework with it. We can even open multiple terminals and switch between them using the Ctrl + Tab combination. It's almost like tabs! It's clear that the good old Alt + Tab also works.

Above, I did not recommend installing Git, and here's why. The fact is that it slows down noticeably in Cygwin. recommend to run the commands:

git config --global core.preloadindex true
git config --global core.fscache true
git config --global gc.auto 256

But this, unfortunately, does not completely solve the problem. So, on a large project, the git status command can run for 20 seconds. On Linux, the command is executed instantly on the exact same repository.

Those who like to work in a console like the Linux console can install Cygwin, a Unix like environment, where standard console programs from Linux will be available.

Cygwin is pretty easy to install. During installation, in one of the modes, you can check the boxes opposite the software packages that you want to install. I chose nano packages, git and something else.

After installation, a Cygwin shortcut appears on the desktop to launch the environment.

Launch Cygwin from any folder

Since I use TotalCommander, it is convenient for me to launch programs directly from the directory I need. Let's create a convenient bat-file for running Cygwin.

Immediately, without much thought, copy the "Object" line from the property of this shortcut to the new file we created C: \ bin \ bash.bat
The complete content of the file will look like this:

@start "" C: \ cygwin \ bin \ mintty.exe -i /Cygwin-Terminal.ico -

Please note that the path to the exe file may be different for you. I have installed Cygwin in the C: \ cygwin directory.
Also, if the C: \ bin directory has not yet been added to the PATH environment variable, then this should be done.

Configuring Cygwin Launch

After some work with Cygwin, I found that despite the fact that I can run Cygwin from any directory, simply by typing the word bash, the environment itself always opens in your user's home directory. (The home directory is set in the HOME environment variable).

It doesn't look very convenient, because if I write the bash command from the D: \ xyz directory, then I expect that running Cygwin will also be in the D: \ xyz directory.

If you pay attention, you will see that the shortcut from the desktop launches the utility mintty.exe. We immediately understand that it is necessary to familiarize ourselves with the list of incoming attributes for this command.
Open Cygwin and enter

Man mintty

After carefully studying the manual, we are pleased with some features that we did not know about, namely: the ability to set the size and coordinates of the Cygwin window to launch.

Open our bat file and change its contents to the following:

@start "" C: \ cygwin \ bin \ mintty.exe -i /Cygwin-Terminal.ico --size 120.77 --position -4.0 -

In this case, I set the size of the Cygwin window and the position of the window to be necessary for me (a negative value of -4 is needed so that the edge of the window is outside the border of the monitor, and it is not visible).

Now my window will always appear in the coordinates convenient for me, and will not shift at each new start by +8 pixels in x, y.

But what about the Cygwin startup directory?

After all, moving to the desired directory from your home directory is terribly inconvenient!

The solution has been found! To set the current directory when Cygwin starts up, we can use the autostart script for the bash startup environment.

So we need to improve our bash.bat file so that it creates an autostart file for the bash console to start.

We start Cygwin, enter the command "man bash" and read the documentation in search of what we need. We find several variants of file names for the user's home directory, which are launched when logging into bash.
Files to run when logged into bash:

~ / .bash_profile ~ / .bash_login ~ / .profile

The file to be launched when "bash is started without authorization in it

~ / .bashrc

Important note: autorun file ~ / .bash_login (or whatever) must be written in UTF-8 encoding! And shouldn't use \ r characters. (For example, the pwd command did not work for me when the file contained the \ r character at the end, typical of Windows).

As it turned out, it is not so easy to output UTF-8 text from CMD, but it is possible!
Here's an example of how it's done:

Cmd / u / c chcp 65001 | echo some text> "filename"

Let's improve our C: \ bin \ bash.bat file, now it has the following content:

@echo off SET file = .bash_login cmd / u / c chcp 65001 | echo #! / bin / bash> "% HOME% \% file%" cmd / u / c chcp 65001 | echo cd "% CD: \ = /%" >> "% HOME% \% file%" @start "" C: \ cygwin \ bin \ mintty.exe -i /Cygwin-Terminal.ico --size 120.77 --position -4.0 -

Once launched, the bash console executes the contents of the ~ / .bash_login file. This file must be in UTF-8 format. To do this, we call CMD with the / u flag, which tells the console to be launched to return the result in UTF-8 format.

As you can see, we are sending two commands separated by | ... This sign allows us to write the two commands we need on one line.

The first command chcp 65001 sets the encoding to UTF-8 in the running console. (To find out what the current encoding is set in the console, just run the chcp command without parameters.)

Second command echo text> "% HOME% \% file%" prints the appropriate text to a file named "% HOME% \% file%", where the variable names are expanded into the path to the home directory and the filename .bash_login.

Note the unusual reference to the CD variable, which contains the current directory of the cmd console. If the variable is usually expanded by writing

Then in our case, we use the record

% CD: \ = /%

This allows you to immediately replace all Windows \ style slashes with Linux / style slashes.

Do not forget to put all file and directory names in double quotes, so this will allow you to get into directories containing spaces.

Due to the fact that UTF-8 is used, this construction successfully allows opening Cygwin in directories with Russian names.

Thus, each time you run the bash command in the console, the script C: \ bin \ bash.bat will run, which overwrites the bash startup file in Cygwin. Now we can easily and conveniently launch the bash console from any directory and immediately go to the same directory in the bash console.

We are happy and enjoy the result!

Let's sum up

  1. We have installed Cygwin
  2. Created file C: \ bin \ bash.bat with content @echo off SET file = .bash_login cmd / u / c chcp 65001 | echo #! / bin / bash> "% HOME% \% file%" cmd / u / c chcp 65001 | echo cd "% CD: \ = /%" >> "% HOME% \% file%" @start "" C: \ cygwin \ bin \ mintty.exe -i /Cygwin-Terminal.ico --size 120.77 --position -4,0 - (Note: the path C: \ bin \ must be in the PATH environment variable)
    Due to this, we have achieved:
    • launch the Cygwin terminal at the specified screen position (--position parameter)
    • launch a window of a certain size (parameter --size)
    • launch Cygwin from any directory by typing bash in the console
    • while running Cygwin is located in the same directory from which it was launched!

The cygwin.bat script is executed from the DOS command line, installs the Cygwin environment and starts the bash interpreter under Windows. Cygwin finely tunes Unix environment variables to match Windows environment variables. For example, on my machine, I logged into Windows as user bjohnson. When I start Cygwin, it is loaded by default under user control bjohnson.

Below is a window with some standard Unix commands in Cygwin.


Depending on the packages you have installed, you can easily run the appropriate Unix utilities. If you're a Unix user, you would undoubtedly want Windows to have a ps command to view the currently running processes without using the Task Manager. If you use the -aW flag, you should be able to see Windows processes just like any Cygwin processes running. Below is a list of Windows processes available from the Cygwin command (ps -aW | less).

PID PPID PGID WINPID TTY UID STIME COMMAND 3193213 0 0 4291774083? 0 Dec 31 C: \ WINDOWS \ SYSTEM \ KERNEL32.DLL 63753 0 0 4294903543? 0 Dec 31 C: \ WINDOWS \ SYSTEM \ MSGSRV32.EXE 60569 0 0 4294906727? 0 Dec 31 C: \ WINDOWS \ SYSTEM \ MPREXE.EXE 77349 0 0 4294889947? 0 Dec 31 C: \ WINDOWS \ SYSTEM \ RPCSS.EXE 196093 0 0 4294771203? 0 Dec 31 C: \ WINDOWS \ SYSTEM \ mmtask.tsk 191237 0 0 4294776059? 0 Dec 31 C: \ WINDOWS \ EXPLORER.EXE 237709 0 0 4294729587? 0 Dec 31 C: \ WINDOWS \ TASKMON.EXE 230713 0 0 4294736583? 0 Dec 31 C: \ WINDOWS \ SYSTEM \ SYSTRAY.EXE 217533 0 0 4294749763? 0 Dec 31 C: \ PROGRAMFILES \ DIRECTCD \ DIRECTCD.EXE 5.1.

Directory structure and file permissions

Cygwin mounts your local drives in the / cygdrive directory. This includes hard disk partitions, floppy drives, CD-ROM drives, ZIP drives. Let's run the df command on my machine. We get a structure similar to the one below.

[email protected]$ df Filesystem 1k-blocks Used Available Use% Mounted on C: \ cygwin \ bin 2096832 0 2096832 0% / usr / bin C: \ cygwin \ lib 2096832 0 2096832 0% / usr / lib C: \ cygwin 2096832 0 2096832 0 % / c: 2096832 0 2096832 0% / cygdrive / cd: 670496 670496 0 100% / cygdrive / d

After installing Cygwin, I told the installer to save the files to the C: \ cygwin \ directory. Cygwin used this directory as the root point mount the filesystem... He mounted C: \ cygwin \ bin to / usr / bin and C: \ cygwin \ lib to / usr / lib. Cygwin (but not Windows) environment variables have been added to the / usr / bin, / bin, and / usr / local / bin directories. The directories from the Windows environment have been imported into Cygwin to be able to access them.

Cygwin also uses a reasonable permissions system for Unix files. But what does this mean for all of your Windows files? Who is the owner of the files, and what are the default permissions? Let's run the ls -al command on several Windows files to get the answer.

[email protected]/ cygdrive / c / cyginstall $ ls -al total 273 drwxr-xr-x 1 bjohnson unknown 0 Mar 13 17:48. drwxr-xr-x 1 bjohnson unknown 0 Dec 31 1969 .. drwxr-xr-x 1 bjohnson unknown 0 Mar 13 18:06 contrib drwxr-xr-x 1 bjohnson unknown 0 Mar 13 18:03 latest -rwxr-xr-x 1 bjohnson unknown 218112 Mar 13 17:48 setup.exe -rw-r - r-- 1 bjohnson unknown 60607 Mar 13 17:54 setup.ini

Cygwin will try to get information about the file's owners (user and group) from Windows. While I was using a Windows 98 machine with one user, all the files were owned by me (bjohnson) with "unknown" as the group. This set permissions for all Windows directories and executables to 755 (read and execute for everyone, write for owner only) and set all Windows files for 644 (read for everyone, write for owner only). The chmod command for Windows files is ignored.