5

I am using Windows 11. In the terminal, the usual Linux commands are not available. So commands such as chmod and vim return command line errors like:

vim : The term 'vim' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ vim ~/.bashrc
+ ~~~
    + CategoryInfo          : ObjectNotFound: (vim:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

How can I fix this? I am using Windows after a gap of a decade, so kindly bear with me!

user2357112
  • 428
  • 1
  • 4
  • 8
tachyon
  • 279
  • 2
  • 8
  • 11
    You need to install WSL (Windows Subsystem for Linux). Use something like an Ubuntu WSL guest from the Microsoft Store. – John Mar 10 '23 at 15:47
  • 49
    It's called by 'Windows not being Linux'. You can get the GNU Core Utils for Windows and put the executables in a folder on your `%PATH%` and get quite a lot of the standard things https://gnuwin32.sourceforge.net/packages/coreutils.htm – Michael Harvey Mar 10 '23 at 15:49
  • 1
    I haven't used it, but [Vim Windows Install Guide – How to Run the Vim Text Editor in PowerShell on your PC](https://www.freecodecamp.org/news/vim-windows-install-powershell/). Also, [How to change file permissions on Windows via powershell / cmd?](https://superuser.com/questions/1539172/how-to-change-file-permissions-on-windows-via-powershell-cmd) But I guess you want something more general as a proper answer. – Andrew Morton Mar 10 '23 at 16:00
  • 6
    Another so far unmentioned tool is [Cygwin](https://www.cygwin.com/). – Peregrino69 Mar 10 '23 at 16:02
  • 11
    I myself would suggest WSL over anything else. It is 100% Linux, not a Windows port of something but when not an option the ports work too. – Señor CMasMas Mar 10 '23 at 16:27
  • 2
    Couldn't agree more, @SeñorCMasMas. I did use Cygwin for years at work, WSL wasn't even a thing. I might still opt for it, depending on the available system resources :-) – Peregrino69 Mar 10 '23 at 16:51
  • @AndrewMorton Regarding Vim for Windows, I have used it, and it is pretty good, though it’s historically been hampered a bit by the limitations of the console host, and there are some otherwise useful things that would normally be done using shell commands that are much more difficult on Windows due to the lack of things like `fmt` or `uniq`. – Austin Hemmelgarn Mar 11 '23 at 00:56
  • 1
    Installing [Git Bash](https://superuser.com/questions/1053633/what-is-git-bash-for-windows-anyway) is by far the easiest (and lightweight) way to get the common Linux tools. I think it is what you get when you [install Git for Windows](https://git-scm.com/download/win) (it uses a standard Windows installer). – Peter Mortensen Mar 11 '23 at 07:58
  • 5
    Note that you mention two very different "commands": `chmod` is a (presumably thin) wrapper around a *system call* of the same name which does not even exist under Windows. You could try to write a program that does something semantically close on Windows (cygwin and msys do that), but it will always be a kludge. `vim`, on the other hand, is a perfectly normal user program which has nothing to do with the operating system it is running on and has, consequently, been ported to many, including Windows. – Peter - Reinstate Monica Mar 11 '23 at 21:40
  • What I want is for Linux and Windows to both make ifconfig and ipconfig synonyms. I'll live with the flags being different. – IllusiveBrian Mar 12 '23 at 02:38
  • 1
    @IllusiveBrian like on a Mac where both ifconfig and ipconfig exist but do different things? That way lies madness! – Criggie Mar 12 '23 at 07:59
  • 5
    A reasonable counter-question is "Why do you expect Windows to have Linux tools?" – Thorbjørn Ravn Andersen Mar 12 '23 at 09:47
  • @MichaelHarvey the CoreUtils are a bit outdated (Last change 2005). I prefer [cmder](https://github.com/cmderdev/cmder/releases). You don't need to install the full package, just extract `vendor\git-for-windows\usr\bin` from the zip-file and you also get quite a lot of the standard things, incl. `awk` or `vim` – Wernfried Domscheit Mar 12 '23 at 19:17
  • There are several distributions of "Linux" baseutils for Windows, like cygwin, WSL, unxutils, but vim is no basic utility that every Linux has. Many install vim-tiny by default, on most unices some kind of vi (without m) is preinstalled and uncomfortable to use if you're used to vim, but one still would not consider it a standard tool. Vim itself provides a Windows version which can be used from powershell, but you have to install it, like you have to install the vim package on Linux if it is not installed. – allo Mar 13 '23 at 12:17
  • There is no fix, Windows is not Unix (WINUX). If you'd type `vim` and the vi improved text editor showed up in vanilla Windows 11, I'd stop using immediately it as it is not Windows 11. – Iuri Guilherme Mar 13 '23 at 14:33

6 Answers6

60

Windows is not Linux. There is no support for Linux commands or utilities on Windows without installing the Windows Subsystem for Linux (WSL), third party tools like MinGW-w64 or Cygwin, or a Linux virtual machine.

Depending on what your requirements are, one of these or another third party tool/suite will very likely suit your needs.

If you edit your question with some more details, we can point you to the most appropriate solution.

Keltari
  • 71,875
  • 26
  • 179
  • 229
  • 29
    also note that commands like `chmod` cannot work properly for windows filesystems (NTFS), since the permissions system is entirely different, so even if you installed additional components, commands like that would either only be the same in name (while requiring entirely different args and options and functioning entirely differently), or simply be unable to function. – Frank Thomas Mar 10 '23 at 16:47
  • 8
    @FrankThomas It is interesting that the OP specifically called out `chmod`. `vim` I get, as its a text editor. Thats why I asked what he is trying to do. – Keltari Mar 10 '23 at 22:00
  • 6
    "There is no support for Linux commands". But Windows PowerShell does alias common UNIX/Linux commands. Examples include `ls`, `rm`, `mv`, `pwd`, `ps`, `wget`, `man`, etc. This is where the confusion comes from. – user71659 Mar 11 '23 at 06:14
  • 4
    @user71659: Yes, and [Microsoft doesn't document the aliases](https://pvm-professionalengineering.blogspot.com/2019/10/powershell-aliases-and-missing.html), at least not on the cmdlets' primary documentation pages. `ls`, `dir`, and `gci` are aliases for [`Get-ChildItem`](https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-ChildItem). `del`, `erase`, `rd`, `ri`, `rm`, and `rmdir` are all aliases for [`Remove-Item`](http://technet.microsoft.com/en-us/library/hh849765.aspx). - – Peter Mortensen Mar 11 '23 at 07:47
  • 2
    cont' - `mi`, `move`, and `mv` are aliases for [`Move-Item`](https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.management/Move-Item). `gl` and `pwd` are aliases for [`Get-Location`](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/get-location). – Peter Mortensen Mar 11 '23 at 07:47
  • 2
    @PeterMortensen Correct. I always thought the linux aliases where a bit strange and out of place. Why use them, if they dont support the linux CLI switches? It would only cause confusion, which it might have done in the OPs case. – Keltari Mar 11 '23 at 14:35
  • 2
    @Keltari well they needed aliases, typing `Get-ChildItem` is just too slow, for something you type that often. `ls` is just so nice to type. The confusion is only momentary - it should be immediately obvious that it's not really the linux command. Try `Get-Alias` to see all of them – Nacht Mar 12 '23 at 08:26
  • @PeterMortensen see `Notes` part at the end of the cmdlet's manual pages above, they show the available aliases – phuclv Mar 13 '23 at 00:45
  • Making a random file "executable" means completely different things in Windows than for Linux. Even the word "executable" has different meanings in the two OSes. – Nelson Mar 13 '23 at 07:58
  • @Nelson Windows does have an execute right on files, it's on by default but `chmod -x` from Cygwin can make executables (.exe) non-executable. – Oskar Skog Mar 13 '23 at 17:05
  • Cygwin provides windows versions of the core-utils IIRC – ScottishTapWater Mar 13 '23 at 21:25
10

Windows and Linux are distinguishable operating systems, By default, there is no support for Linux commands or shell commands. But you can install Windows Subsystem for Linux (WSL) to enable the execution of Linux commands on the system.

It is imperative to note that Windows Subsystem for Linux (WSL) is only available for Windows 10 and later versions. It is not compatible with any prior versions of the Windows operating system.

There are several third-party tools available for running Linux commands on Windows systems, such as

Git Bash
Cygwin
MSYS2
Babun
Gow
UWin
MinGW
PowerShell with Windows Compatibility Pack

It is up to the user's discretion to decide whether to install WSL or use third-party applications to execute Linux commands on their Windows system.

You can also use Oracle VM VirtualBox to run multiple operating systems simultaneously on a single computer, without the need for separate hardware, including Linux.

  • 1
    You can also use the built in Hyper-V to run Virtual Machines. – OrangeDog Mar 11 '23 at 12:53
  • SFU and SUA are the equivalent of WSL1 for various earlier versions of Windows NT. – Neil Mar 12 '23 at 01:07
  • @OrangeDog Absolutely, but it has its own benefits and limitations such as `No support for OpenGL acceleration`, Hyper-V does not provide support for OpenGL acceleration, which can impact the performance of graphics-intensive applications running in a virtual machine. Oracle VirtualBox supports this feature. – Sai kiran Reddy Mar 17 '23 at 15:03
3

In Windows PowerShell, some Linux commands cannot be used because there are predefined aliases for them.

For example, ls is an alias for Get-ChildItems or cat is an alias for Get-Content. But as the other users already said Windows has no native support for Linux executables.

You can see all aliases that are set by using the Command Get-Alias and you can define your own by using Set-Alias -Name "youralias" -Value "yourcommand" and you can persist them by adding them to your profile file. You can find your profile in the $profile variable. PowerShell profile files are comparable to .bashrc.

tachyon
  • 279
  • 2
  • 8
Daniel
  • 31
  • 1
  • Windows 10 and 11 do have native support for Linux executables through WSL, but this is not normally installed by default. – PC Luddite Mar 11 '23 at 22:55
1

Linux in many ways follows the POSIX standards and has its own ports of various applications - typically from Gnu userland tools. You'd find subtle differences between the same commands from gnu, busybox, various olschool unixes and BSD varients.

Windows isn't designed to be a POSIX OS, with inspiration from DOS and Windows 9x tools, and its own kernel and userland.

Its a bit like trying to work out why a train and a car have different controls. Simply, someone using windows wouldn't be expected to 'intuitively' expect a unix-alike environment.

The gap's closed a little with WSL, ports for gnu tools to windows and some standard tools in powershell having Aliases.

To an extent this is a user problem - you need to recaliberate yourself to using windows and either finding the native commands (and learning or aliasing them) with things like chmod, or installing the tools you need by installing ports of things like Vim

Journeyman Geek
  • 127,463
  • 52
  • 260
  • 430
0

Yes, you can use VIM inside Windows machine by installing the git bash for windows architecture.

  • Git bash is similar to a linux terminal, so you can use linux commands on it.

Reference0

Reference1

  • 1
    `vim` has nothing to do with git bash. There are standalone Windows vim ports that runs directly. If one just needs vim there's no reason to install git bash – phuclv Mar 13 '23 at 00:46
  • This is a bit of a heavy handed response - the git installer comes bundled with a bunch of optional unix tools one of which being bash & vim and such.. but you can install those elements, through arguably better means, separately. This answer only really makes sense if you are going to install git anyway, and still then doesn't make them accessible from powershell or command prompt. – James T Mar 13 '23 at 10:44
-7

Many of these tools are GPL licensed and can't be shipped together with proprietary windows without Microsoft having to release source code also under the GPL.

DavidPostill
  • 153,128
  • 77
  • 353
  • 394
akostadinov
  • 1,375
  • 1
  • 15
  • 22
  • I think you can ship the tools and point to their sources. Windows will not include GPL sources in that case nor link to any GPL library, hence will not be bound to release proprietary code. – vkubicki Mar 12 '23 at 12:34
  • @vkubicki, true that independent programs could be distributed as aggregate work. But GPL restricts distributing binaries, not sources. Also "linking" is interpreted in a broader sense, not only library linking. You can check here: https://www.gnu.org/licenses/gpl-faq.html#MereAggregation ; for example one reason windows cmd is so inconvenient is lack of `readline` support because it is GPL and needs to be linked. `vim` might be alright. `chmod` is something UNIX specific and would require windows internals to work. – akostadinov Mar 12 '23 at 13:01
  • @vkubicki, `vim` even isn't GPL but likely would require more advanced terminal support than `cmd`, then you need to compile a terminal emulator and who knows what other libraries would be needed. While surely windows has a different paradigm and they want to keep users locked-in, that would be a complicated licensing situation to get things distributed in a safe way together on windows. Moreover at a time Microsoft wanted to prove that GPL was cancer. So licensing certainly played a big role. – akostadinov Mar 12 '23 at 13:05
  • I am not on my PC machine at the moment, but I think once you launch WSL from the standard windows terminal, you get access to Vim. – vkubicki Mar 12 '23 at 14:28
  • @vkubicki, WSL is a linux VM last time I heard. So not sure what's the point. – akostadinov Mar 12 '23 at 21:41
  • @akostadinov the point is to get access to a subsystem of linux in a windows system. Just because you personally do not like windows does not mean it is completely replaceable for the average user by linux. Even power users of linux - as OP appears to be - clearly have a use case for windows over linux else they would not have made the switch in the first place. When someone asks a question on this site, the answer should never be "don't do that" without _extremely_ sound reasoning. – James T Mar 13 '23 at 10:48
  • @JamesT, "don't do" was just a thong in cheek side advice. Nothing to do with the actual answer that concerns licenses. I expected to get downvotes from windows fanboys but I don't care so much about reputation. Be well and not take things so serious ;) – akostadinov Mar 13 '23 at 11:16
  • 2
    This is really a comment and **not** an answer to the original question. You can always comment on your own posts, and once you have sufficient [reputation](https://superuser.com/help/whats-reputation) you will be able to [comment on any post](https://superuser.com/help/privileges/comment). Please read [Why do I need 50 reputation to comment? What can I do instead?](https://meta.stackexchange.com/a/214174). – DavidPostill Mar 13 '23 at 12:47
  • I've undeleted your post and cleaned it up. – DavidPostill Mar 13 '23 at 18:06