[Windows Bash] Using bash in Windows

As a full-stack developer in LAMP, I often play-around with Linux servers.
Unfortunately, there are always some reason that I can’t switch to Linux development machine.
E.g. Windows only printer drivers, Adobe Software, exe…

However, Windows cmd/PowerShell always disgust me for their special syntax.
And I missed Unix-like CLI tools such as (grep, find, wget, curl, vim, ssh…) so much.
Plus you can’t use id_rsa format in Windows directly (You will need putty, a GUI tool for CLI… and you need to convert all your keys)

So today we will get those lovely tools back, on Windows!
(Does NOT require Windows 10 Ubuntu Bash, should work on any supported version of Windows)

  1. Install Git for Windows
    No matter if you use Git, you will need to install it.
    Git for Windows installation includes a very nice Bash environment (In form of MinGW)
    https://git-scm.com/During the installation, those options are recommend, otherwise keep the default option.

  2. Meet the bash shell
    Now right click on any folder in Windows Explorer, a nice bash shell is waiting for you
    You can right click on the title bar to set windows/font size and other settings.

  3. Know about the path structure
    Bash in Windows is base on MinGW, it’s not an emulator, but a compatibility layer to make Windows environment POSIX compatible.
    Maybe too complicated, let’s forgot it. What you need to know first is the path used in this Bash
    e.g. To change working directory to C:\Windows\, you will need to cd /c/windows (Yes, it’s case Insensitive)
    To edit C:\Apache\htdocs\phpinfo.php, you will need to vim /c/Apache/htdocs/phpinfo.php
  4. What about ssh?
    That’s what I need the most.
    Firstly, we can now use ssh-keygen to generate our public/private pairs like on Unix.
    They will be stored in ~/.ssh/ (i.e. C:\Users\Tiger\.ssh like path)
    id_rsa and id_rsa.pub works directly without converting in bash!
    You can now ssh [email protected] without the need of external tools!
    Of course, git works well in bash.
  5.  Other goodies from Unix
    curl, vim, ssh, git, grep, find… works out-out-box
    Check C:\Program Files\Git\mingw64\bin and C:\Program Files\Git\usr\bin to see what’s available.

    You may as well, add your favorite CLI tools to Windows Environment Path.
    MinGW bash does pick them up, after a computer restart.

    Color works, ~/.bashrc works, tab-completions are awesome just like on Linux.

    Happy bashing!

3 Replies to “[Windows Bash] Using bash in Windows”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.