> ## Documentation Index
> Fetch the complete documentation index at: https://www.qovery.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Import Environment Variables with the Qovery CLI

> Bulk import environment variables and secrets from a .env file

This tutorial demonstrates how to bulk import environment variables and secrets from a `.env` file using the Qovery CLI, rather than adding them individually through the web interface.

## Prerequisites

* A compliant dotenv (`.env`) file following [RFC 2-dotenv specifications](https://smartmob-rfc.readthedocs.io/en/latest/2-dotenv.html)
* An existing application created in Qovery

## Step 1: Install Qovery CLI

The installation command varies by platform:

<Tabs>
  <Tab title="Linux/Unix">
    ```bash theme={null}
    curl -s https://get.qovery.com | bash
    ```
  </Tab>

  <Tab title="macOS">
    ```bash theme={null}
    brew tap qovery/qovery-cli
    brew install qovery-cli
    ```
  </Tab>

  <Tab title="Windows">
    ```powershell theme={null}
    scoop bucket add qovery https://github.com/Qovery/scoop-qovery-cli.git
    scoop install qovery-cli
    ```
  </Tab>
</Tabs>

For additional installation methods, see the [CLI documentation](/cli/overview).

***

## Step 2: Authenticate and Set Context

### Authenticate

```bash theme={null}
qovery auth
```

This opens your browser for authentication.

### Set Context

After authenticating, specify the target application:

```bash theme={null}
qovery context set
```

Follow the prompts to select:

1. Your organization
2. Your project
3. Your environment
4. Your application

***

## Step 3: Prepare Your .env File

Create a `.env` file with your variables. For example, `.env.development`:

```bash theme={null}
# Public variables
COLOR_BACKGROUND=#F0F0F0
API_URL=https://api.example.com

# Secret variables
STRAPI_API_KEY=sk_test_1234567890abcdef
AUTH0_API_KEY_SECRET=my_super_secret_key_123
```

***

## Step 4: Import Environment Variables

### Import Public Variables

```bash theme={null}
qovery env import .env.development
```

You'll see an interactive prompt to select which variables to import:

```
? Select environment variables to import:
  ◯ COLOR_BACKGROUND
  ◯ API_URL
  ◯ STRAPI_API_KEY
  ◯ AUTH0_API_KEY_SECRET
```

Use:

* **Arrow keys** to navigate
* **Space bar** to select/deselect
* **Enter** to confirm

Select the public variables (`COLOR_BACKGROUND` and `API_URL`) and press Enter.

<Info>
  Public environment variables are visible in the Qovery Console and can be viewed by team members.
</Info>

***

## Step 5: Import Secrets

For sensitive data, import as secrets:

```bash theme={null}
qovery env import .env.development
```

When prompted, select **"Secrets"** instead of "Environment Variables", then choose the secret variables:

```
? Select type:
  ◯ Environment Variables
  ◉ Secrets
```

Select the sensitive variables (`STRAPI_API_KEY` and `AUTH0_API_KEY_SECRET`) and press Enter.

<Warning>
  Secrets are encrypted and cannot be viewed in plain text after import. They can only be updated or deleted.
</Warning>

***

## Step 6: Verify Import

### Via Qovery Console

1. Navigate to your application in Qovery Console
2. Go to **Variables** tab
3. Verify both environment variables and secrets are present

### Via CLI

```bash theme={null}
# List environment variables
qovery env list

# List secrets (values will be hidden)
qovery secret list
```

***

## Advanced Usage

### Import from Different Files

```bash theme={null}
# Development environment
qovery env import .env.development

# Production environment
qovery env import .env.production
```

### Override Existing Variables

Use the `--force` flag to override existing variables:

```bash theme={null}
qovery env import .env.development --force
```

### Import Specific Variables

You can also manually specify which variables to import by editing your `.env` file before importing.

***

## Best Practices

<AccordionGroup>
  <Accordion title="Never commit .env files to Git">
    Add `.env*` to your `.gitignore` file to prevent accidentally committing secrets:

    ```
    # .gitignore
    .env
    .env.*
    ```
  </Accordion>

  <Accordion title="Use different files for different environments">
    Maintain separate `.env` files for each environment:

    * `.env.development`
    * `.env.staging`
    * `.env.production`
  </Accordion>

  <Accordion title="Always use secrets for sensitive data">
    Mark these as secrets:

    * API keys
    * Database passwords
    * OAuth client secrets
    * Encryption keys
    * Third-party service tokens
  </Accordion>

  <Accordion title="Document your environment variables">
    Create a `.env.example` file with placeholder values:

    ```bash theme={null}
    # .env.example
    COLOR_BACKGROUND=<hex_color>
    API_URL=<your_api_url>
    STRAPI_API_KEY=<your_strapi_key>
    AUTH0_API_KEY_SECRET=<your_auth0_secret>
    ```
  </Accordion>
</AccordionGroup>

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="Import failed: invalid format">
    Ensure your `.env` file follows the RFC 2-dotenv specifications:

    * One variable per line
    * Format: `KEY=value`
    * No spaces around the `=` sign
    * Comments start with `#`
  </Accordion>

  <Accordion title="Variables not appearing in console">
    * Verify you imported to the correct application
    * Check you ran `qovery context set` before importing
    * Refresh the Qovery Console page
  </Accordion>

  <Accordion title="Cannot see secret values">
    This is expected behavior. Secrets are encrypted and cannot be viewed in plain text for security reasons.
  </Accordion>
</AccordionGroup>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Environment Variables" icon="key" href="/configuration/environment-variables">
    Learn about environment variables in Qovery
  </Card>

  <Card title="Qovery CLI" icon="terminal" href="/cli/overview">
    Complete CLI documentation
  </Card>

  <Card title="Secrets Management" icon="lock" href="/getting-started/security-and-compliance/overview">
    Understanding secrets and encryption
  </Card>

  <Card title="Application Configuration" icon="gear" href="/configuration/application">
    Configure your applications
  </Card>
</CardGroup>
