# pier vars

> Environment variables

URL: https://pier.run/docs/cli/reference/vars

```bash
pier vars <command>
```

Environment variables.

## Subcommands

### pier vars ls

```bash
pier vars ls
```

List environment variables.

### pier vars set

```bash
pier vars set [<key>] [<value>] [flags]
```

Set a variable (plain, secret or linked); KEY=VALUE or KEY VALUE.

| Argument  | Required | Description                  |
| --------- | -------- | ---------------------------- |
| `<key>`   | no       | Variable name (or KEY=VALUE) |
| `<value>` | no       | Variable value               |

| Flag             | Value    | Default | Description                                                         |
| ---------------- | -------- | ------- | ------------------------------------------------------------------- |
| `-s`, `--secret` |          |         | Store as secret                                                     |
| `--secret-value` | `STRING` |         | Secret value (use '-' for stdin)                                    |
| `--from`         | `STRING` |         | Link to resource reference (e.g. postgres.main.url)                 |
| `--app`          | `STRING` |         | Scope to an app (slug or slug/target)                               |
| `--site`         | `STRING` |         | Scope to a site (slug or slug/target)                               |
| `--stage`        |          |         | Write the change to pier.yaml only — apply later with 'pier deploy' |

### pier vars rm

```bash
pier vars rm [<key>] [flags]
```

Remove a variable.

| Argument | Required | Description             |
| -------- | -------- | ----------------------- |
| `<key>`  | no       | Variable name to remove |

| Flag          | Value    | Default | Description                                                         |
| ------------- | -------- | ------- | ------------------------------------------------------------------- |
| `--app`       | `STRING` |         | Scope to an app (slug or slug/target)                               |
| `--site`      | `STRING` |         | Scope to a site (slug or slug/target)                               |
| `-y`, `--yes` |          |         | Skip confirmation prompt                                            |
| `--stage`     |          |         | Write the change to pier.yaml only — apply later with 'pier deploy' |

### pier vars import

```bash
pier vars import [flags]
```

Import variables from a .env file.

| Flag          | Value    | Default | Description                           |
| ------------- | -------- | ------- | ------------------------------------- |
| `--file`      | `STRING` |         | Path to .env file (use '-' for stdin) |
| `--secret`    |          |         | Treat all imported vars as secrets    |
| `-y`, `--yes` |          |         | Skip confirmation prompt              |

### pier vars reveal

```bash
pier vars reveal [<key>]
```

Reveal the value of a secret variable.

| Argument | Required | Description             |
| -------- | -------- | ----------------------- |
| `<key>`  | no       | Variable name to reveal |

[Global flags](/docs/cli/reference#global-flags) apply to every command.

## Examples

```bash
pier vars                                   # every variable, every scope
pier vars set LOG_LEVEL=info --app api      # plain, app scope
pier vars set API_KEY --secret --secret-value - --app api < key.txt
pier vars set DATABASE_URL --from postgres.main.url --app api
pier vars import --file .env --secret       # many at once
pier vars reveal API_KEY
pier vars rm LOG_LEVEL --app api
pier deploy api                             # release the new environment version (no rebuild)
```

## Behaviour

* `set`, `rm` and `import` record the change as a new environment version and write the
  declaration to `pier.yaml`; they do not roll anything. `pier deploy <ref>` releases it
  without a build; `pier deploy` releases every target that is behind.
* A secret's value goes to the platform's vault; `pier.yaml` carries only
  `secret: true`. `reveal` prints the value for your role.

## See also

[Environment variables](/docs/vars) · [Set environment variables](/docs/guides/set-environment-variables) ·
[`pier deploy`](/docs/cli/reference/deploy)
