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"](https://cdn.statically.io/img/i.sstatic.net/iZfvO.png)
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:
- 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
- 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](https://cdn.statically.io/img/i.sstatic.net/kiGMp.png)
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
.
C:\Cygwin64
, do you see there a filecygwin.bat
? Try to double click on it and let us know what happenedcmd
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.PAUSE
as a last command. (Sometimes the batch is more complex, containingif, elseif, else
branches, so the end of the batch might be somewhere inbetween. In those cases you would need to add aPAUSE
within the conditions)