Why some programs need a Path value, and some others don't in Windows?
Solution 1:
I answered this for Microsoft Windows. I see there is also a Linux tag on here. Well, the same concepts apply. (Further Linux notes are mentioned in the last paragraph.)
You can use programs if they aren't in a directory specified by the PATH environment variable. However, it is a bit less convenient.
For instance, I often run 7-Zip even though it isn't in the path. So instead of starting the command line with "7z", I make the command line start with:"C:\Program Files\7-Zip\7z.exe"
That isn't quite as bad as it looks, because what I actually type is usually something more like:
C:\ tab Pro tab 7 tab 7 tab
(I listen for beeps which can happen if there are typos, and after my final expansion with the tab key, I also check the command line for accuracy, to make sure it runs what I wanted it to.)
A program can check how you referred to the program on the command line, and can check your current directory. So a program could act different based on if it is in the PATH. However, that is unlikely.
An alternate solutions: Adjust the PATH environment variable to also include the directory where a program is installed.
Another alternate solution: Simply place the executable file into a directory that is already in the PATH. (However, some programs are more complicated, because they may also need other files, like DLL files, copied into such a directory; therefore, this approach is usually not recommended for programs that you need to "install", by running an "installation program". However, for simple executables that can just be run without needing a bunch of support files, this is often viable.)
In Linux, there are some minor differences: You would just use "echo ${PATH}
" instead of "echo %PATH%
", use forward slashes instead of backslashes, use 7za
for 7-Zip instead of 7z.exe
. If you wish to adjust the path, you may use a different command, like export
, but really depending on what shell you use.)
Solution 2:
Why some programs need a Path value, and some others don't in Windows?
Why When I install Composer on Windows 7/8/10, or some UNIX-suited programs like GNU Tar, I need to set their Path value, and if I don't, it won't be usable by other programs?
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.
DOS, OS/2, and Windows
Some programs may add their directory to the front of the PATH variable's content during installation, to speed up the search process and/or override OS commands. In the DOS era, it was customary to add a PATH {program directory};%PATH%
or SET PATH={program directory};%PATH%
line to AUTOEXEC.BAT
.
When a command is entered in a command shell or a system call is made by a program to execute a program, the system first searches the current working directory and then searches the path, examining each directory from left to right, looking for an executable filename that matches the command name given. Executable programs have filename extensions of EXE
or COM
, and batch scripts have extensions of BAT
or CMD
. Other executable filename extensions can be registered with the system as well.
Unix and Unix-like
When a command name is specified by the user or an exec call is made from a program, the system searches through $PATH
, examining each directory from left to right in the list, looking for a filename that matches the command name. Once found, the program is executed as a child process of the command shell or program that issued the command.
Source: PATH_(variable)
Solution 3:
In Windows, an application can register its path under {HKCU|HKLM}\Software\Microsoft\Windows\CurrentVersion\App Paths
in the registry. Windows will then remember where to find the respective .exe file, without bloating the PATH
environment variable.
From Application Registration:
An application that is installed for per user can be registered under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths. An application that is installed for all users of the computer can be registered under HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths.
The entries found under App Paths are used primarily for the following purposes:
- To map an application's executable file name to that file's fully qualified path.
- To pre-pend information to the PATH environment variable on a per-application, per-process basis.
For example, a default Windows installation has the registry entry:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WORDPAD.EXE
(Default)="%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE"
This allows WordPad to be started from Start / Run by typing-in just wordpad
(or start wordpad
at a cmd prompt) even though %ProgramFiles%\Windows NT\Accessories
is not in the PATH.