# Set

Set an environment variable.

### Syntax

```
$ vela env set <key> [--public] -t <target>
```

```
$ vela env set STRIPE_SECRET_KEY -t production   # prompts, without echo
$ vela env set WHATSAPP_MODE --public -t preview # prompts, with echo
$ vela env set VELASTACK_API_KEY -t all          # every server the app is deployed to
$ vela env set STRIPE_SECRET_KEY                 # asks which environment first
```

The value is always prompted for, never taken as an argument, so it cannot land in shell history. A secret is typed without echo; a public value with echo, so the prompt tells you which kind you are setting. The key has to be a valid environment variable name.

### Options

- `--public` - Readable back with [`vela env get`](/docs/env/get) and in [`vela env list`](/docs/env/list). Without it the value is secret: written, never read back. `PUBLIC_*` keys are public regardless, since SvelteKit ships them to the browser.
- `-t, --target <target>` - `local`, `all`, `preview`, `preview:<branch>`, `production` or a bound target. Asked for when missing; required in CI.

Setting a key again with or without `--public` moves it between the two.

### What happens next

On a server the instance is restarted so the value takes effect; `-t all` and `-t preview` restart every instance the layer reaches, on every bound server. Two exceptions, each said aloud: a key the app imports from `$env/static` is baked at build time, so the command says "redeploy to apply" instead; and the PocketBase superuser credentials wait for a [`vela deploy`](/docs/deploy), which is what reconciles them with the database.

Locally the value is written to `.env`; restart [`vela dev`](/docs/dev) to pick it up.