Possibly the easiest manual way is in Windows 10 and Windows 2012 R2 (likely previous versions too but don’t have them handy while writing this):
- From the Desktop, right click on the Windows icon (Start Menu) in the bottom left of the screen
- Click on “System”
- Click the “Advanced system settings” link in the left column.
- In the “System Properties” window, click on the “Advanced” tab, then click the “Environment Variables” button near the bottom of that tab.
- In the “Environment Variables” window, highlight the “Path” variable in the “System variables” section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon”
- When done adding paths click the “OK” button on the “Edit System Variable” windows, the “OK” button on the “Environment Variables” window, the “OK” button on “System Properties” and close the “System” window.
This automated way is a little quicker, as with other code on my site make sure you understand what it’s doing before you do it on a production server.
function AddSystemPaths([array] $PathsToAdd) { $VerifiedPathsToAdd = "" foreach ($Path in $PathsToAdd) { if ($Env:Path -like "*$Path*") { echo " Path to $Path already added" } else { $VerifiedPathsToAdd += ";$Path";echo " Path to $Path needs to be added" } } if ($VerifiedPathsToAdd -ne "") { echo "Adding paths: $VerifiedPathsToAdd" [System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + "$VerifiedPathsToAdd","Machine") echo "Note: The new path does NOT take immediately in running processes. Only new processes will see new path." } }
AddSystemPaths ("C:\java\bin") # or AddSystemPaths ("C:\java\bin","c:\TeamCity\bin")