0

Context: I use Fedora GNU/Linux as my main OS, but sometimes I need to work within Windows.

Over the years, using Linux distros, I have become used to working mainly through the command line, calling programs from it. For example:

  • Using neovim as a text editor
  • Running python directly from the shell
  • Compiling LaTeX with pdflatex
  • etc.

I find this workflow faster and comfier.

Problem is, to do this in Windows, I have to constantly fight with the PATH variable. Every time I want to run a new program, I have to add its path to the PATH variable. This is incredibly annoying since to do it I must follow a long GUI procedure to access the environment variables. I have read that this GUI option is best since using setx from CMD will probably cause mayhem in the long run.

In Linux it is just so easy -- You install an app and it's just automatically callable from the shell! Why doesn't Windows automatically add newly installed programs to the PATH?

And since Windows doesn't behave this way, must I put up with the hassle and manually add every single app address to the PATH, or is there an easier way?

Would PowerShell usage instead of CMD change something? I am open to every possible way to end my annoyance.

3 Answers 3

2

using setx from CMD will probably cause mayhem in the long run

This is absolute rubbish - there is nothing wrong with setx.

Why windows doesn't automatically add newly installed programs to PATH?

If Windows would have done that for the hundreds of applications that I have installed on my computer, it would have become unusable.

The difference is that, while in Linux all applications are installed into /usr/bin which is in the PATH, in Windows each is installed in a separate folder.

Would PowerShell usage instead of CMD change something?

No - as far as searching for executables is concerned, PowerShell uses exactly the same Windows mechanisms as CMD.

I am open to every possible way to end my annoyance.

If you do not wish to add to the PATH all your apps, you may use an alternative approach : You could add only one folder of yours to the PATH, then store in it shortcuts to your applications.

2
2

In Linux is just so easy: you install an app and it's just automatically callable from the shell!

That only applies to apps that install to standard locations like /usr/bin or /usr/local/bin. If you install apps from source for example, or to your own local locations then it obviously won't work that way and you'll still have to mess with $PATH

In Windows there's a standard package manager: winget. You should use it if possible and avoid each app's installer. That'll solve some of the problems, but not all, because Windows doesn't spread things around like Linux. An app on Linux stores its binaries in /usr/bin, libraries in /usr/lib, settings in /etc, many other files in /opt, /var, ~... while Windows apps put pretty much everything in a single folder for ease of management and uninstallation

Anyway regardless of the installation method, editing %PATH% to include every app you use is a wrong way to do. Not only it makes the variable longer, which causes problems in many long commands, it also makes searching for executables and libraries longer unnecessarily

There are many ways to fix that:

  • Make a shortcut or a symlink in a folder that's in %PATH%. For example add C:\MyApps to %PATH% and make a link to pdflatex, python... in that folder. Alternatively create a *.cmd/*.bat/*.ps1 file that runs the desired app
  • Add the app to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths. That's the recommended way for Application Registration and is how most proper commands like winword, excel... works. This is also easy to do from the command line or scripts
  • Create a permanent doskey macro in cmd, or alias (for simple commands) or function (for more complex ones) in PowerShell's profile

Would PowerShell usage instead of CMD change something?

No, that obviously won't change anything related to the PATH variable. The only difference in PowerShell regarding executable searching is that it doesn't search in the the current directory for security reasons just like on Linux

But PowerShell is vastly more powerful and there's no terrible legacy behaviors that need to be learned like in cmd. There's no reason to use cmd for new scripts. Lots of commands work the same or somewhat similar to Linux commands, for example the behavior of cd and cd ~ are exactly the same in PowerShell and bash (yes you can use ~ in PowerShell for home, unlike cmd where it's painful to change to your home folder)

PowerShell is even far more powerful than bash, it can do anything a native Win32 app can do, call Win32 APIs directly, do big integer math, date time calculation, GUI programming, base conversion, direct XML/JSON/string config manipulations...

1
  • 1
    You might check out ctypes.sh if you want to incorporate some of the more advanced features of PowerShell into bash.
    – doneal24
    Commented Nov 13, 2022 at 17:26
0

Why Windows doesn't automatically add newly installed programs to PATH?

It's up to the application's installer to add the program to the path. That's really true under Linux as well, of course. As others have mentioned, many packages in Linux just install to /usr/bin or similar.

However, there are applications in Linux, primarily those not installed through package-management, that install into a directory that isn't in the path. Often, the installers for these programs will modify your startup files (e.g. ~/.bashrc) or at least offer to, in order to add themselves to your path.

But ultimately, whether it is Linux or Windows, it's up to the application's installer to determine how it is launched.

There's also a difference in the "organization strategy" for applications between Linux and Windows:

  • Linux places most applications, especially those installed through the distributions package-manager, in /usr/bin or /bin (which are typically the same through a symlink). Libraries are placed in /usr/lib, etc.

  • Windows does not have a centralized package-manager, and each application installs its files (binaries, non-shared-libraries, and static data) into an application directory.

For someone coming from Windows, the "put everything in one location" concept is a bit strange as well. I've used both Windows and Linux extensively over the years, so I'm used to both, but either has its advantages and disadvantages.

Launching apps by name/keyboard

I am open to every possible way to end my annoyance.

For keyboard junkies like you and I, there are multiple alternatives in Windows:

Start Menu

Keep in mind that Windows has pretty much always had a standard graphical launch mechanism for applications, the Start menu (going back to Windows 95) and the Program Manager before that. Most users are launching GUI applications, not command-line ones. And even for keyboard-junkies like me, the Start menu provides an easy "Search" feature that allows me to simply hit the Windows key (🪟) and start typing the name of an application.

PowerToys Run

Taking it one step further (for graphical applications) is PowerToys Run (installable from the Microsoft Store by installing Microsoft PowerToys), which allows you to not only search/launch applications by name (after starting it with Alt+Space), but also Folders, Terminal profiles, and many others.

PowerShell or CMD aliases

Under PowerShell, you could simple create aliases (similar to Linux shell aliases) to launch your apps rather than adding each one to the Path. It's possible, I believe, with CMD, but the PowerShell mechanism is much more modern and user-friendly. See New-Alias (and other examples).

New-Alias nvim C:\Where\I\Installed\Neovim\nvim.exe

Windows Subsystem for Linux

As a Linux user, you may just want to consider the user of WSL under Windows and continue to use your Linux applications under Fedora when in Windows.

If you are on a recent Windows release (preferably 11, but Windows 10 also works), you can install it by starting an Admin PowerShell session and running:

wsl --install

Follow the instructions, rebooting when needed. Once you restart, run as a normal user, not Admin.

By default, this will install an Ubuntu distribution, but a version of Fedora is also available in the Microsoft Store.

Under Windows 11, you can even run graphical Linux apps out-of-the-box. It's possible on Windows 10, but requires some manual configuration.

Bonus Tip: Windows Terminal

If you prefer the commandline, you will want to install Windows Terminal. It may already be installed on Windows 11 systems, but it can be installed from the Microsoft Store if not (and for Windows 10). It's a huge upgrade from the 25-year old legacy terminal (Windows Console Host) that Windows used by default until recently.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .