System variable PATH Windows
| What is used for | |
| Example | |
| Add a directory to PATH | |
| Explore the PATH contents | |
| Errors | |
| Postgesql |
What is used for
When you execute a command in a console, the system looks for a match.
between the name of the commands and the program that can be executed.
Searching the entire hard drive would take too long, so search
It only works on some directories.
A list of these special directories is stored in the PATH system variable.
Example
Suppose that it is necessary to run a program, for example.
Firefox
directly from the command line.
Without prior preparation entry Firefox The console will give you an error.
C:\Users\a>firefox
'firefox' is not recognized as an internal or external command, operable program or batch file.
To solve this problem, you need to add a directory with a firefox voice file to PATH.
Add a directory to PATH
A quick way to move on to PATH editing is to press the Win key and type in search. env
Step by step:
Right Click on This PC → Properties
Additional system settings (advanced system settings)
Additional (Advanced) → Environmental Variables
If you want to change for the whole system, then in the window "Variable environments"
(System Variables)
Find the PATH string in the block
System variables (System variables)
Click and click the button «Change. .» (Edit...)
If you want to change only for your user, do it in the block.
«User variables for %USERNAME%» (User variables for %USERNAME%)
Create a New Path (New)
Enter the address of the directory in which the desired program is located. In our case, this is
C:\Program Files (x86)\Mozilla Firefox
Restart the console or open a new one and write firefox.
C:\Users\a>firefox
The browser should start.
Explore the PATH contents
PowerShell is enough to do.
echo $Env:Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
Or
Get-ChildItem Env:Path
Name Value ---- ----- Path C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPo...
In cmd.exe see the list of variables environment can be performed by command set No parameters.
set
The output contains system and user variables and additional information. PATH content is highlighted in green.
Errors
-bash: syntax error near unexpected token `('
Most likely, you are trying to add to the unix PATH address from Windows, with spaces, brackets and so on.
For example:
andrey@olegovich-10:/usr/share$ export PATH=/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath_target_1128437:$PATH
-bash: syntax error near unexpected token `('
To solve this problem, you need to shield spaces and brackets. If there are many routes imported and the input is very long,
It’s a little easier to write PATH=$PATH:/path if you get the record right at the end.
You also need to remember that all the extra gaps will break the import - to check you can make the entire script in one line.
in a text editor.
It is also important to remember that if you work in
bash under Windows
.
The environment variables must be set through Windows.
andrey@olegovich-10:/usr/share$ export PATH=$PATH:/mnt/c/Program\ Files\ \(x86\)/Common\ Files/Oracle/Java/javapath_target_1128437
Postgesql
Let me give you an example of using psql.
bash under Windows
This may be useful if you want to add temporarily.
Psql path to PATH to run
Postrgres
script.
In my case, psql.exe is in the folder C:\Program Files\PostgreSQL\12\bin
PATH=$PATH:/mnt/c/Program\ Files/PostgreSQL/12/bin
Related Articles:
Article author: Andrei Olegovich