Cygwin error - Failed to run '/bin/bash': No such file or directory

14,835

Solution 1

I managed to sort this with yet another installation - this time I opted to download and install from the net (option 1 in the installer), instead of downloading the files separately and installing from the locally-stored folder (options 2 and 3). I can't be sure why selecting those options was providing me with an incomplete installation, but I'm now able to run bash without errors.

Solution 2

The Problem

You can skip down to look at the two solutions, especially the second one, which worked for me, if you'd like.

I just ran into this problem after recovering a corrupted portion of my computer (after the System32 directory got corrupted - yuck!) This kind of stuff had happened before (due to other circumstances), where I still had the C:\cygwin64 directory with the folders and at least some other files still there.

Before, I had always been able to simply re-install by running setup-x86_64.exe (I put mine in C:\cygwin64). After that, bash would be back. I always run this with the online option through https://mirrors.kernel.org but even if I only select bash in the installation GUI, I was running into this problem, though my error came up as

/bin/bash: Exit 126.
Failed to run '/bin/bash': No such file or directory

Cygwin terminal (emulator) with the text specified above, i.e. "/bin/bash: Exit 126. Failed to run '/bin/bash': No such file or directory"

Checking my bin directory showed that, indeed, bash was missing. From the commmand prompt (CMD)

C:\Windows\System32>C:\cygwin64\Cygwin
'bash' is not recognized as an internal or external command,
operable program or batch file.

C:\Windows\System32>dir C:\cygwin64\bin\bas*
 Volume in drive C is ██████████
 Volume Serial Number is ██████████

 Directory of C:\cygwin64\bin

File Not Found

C:\cygwin64\bin>

Note that I usually run Cygwin by either:

  1. using the Desktop shortcut, which is the same as running the following from the (Windows) command prompt
C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -

or

  1. Using the Cygwin.bat file. I'll first show the file contents, then the results of my attempts at running it.
C:\Windows\System32>type C:\cygwin64\Cygwin.bat
@echo off

C:
chdir C:\cygwin64\bin

bash --login -i

C:\Windows\System32>C:\cygwin64\Cygwin
'bash' is not recognized as an internal or external command,
operable program or batch file.

C:\cygwin64\bin>

First (unsuccessful attempt at a) solution

Finding bash-<version>.tar.xz

I had downloaded before from https://mirrors.kernel.org, so I had a folder,

C:\cygwin64\http%3a%2f%2fmirrors.kernel.org%2fsourceware%2fcygwin%2f

Poking around a bit further, I found a tarball called bash-4.4.12-3.tar.xz in

C:\cygwin64\http%3a%2f%2fmirrors.kernel.org%2fsourceware%2fcygwin%2f\x86_64\release\bash

making the full path

C:\cygwin64\http%3a%2f%2fmirrors.kernel.org%2fsourceware%2fcygwin%2f\x86_64\release\bash\bash-4.4.12-3.tar.xz

I ended up opening this with 7zip, though you could use WinRAR or something else similar.

(I went on a bit of a rant about how tar is now available on Windows, but using it didn't work for the extraction. You can see the rant here if you want to learn more about tar and curl natively on Windows 10) I copied/pasted the tarball to the desktop, then right-clicked and chose 'Expand to ` twice to get at what was inside. I copied all of that into

C:\Users\bballdave025\Desktop\bash-4.4.12-3\

at which point I could look at what was inside. I then compared the locations of the files inside to the locations of the files on a machine where I had Cygwin working. I was able to find all of the files, then I planned to simply move them to their appropriate positions.

For some other people, perhaps some coming from git bash (like this poster)(archived) or mingw/msys2 (like this poster)(archived), note that my error said the system couldn't find /bin/bash - different from how your errors might reference /usr/bin/bash, so there will be some differences.

C:\Users\bballdave025\Desktop\bash-4.4.12-3>tree /a /f .
Folder PATH listing for volume ██████████ OS
Volume serial number is ██████████ ██████████
C:\USERS\BBALLDAVE025\DESKTOP\BASH-4.4.12-3
|
+---etc               \   . On the working computer's version, I found
|   \---postinstall    }-' C:\cygwin64\etc\postinstall\bash.sh.done
|           bash.sh   /   I'm going to move the file from where you
|                       see it to _my_ C:\cygwin64\etc\postinstall.sh
|                     Then I'll run it, and if the tests pass, I'll
|                   rename it to bash.sh.done . I'll do that after
|                 moving all the others.
|
\---usr                 
    +---bin              
    |       bash.exe     \     
    |       bashbug       }---  I'll move these three files into 
    |       sh.exe       /      _my_  C:\cygwin64\bin   FIRST (1)
    |
    +---include
    |   \---bash                      \    . I'll move this bash
    |           <lots of *.h files>    }--' directory and all its
    |                                 /  constituent header (*.h)
    |                                  files to _my_ directory,
    |                                      C:\cygwin64\usr\include\
    |
    +---lib
    |       libbash.dll.a  }- I'll move this one file to _my_
    |                     /                         C:\cygwin64\lib\
    |
    |
    |                                          \
    \---share                                   \
        +---doc                                  :
        |   +---bash                              \
        |   |   +---<lots of bash doc stuff>       :
        |   |                                      |
        |   \---Cygwin                             : 
        |           bash.README                    |   .-I'll put the
        |                                      _.-'  _/ doc, info,
        +---info                              /   _-'  locale, and
        |       bash.info.gz                  \_/'  man directories
        |                                   --'   in _my_
        |                                  /  C:\cygdrive64\usr\share\
        +---locale                         `--------...____   directory,  
        |   +---<lots of locales which have the same  >    :  which is 
        |   |   <structure underneath; the last locale>   /  where they
        |   |   <(serving as an example) is below     >  :  were in the
        |   \---zh_TW                                   /   working
        |       \---LC_MESSAGES                        /    version.
        |               bash.mo                       /
        |                                            :
        \---man                                     /
            \---man1                               :
                    <lots of PROGRAM.gz files>    /
                                                 /                              

Yeah, I hope to get back, but I want to get some of this answer up and saved.

Second solution

I had this happen to a friend. An administrator had set up her account and the administrator had left "his hooks" in it, meaning he held some kind of ownership. Since that administrator no longer worked at the place we did, we had to figure out a way to get everything fixed.

First, we tried to delete everything, but there were always a few files and folders that we couldn't get rid of - they were owned by that administrator (who is a really nice guy, by the way.) We couldn't even delete if we ran the deletion as an administrator ( File Manager -> C -> Windows -> explorer.exe, right click, then 'Run as Administrator', go to the C:\cygwin64 directory and try to delete ... no dice. )

To finally get things to work, we had to go in as administrator to change the permissions on the base directory and all the other directories, after which we could delete the C:\cygwin directory, re-create it, put setup-86_64.exe in the new cygwin64 directory, then run the setup. You can try to just change the permissions for the whole directory and then re-install bash with the setup-x86_64.exe GUI, but when I tried that and then went on the Cygwin terminal, I got stuff like this.

bballdave025@MY_MACHINE ~
$ wget https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
--2020-04-26 13:08:26--  https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.68.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.68.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13765 (13K) [text/plain]
apt-cyg: Permission denied

Cannot write to ‘apt-cyg’ (Permission denied).

bballdave025@MY_MACHINE ~
$ stat .
  File: .
  Size: 0               Blocks: 24         IO Block: ██████████  directory
Device: ██████████/██████████   Inode: ██████████  Links: 1
Access: (0575/dr-xrwxr-x)  Uid: (██████████/   bballdave025)   Gid: (██████████/Unknown+Group)
Access: 2020-03-25 06:44:06.256806800 █████
Modify: 2020-03-25 06:44:04.686424000 █████
Change: 2020-04-26 09:23:47.452255300 █████
 Birth: 2019-12-26 12:34:40.017177300 █████

bballdave025@MY_MACHINE ~
$ stat /
  File: /
  Size: 0               Blocks: 4          IO Block: ██████████  directory
Device: ██████████/██████████   Inode: ██████████  Links: 1
Access: (0775/drwxrwxr-x)  Uid: (██████████/   bballdave025)   Gid: (██████████/Unknown+Group)
Access: 2020-04-26 09:34:23.227577100 █████
Modify: 2020-04-26 09:34:23.227577100 █████
Change: 2020-04-26 12:55:46.658249200 █████
 Birth: 2019-06-25 06:49:31.485205900 █████

bballdave025@MY_MACHINE ~
$ chmod u+w .
chmod: changing permissions of '.': Permission denied

bballdave025@MY_MACHINE ~
$ # It's not going to be very useful like this.

By the way chmod -R u+w / just led to a lot of Permission denied errors as well.

IF YOU HAVE FILES TO RECOVER, YOU HAVE PROBABLY THE SECOND BEST CHANCE OF DOING IT, NOW.

One way to do the deletiion is to follow the directions from this appuals tutorial (archived). You'll need admin privileges to run CMD as administrator.

You can also do it with Windows Explorer, but you'll probably need to run explorer as admin. I tried changing permissions like this as well, but with no luck.

From the type menu, search cmd, then run as administrator. See the screeshot below.

Steps to run CMD as Admin

Take ownership

takeown /r /d y /f C:\cygwin64

Notice that the command's two constituent words are 'TAKE OWN' not 'TAKE DOWN'. Also note that this command will probably take a long time, on the order of 5-20 minutes for my almost-full install (archived).

Next, we're giving everyone full permissions.

icacls C:\cygwin64 /t /grant Everyone:F

We could, once again, try to go back and install/re-install bash, but I don't like the security implications of what was just done.

IF YOU HAVE FILES TO RECOVER, YOU HAVE PROBABLY THE SECOND BEST CHANCE OF DOING IT, NOW. I mean that, if you install or re-install bash using the setup-x86_64 GUI at this point, or even if you just use Windows File Explorer, this is your best chance.

I'd rather just delete this Cygwin and get a new installation. IF YOU HAVE TRIED TO RECOVER ANY FILES YOU CAN, go ahead and run the following command.

rmdir /s /q C:\cygwin64

After this delete, and before re-installation, make sure you use

Windows + R and then regedit, then remove/delete everything in the Software\Cygwin folder in HKEY_LOCAL_MACHINE and HKEY-CURRENT-USER.

Solution 3

I had the same problem after a default fresh install directly from the web.

I solved it by going to "C:\cygwin64\bin" and duplicating "ash.exe" and renaming the copy to "bash.exe".

(I was trying this by pure chance, just because bash was missing and I found this ominous ash file)

Solution 4

This is how I stumbled on this error:

I was trying to delete a write-protected folder, but it wasn't working:

sudo rm -rf New\ folder/

I was trying to see why the rm command is failing, so I searched on how to keep the new terminal window that opens, prevent it from closing: https://askubuntu.com/questions/20330/how-to-run-a-script-without-closing-the-terminal

Which suggested adding $SHELL to the end of the command, little did I know $SHELL is /bin/bash so rm basically removed the bash:

sudo rm -rf New\ folder/ $SHELL ; WARNING: DO NOT RUN THIS.

I tried reinstalling Cygwin, but for some reason it doesn't check for missing files, but hopefully I had a backup of my C drive so I copied the bash.exe from my backup to my Cygwin folder, but what you have to do is do a clean install and you should get back bash.exe if you get this error.

And btw, sudo is an alias I have set before:

alias sudo='cygstart --action=runas'

And the folder became write-protected because I ran this command inside it, I was trying to change the extension of multiple mp3 files to flac (I was testing something):

find . -iname '*.mp3' -exec bash -c 'mv -- "$1" "${1%.mp3}.flac"' bash {} \;
Share:
14,835

Related videos on Youtube

Hashim Aziz
Author by

Hashim Aziz

Updated on September 18, 2022

Comments

  • Hashim Aziz
    Hashim Aziz over 1 year

    I've just downloaded and installed Cygwin on Windows 7. It seems to have installed successfully, with the C:\Cygwin64 folder comprising 1.2GB of data when the installation folder I installed it from was just under 300MB. However, clicking the desktop shortcut opens mintty.exe, which then displays the error:

    Failed to run '/bin/bash': No such file or directory

    This is despite the fact I installed all of the base files, of which bash was supposedly part of - and even if it wasn't, the installer later showed it as a required package and installed it itself. So does anyone have any idea what's happening here? This might be my fourth attempt in the last day trying to get a successful install of Cygwin working; I'm starting to think I'm just not meant to have it.

    • Admin
      Admin over 7 years
      Navigate to C:\Cygwin64, do you see there a file cygwin.bat ? Try to double click on it and let us know what happened
    • Admin
      Admin over 7 years
      The .bat file was there, but clicking it made cmd flash for a fraction of a second and did nothing else. Still, I've managed to sort this now, as detailed in my answer. Thanks anyway, @Alex.
    • Admin
      Admin over 4 years
      In your case, where a batch file closes too fast, you can always edit the .bat by adding a PAUSE as a last command. (Sometimes the batch is more complex, containing if, elseif, else branches, so the end of the batch might be somewhere inbetween. In those cases you would need to add a PAUSE within the conditions)
  • Alex
    Alex over 7 years
    file base installation is convenient choice when you already setup some cygwin installation and need to spread it across another computers. This way first you download from inet, and installation folder would stuffed full of packages on the end of installation that you can reuse on other computers later.
  • Hashim Aziz
    Hashim Aziz over 7 years
    Agreed. Thankfully I didn't need it that urgently, so I can do without it, but it is a shame that it wasn't installing properly that way, could have been useful in the future.
  • Phoenix
    Phoenix about 4 years
    Yes. This may work. But the ash.exe in the OP's could be something else then the bash.exe