Environment Variables¶
Linux¶
Abstract
Most modern Linux distributions use Systemd and it's environment variables become accessible to both terminal and GUI apps. Ensure your system uses it before proceeding.
User¶
Applying Changes
Changes in environment.d require you to log out and log back in, or restart the user systemd instance.
Splitting Config Files
We can split configuration across multiple .conf files under ~/.config/environment.d/, which makes it easy to keep separate files for different providers (e.g., llm-anthropic.conf, llm-google.conf).
A nice side effect of this approach is that configs can be disabled without commenting out individual key-value pairs. Renaming a file's extension from .conf to anything else (e.g. .conf.disable) causes systemd to skip it entirely.
System¶
Windows¶
Add a New Variable¶
[System.Environment]::SetEnvironmentVariable("VAR_NAME", "Value", [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable("VAR_NAME", "Value", [System.EnvironmentVariableTarget]::Machine)
Add to PATH¶
PowerShell does not have a built-in cmdlet to safely append to the PATH without manually managing semicolons. The safest approach is to create a reusable function.
Profile Setup
Add the following function to your $PROFILE so it is always available in your PowerShell sessions.
function Add-Path {
param(
[Parameter(Mandatory=$true)]
[string]$NewPath,
[System.EnvironmentVariableTarget]$Scope = [System.EnvironmentVariableTarget]::User
)
$current = [System.Environment]::GetEnvironmentVariable("Path", $Scope)
$updatedParts = ($current -split ';' | Where-Object { $_ }) + $NewPath
$seen = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
$deduped = $updatedParts | Where-Object { $seen.Add($_) }
[System.Environment]::SetEnvironmentVariable("Path", ($deduped -join ';'), $Scope)
}