What is the "path" environment variable? What is the role of path?

  • Bing answers :

  • The function of path is to specify which folders the system can search in when executing a command or program. Path is an environment variable whose value consists of multiple folder paths, separated by semicolons. For example, if the value of path is C:\Windows;C:\Python;C:\Program Files\Java\bin, then when the user enters python or java in the command line window, the system will sequentially search in these three folders. Find the corresponding executable file. If it is found, the program will be run; if it is not found, an error will be reported. The path environment variable allows users to easily run some commonly used programs at any location without entering the full path.
    The difference between the path environment variable and other environment variables is that the path environment variable is often used and its variable name is fixed. The variable names of other environment variables can be customized, and their role is to set some parameters or properties according to different applications or requirements. For example, the PYTHONPATH environment variable specifies which folders the Python interpreter can look for when importing modules. The LIBRARY_PATH and LD_LIBRARY_PATH environment variables specify the folders in which the compiler and linker can find library files when compiling and running C/C++ programs.

  • Refer to Zhihu blog :

  • What are environment variables?
    Quoting the explanation from Baidu Encyclopedia: An environment variable is an object with a specific name in the operating system. To put it bluntly, it is a small thing in the operating system that is used to search for your file location and open your software. It is given a name. called environment variables. It contains information that will be used by one or more applications. After seeing this, I believe you may still have some doubts, but don’t worry, keep reading.

  • Why are environment variables needed?
    Under Windows system, if we install a certain software, after the installation is completed, an .exe (suffix name for computer software) file of the software will be generated in the installation directory. Double-click the file and we can start the software. But do we have to find the path where the .exe file is located every time we want to run the software (click here to learn what the path is), and then double-click it. This is obviously impossible because there are too many software installed. It is simply impossible to remember the paths of all installed software. At the same time, if we want to run some software in other paths, it will not run. At this time, environment variables are needed.

  • What is the role of environment variables?
    As I said just now, 1. As more and more software are installed on computers, we cannot remember the installation paths of all software, and it is very troublesome to run a certain software. 2. If you want to run a certain software directly under a certain path, there is nothing we can do.
    By adding the installation paths of all software to the environment variables, when we want to run a certain software, double-click its shortcut. At this time, in addition to looking for the .exe file of the software in its current directory, the computer will also search for the .exe file in the environment variable. Search the path of the software, find it, and run it.
    To sum up, when the environment variables in Windows require the system to run a program without telling it the full path of the program, the system should not only look for the program in the current directory, but also go to the specified path on the computer to find it. Users can better run processes by setting environment variables.

Reference content:
chatGPT4.0
Zhihu blog (https://zhuanlan.zhihu.com/p/338250520)

Guess you like

Origin blog.csdn.net/qq_45833373/article/details/132839006