Thursday, May 14, 2009

Bash environment on Windows: This is not Cygwin

Bookmark and Share

If you are a Linux/UNIX guy and are forced to use Windows then you may find this post useful. Linux/Unix guys use windows due to many reasons. One of the reasons is Microsoft Outlook. This is must have for me and there is no application that can take its place in Enterprise environment.

Today, we will try to setup bash environment of Windows XP. If command prompt is launched then it user should able to change his/her default shell to bash shell and should able to execute generally used Unix tools.

There are few software packages that need to be downloaded.

1. Download bash-203.zip and extract it to “c:\bash”

2. Now download Native Win32 ports of some GNU utilities to “c:\temp\UnxUtils”

Now copy all files from “c:\temp\UnxUtils\usr\local\wbin” to “c:\bash”. It should look like this,

BASH directory on windows

Now add “c:\bash” to global PATH environment variable as below,

PATH Environment variable on Windows for bash

On windows, we can also add “HOME” environment variable which will be passed to bash shell.

Once PATH variable includes “c:\bash”, launch Program=>Accessories=>Command Prompt and type in “bash”.

Bash environment is ready on windows. All bash shortcuts will also work as equally as on Linux.

I also know that there could be other ways to get this work done on windows. If you use this or similar technique then let me know your experience in comments below.


7 comments:

  1. Very useful for the simplicity of the approach and the handy links. I've used bash that comes with MsysGit and Cygwin - both very large distributions.

    Sean

    Read: http://www.openmakesoftware.com/blogs/seanblanton
    Follow: http://www.twitter.com/seanblanton
    Connect: http://www.linkedin.com/in/seanblanton
    ReplyDelete
  2. I just followed these instructions - I'm quite happy to have some additional unix utils on my command line (cat, less, rm) - but I could not get bash itself to work.

    It will run fine, but reports "bash: warning: could not find /tmp, please create!" - I tried creating a "tmp" within C:\Users\myusername (where I set my HOME environment to), and also within C:\bash, but this did not stop the error.

    Not so bad though, right? Just a warning. Well, actually it's worse: immediately after opening bash, a command like "ls" will display files in the good old fashioned style, then dump this to me: "[sig] C:\bash\bash.exe 1000 (0) call_handler: couldn't get context of main thread, error 998", and hang. After a CTRL+C, you end up with "[sig] bash 1000 (28) call_handler: couldn't get context of main thread, error 998", and now the terminal is entirely nonresponsive.

    I'm running 64-bit Win7 Ultimate on an Intel Core2, about 4gb of ram and the rest is unimportant. I'm guessing this is a 64-bit issue or just a "Win7 is different" issue, which is causing some DLL call to fail or return differently and muck things up. If I find a fix I'll report back; I'm also cross-posting this to my own blog.

    Thanks for the suggested method to bring bash to Windows!

    Wyatt
    ReplyDelete
  3. Hi Wyatt, I ran into the same issue with bash. However, I've downloaded another window bash program (http://win-bash.sourceforge.net)and fortunately it works fine. And there is no dll to worry about - it's completely self-contained.

    Mike
    ReplyDelete
  4. the tmp directory should be created in the root of the system:
    mkdir /tmp. This worked for me.
    Setting Home environment variable got rid of complaint about .bashrc
    ReplyDelete
  5. the same problem with 'tmp'. I tryed to create this folder inside:
    %BASH HOME DIR%
    c:\Windows
    c:\Windows\system
    c:\Windows\system32

    it wont works.

    I installed win-bash (bash_nt) and its working now.
    ReplyDelete
  6. For those of you who have run into the problem with the tmp file, while in bash, in looks for tmp at the root. So in bash,

    mkdir /tmp

    or go to the C:\ and right click, New, Folder, and name it tmp.

    As for the home directory, right click on "My Computer", and go to Properties, Advanced, and at the bottom, click "Environment Variables." On the system variables at the bottom, select Path and add: ;c:\bash at the end of the line. Then on the "User Variables" at the top, click "New" then give the name Home and the value C:\Documents and Settings\username

    This should do it.

    HTH,

    KaBar's Edge
    Registered Linux User #431029
    Windows free since 05/2000
    ReplyDelete
  7. I'm (being forced to) use window 7. I could not create /tmp using bash so I did it using windows and it did not complain.
    For almost every command I get
    [sig] C:\bash\bash-2.03\bash.exe 1000 (0) call_handler: couldn't get context of
    main thread, error 998

    But this warrants further investigation time and effort. I will watch this space. Let me know if I can help.

    Cheers
    Tony
    ReplyDelete

Your valuable comments are welcome. (Comments will be moderated.)

 




Technology