Sudipta Chatterjee
Sudipta Chatterjee

Reputation: 4670

Cygwin - command not found

Running bash commands in cygwin produce the following error:

$ ls
ls: command not found

This is a question that I self-answered on my tech blog where I keep the tech-tips which I need to give to myself from time to time, so I decided to move it over here instead. The original blog post is here: http://thehacklist.blogspot.com/2009/04/cygwin-ls-command-not-found.html

If you are a linux enthusiast and really miss those greps and sed/awks on the windows box, you've probably installed cygwin. You tried running it either by double-clicking the cygwin icon on your desktop or the cygwin.bat file in your C:\cygwin directory and got the bash-3.X$ prompt. However, although the pwd or cd commands work, if you try ls, it says:ls: command not found.

Upvotes: 74

Views: 100458

Answers (4)

Niko
Niko

Reputation: 680

Just in case someone want to do the same thing as approved answer in PowerShell:

 [Environment]::SetEnvironmentVariable('Path', $Env:Path + "C:\cygwin64\bin;", 'User')
  • Here I'm on Windows 11 so my Cygwin path have 64 in the name (C:\cygwin64\bin).
  • I used scope 'User' but if you want to set it globally you should run PowerShell as Admin and use scope 'Machine'
  • I'm putting ; at the end because my $Env:Path ends with it. If it's different for you use $Env:Path + ";C:\cygwin64\bin"

Upvotes: 1

chantey
chantey

Reputation: 5827

I was able to resolve this by adding C:\cygwin\bin to the Windows path.

Maybe not suitable for every use-case but got the job done in my situation.

Upvotes: 0

Sudipta Chatterjee
Sudipta Chatterjee

Reputation: 4670

  1. Right click on "My Computer" -> Properties -> Advanced -> Environment Variables
  2. Add a new environment variable, called CYGWIN_HOME and set its value to C:\cygwin
  3. Edit the PATH environment variable and add %CYGWIN_HOME%\bin to it (usually separated by a ';').
  4. Just click okay, exit any command prompts or bash shells (over cygwin) you may have open, and open it again - it'll work!

Assumption - this assumes that you have installed cygwin at C:\cygwin. If you've kept it someplace else, please modify the above accordingly.

Upvotes: 103

michael
michael

Reputation: 9759

Check the cygwin.bat file, it should have something like:

set PATH=C:\cygwin\bin;C:\cygwin;%PATH%
...etc
bash --login -i

(you don't really need c:\cygwin in there, but I have some additional scripts/bat files there; the key thing is c:\cygwin\bin)

Upvotes: 16

Related Questions