Relay365Multi-model API relay desk
← All desk bulletins
Field notes from the deskEN164 desk reads

Set Environment Variables on macOS, Linux and Windows

Understand What an Environment Variable Does

Environment variables let you pass configuration to programs without editing their source code. A variable has a name and a value, such as APP_ENV and development. Programs launched from your shell inherit its exported environment, which makes variables useful for command-line configuration. ([gnu.org](https://www.gnu.org/software/bash/manual/html_node/Environment.html?utm_source=openai))

This numbered walkthrough uses a harmless practice variable first. Follow the instructions for your operating system, then apply the same pattern to settings your application actually supports.

Choose Your Terminal and Practice Value

1. On macOS or Linux, open your terminal and run echo "$SHELL". Treat the result as a clue to your configured shell, not proof of which shell is currently running. The commands below cover Bash and Zsh. On Windows, open PowerShell; do not paste PowerShell syntax into Command Prompt.

Use APP_ENV as the variable name and development as its value. Keep the spelling consistent throughout the exercise.

Set a Variable in macOS or Linux

2. In Bash or Zsh, enter export APP_ENV='development'. Do not put spaces around the equals sign. The export instruction makes the variable available to programs you launch afterward from that shell. It does not update an application that is already running. ([gnu.org](https://www.gnu.org/s/bash/manual/bash.html?utm_source=openai))

Check the result with printenv APP_ENV. You should see development. This initial setting is temporary: saving it for future terminal sessions requires a startup-file entry.

Save Variables for Future macOS or Linux Sessions

3. For an interactive Zsh terminal, edit ~/.zshrc in your preferred text editor. Add export APP_ENV='development' on its own line, save the file, and run source ~/.zshrc. Zsh reads this file for interactive shells; a custom ZDOTDIR configuration can change its location. ([zsh.sourceforge.io](https://zsh.sourceforge.io/Intro/intro_3.html?utm_source=openai))

For an interactive, non-login Bash terminal, add the same line to ~/.bashrc, then run source ~/.bashrc. Bash login shells use different startup files: they read the first available file among ~/.bash_profile, ~/.bash_login and ~/.profile. If your setting disappears in a login terminal, check whether that file loads ~/.bashrc. ([gnu.org](https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files?utm_source=openai))

Avoid adding duplicate assignments. If APP_ENV already exists in the appropriate file, update that line instead.

Set a Variable in Windows PowerShell

4. Enter $env:APP_ENV = 'development'. Check it with $env:APP_ENV. PowerShell should display development. This changes the current process environment and is inherited by child processes launched afterward; it does not permanently save the setting. ([learn.microsoft.com](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Environment_Variables?utm_source=openai))

For a first test, launch your application from this same PowerShell window. That keeps the configuration and the application in the same process-inheritance chain.

Save a Windows Variable for Your User Account

5. To persist the value, run [Environment]::SetEnvironmentVariable('APP_ENV', 'development', 'User'). User scope saves the setting for your account rather than changing machine-wide configuration. It does not rewrite the environment of your current PowerShell process. ([learn.microsoft.com](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.4&utm_source=openai))

Close and reopen your terminal application, then check $env:APP_ENV again. If an editor launches your terminals, restart the editor too. Existing parent processes can otherwise keep passing along their older environment. ([learn.microsoft.com](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Environment_Variables?utm_source=openai))

Apply the Pattern to API Configuration Safely

6. Replace the practice name with the exact variable your tool documents. Do not assume every client recognizes the same API-key or base-URL variable. Configure one setting at a time and test before adding more.

For a pay-as-you-go relay workflow across model families, consider Relay365 when it fits your tooling. Create an account when you are ready to test, then follow the configuration instructions for your chosen client.

  • Practice with non-secret values before entering a real API key.
  • Avoid exposing credentials in screenshots, shared terminal output or committed configuration files.
  • Treat environment variables as configuration, not as an encrypted secret vault.

Remove Practice Variables and Check Your Application

7. In Bash or Zsh, run unset APP_ENV and remove its saved startup-file entry. In PowerShell, run Remove-Item Env:APP_ENV; also run [Environment]::SetEnvironmentVariable('APP_ENV', '', 'User') if you saved it persistently. Restart affected applications after changing their environment. ([gnu.org](https://www.gnu.org/s/bash/manual/bash.html?utm_source=openai))

Finish by checking behavior inside the application itself. Seeing a value in your terminal confirms the shell setting, but your application must also recognize and read that variable.

Further desk bulletins

Curious how it runs on your own code? Sign up →