---
id: upgrading
title: Upgrading to a new version
sidebar_label: Upgrading to a new version
---

:::info
Check out the [release notes](https://github.com/teslamate-org/teslamate/releases) before upgrading!
:::

:::note
Create a [backup](maintenance/backup_restore.md) before updating.
If you are using `docker-compose`, you are using Docker Compose v1, which has been deprecated. Docker Compose commands refer to Docker Compose v2. Consider upgrading your docker setup, see [Migrate to Compose V2](https://docs.docker.com/compose/migrate/)
:::

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

<Tabs
defaultValue="docker"
values={[
{ label: 'Docker', value: 'docker', },
{ label: 'Manual install (Debian)', value: 'manual_debian', },
{ label: 'Manual install (FreeBSD)', value: 'manual_freebsd', },
]}>
<TabItem value="docker">

Within the directory where the YML file is located, pull the new images:

```bash
docker compose pull
```

and restart the stack with `docker compose up`. To run the containers in the background add the `-d` flag:

```bash
docker compose up -d
```

</TabItem>
<TabItem value="manual_debian">

1. Pull the new changes from the git repository, checkout the new version and then build the new release:

   ```bash
   git pull
   git checkout $(git describe --tags `git rev-list --tags --max-count=1`)

   mix deps.get --only prod
   npm install --prefix ./assets && npm run deploy --prefix ./assets

   rm -rf _build
   MIX_ENV=prod mix do phx.digest, release --overwrite
   ```

2. Most upgrades requires to run new database migrations. If so continue with the following command:

   ```bash
    _build/prod/rel/teslamate/bin/teslamate eval "TeslaMate.Release.migrate"
   ```

   Note, you may need to include environment variables when running this step:

   ```bash
    DATABASE_USER=teslamate DATABASE_PASS=super_secret_password DATABASE_NAME=teslamate DATABASE_HOST=localhost MQTT_HOST=your_MQTT_host(HomeAssistant in my case) _build/prod/rel/teslamate/bin/teslamate eval "TeslaMate.Release.migrate"
   ```

3. Finally, re-import the Grafana dashboards:

   ```bash
   LOGIN="user:pass" ./grafana/dashboards.sh restore
   ```

</TabItem>
<TabItem value="manual_freebsd">

1. Pull the new changes from the git repository, checkout the new version and then build the new release:

   ```bash
   bash

   git pull
   git checkout $(git describe --tags `git rev-list --tags --max-count=1`)

   mix deps.get --only prod
   npm install --prefix ./assets && npm run deploy --prefix ./assets

   rm -rf _build
   export MIX_ENV=prod
   mix do phx.digest, release --overwrite
   ```

2. Most upgrades requires to run new database migrations. If so continue with the following command:

   ```bash
    _build/prod/rel/teslamate/bin/teslamate eval "TeslaMate.Release.migrate"
   ```

   Note: you may need to include environment variables as part of this step:

   ```bash
    DATABASE_USER=teslamate DATABASE_PASS=super_secret_password DATABASE_NAME=teslamate DATABASE_HOST=localhost MQTT_HOST=your_MQTT_host(HomeAssistant in my case) _build/prod/rel/teslamate/bin/teslamate eval "TeslaMate.Release.migrate"
   ```

3. Finally, re-import the Grafana dashboards:

   ```bash
   bash
   export LOGIN="user:pass"
   ./grafana/dashboards.sh restore
   ```

</TabItem>
</Tabs>
