# Set environment variables (/docs/guides/runtime/set-env)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 333 · updated: 2026-07-28 -->
Related: [Delete directories](/docs/guides/runtime/delete-directory.md), [Delete files](/docs/guides/runtime/delete-file.md), [Import a HTML file as text](/docs/guides/runtime/import-html.md), [Import a JSON file](/docs/guides/runtime/import-json.md), [Import a JSON5 file](/docs/guides/runtime/import-json5.md), [Import a TOML file](/docs/guides/runtime/import-toml.md)

Access the current environment variables with `process.env` or `Bun.env`.

```ts index.ts icon="/icons/typescript.svg"
Bun.env.API_TOKEN; // => "secret"
process.env.API_TOKEN; // => "secret"
```

***

Set these variables in a `.env` file.

Bun reads the following files automatically (listed in order of increasing precedence).

* `.env`
* `.env.production`, `.env.development`, `.env.test` (depending on value of `NODE_ENV`)
* `.env.local` (not loaded when `NODE_ENV=test`)

```ini .env icon="settings"
FOO=hello
BAR=world
```

***

You can also set variables on the command line.

<CodeGroup>
  <CodeBlockTabs defaultValue="Linux/macOS">
    <CodeBlockTabsList>
      <CodeBlockTabsTrigger value="Linux/macOS">
        Linux/macOS
      </CodeBlockTabsTrigger>

      <CodeBlockTabsTrigger value="Windows">
        Windows
      </CodeBlockTabsTrigger>
    </CodeBlockTabsList>

    <CodeBlockTab value="Linux/macOS">
      ```sh icon="terminal" 
      FOO=helloworld bun run dev
      ```
    </CodeBlockTab>

    <CodeBlockTab value="Windows">
      ```sh icon="windows" 
      # Using CMD
      set FOO=helloworld && bun run dev

      # Using PowerShell
      $env:FOO="helloworld"; bun run dev
      ```
    </CodeBlockTab>
  </CodeBlockTabs>
</CodeGroup>

***

See [Environment variables](/runtime/environment-variables).
