Files and shell

Set an environment variable for good

Save a variable like an API URL or a token so every new terminal has it.

Fill these in once
  1. Save it in your shell settings and load them
    Terminal
    echo 'export MY_API_URL="https://api.example.com"' >> ~/.zshrc
    source ~/.zshrc

    For secrets, a .env file in your project is usually safer than your shell settings.

Check it worked

  1. Check the value
    Terminal
    printenv MY_API_URL
Undo it
  1. Remove it
    Terminal
    sed -i '' '/^export MY_API_URL=/d' ~/.zshrc && unset MY_API_URL
  1. Save it in your shell settings and load them
    Terminal · Ubuntu / Debian
    echo 'export MY_API_URL="https://api.example.com"' >> ~/.bashrc
    source ~/.bashrc

    For secrets, a .env file in your project is usually safer than your shell settings.

Check it worked

  1. Check the value
    Terminal · Ubuntu / Debian
    printenv MY_API_URL
Undo it
  1. Remove it
    Terminal · Ubuntu / Debian
    sed -i '/^export MY_API_URL=/d' ~/.bashrc && unset MY_API_URL
  1. Save it for your user
    PowerShell
    [Environment]::SetEnvironmentVariable("MY_API_URL", "https://api.example.com", "User")

    Close and reopen PowerShell afterwards.

Check it worked

  1. Check the value
    PowerShell
    [Environment]::GetEnvironmentVariable("MY_API_URL", "User")
Undo it
  1. Remove it
    PowerShell
    [Environment]::SetEnvironmentVariable("MY_API_URL", $null, "User")