# Updating

URL: https://swb.one/docs/updating

See the [SwB 1.1 release notes](/docs/release-notes).

## Keep your data [#keep-your-data]

Make a [backup](/docs/operate#backups-and-upgrades) before you update. Keep the same data folder, configuration and `.env` file. SwB uses them to keep your data and connections.

Local SwB usually stores data in `./data` in the folder where you start it. Use the same `--dir` if you set one. Keep `~/.local/share/switchboard` if your instance uses it. Keep any custom `data_dir` or `SWB_DATA_DIR` setting.

Containers and cloud services use `/data`. Compose mounts the host folder `./data` there. Keep the same disk or folder attached at `/data`.

## Check the version [#check-the-version]

Read `version` from `/healthz` to check the running server. Use the address of your server.

```sh
curl -fsS http://127.0.0.1:8870/healthz
curl -fsS https://swb.example.com/healthz
```

Run `swb --version` to check the version of the installed command.

## Automatic updates [#automatic-updates]

Follow the manual instructions on this page for the first upgrade from SwB 1.0.0.

SwB checks for new releases every six hours. By default it installs stable releases with the same first version number. It asks the owner to approve a change to that number.

SwB waits for 60 seconds of idle time before it applies an update. If the new version fails the local health check, SwB restores the previous version.

Sign in as the owner to check now. Open **Settings**, then **About**. Find the **Update** row under **Version**. In that row, select **Check and update** or **Update**.

### Local packages [#local-packages]

On Linux or macOS, run SwB from `uvx`, `uv tool install` or `pipx` with `swb up` or `swb serve`. For automatic updates, have SwB listen on localhost or all addresses. A tunnel started by `swb up` stays open during the update. Update other package installs, Windows installs and servers on a specific network interface through their original install method.

A normal restart uses the last verified package. To use an older package, restore its matching backup. Set `SWB_UPDATE_SUPERVISOR=0` when you start the older package.

### Docker Compose [#docker-compose]

Install [uv](https://docs.astral.sh/uv/) on the Docker host. Set `SWB_UPDATE_IMAGE_SUPERVISED=1` in the Compose `.env` file. Recreate the SwB service with this setting.

Run the updater on the host from the repository root. Keep it running with your service manager.

```sh
uv sync --locked --no-dev --no-install-project
uv run --no-sync python deploy/compose/update.py --layout root --watch
```

Use `--layout caddy` for the official Caddy setup instead of the source setup. Keep the Docker socket on the host. Use this updater in place of Watchtower. See [Compose maintenance](https://github.com/ZhehanZhang/SwB/blob/main/deploy/README.md#update-docker-compose) for manual updates and later service changes.

### Owner notices [#owner-notices]

Use your deployment tools for standalone Docker, Fly.io, Render, Railway, Koyeb and custom Cloudflare deployments. When an update needs action, SwB sends the owner an instruction through the active agent or the project's main route.

Cloudflare Tunnel updates happen on the machine that runs SwB. Keep the tunnel as it is.

### Update settings [#update-settings]

Use the `updates` section of your [config file](/docs/config).

```yaml
updates:
  automatic: false
  channel: '1.1'
  owner_project: my-project
```

Set `updates.automatic` to `false` to turn off automatic installation and keep release checks. Set `updates.channel` to `'1.1'` to limit automatic updates to 1.1 releases. The default channel is `stable`. Use the optional `updates.owner_project` to select a project by its short name, or slug, for owner notices.

### SwB Companion on macOS [#swb-companion-on-macos]

The native Companion app updates separately from the server. SwB checks the download's signature and notarization. Notarization is Apple's security check for the app. If an app update fails, SwB reports it to the owner.

## uvx [#uvx]

A cache is a local copy that uvx can use again. A plain `uvx swb-one up` can reuse the old release from the cache.

Stop SwB. Run either command from the same instance folder to check for the latest release and start it.

```sh
uvx swb-one@latest up
uvx --refresh swb-one up
```

To return to 1.0.0, stop SwB. Start that version with this command.

```sh
uvx swb-one==1.0.0 up
```

## pipx [#pipx]

Stop SwB. Upgrade the `swb-one` package. Start SwB from the same instance folder.

```sh
pipx upgrade swb-one
swb up
```

To return to 1.0.0, stop SwB. Install that version. Start SwB.

```sh
pipx install --force swb-one==1.0.0
swb up
```

## Docker Compose and GHCR [#docker-compose]

The [Compose setup](/docs/deploy#docker-compose) builds `switchboard:local` from the repository. Update the source in your local copy. Rebuild the SwB service in that folder.

```sh
git switch release/1.0
git pull --ff-only origin release/1.0
docker compose up -d --build --no-deps switchboard
```

A Git tag marks the source of a release. To return to 1.0.0, get its tag. Switch to that tag. Rebuild SwB.

```sh
git fetch origin tag v1.0.0
git switch --detach v1.0.0
docker compose up -d --build --no-deps switchboard
```

GitHub Container Registry, or GHCR, stores ready-to-run images. An image contains SwB and the files it needs to run. A tag selects a version of that image.

To use the published image with the repo's Compose file, add this to `compose.override.yaml`. Give user ID `10001` access to the mounted data and configuration.

```yaml
services:
  switchboard:
    build: !reset null
    image: ghcr.io/zhehanzhang/swb:1.1.0
```

Pull the image. Start SwB with that image.

```sh
docker compose pull switchboard
docker compose up -d --no-deps switchboard
```

To return to 1.0.0, set `image` to `ghcr.io/zhehanzhang/swb:1.0.0`. Run the same commands.

If you used the [Docker install command](/docs/install), replace that container. Run these commands from the folder with its `.env` file. Use the same `swb-data` volume, which is the disk Docker keeps for SwB.

```sh
docker pull ghcr.io/zhehanzhang/swb:1.1.0
docker stop swb
docker rm swb
docker run -d --name swb --env-file .env \
  -p 127.0.0.1:8870:8000 -v swb-data:/data \
  ghcr.io/zhehanzhang/swb:1.1.0
```

To return to 1.0.0, use `ghcr.io/zhehanzhang/swb:1.0.0` in both image commands.

## Fly.io [#fly]

Update the source checkout. Run the deploy script for your existing app. Replace `my-swb` with its name.

```sh
git switch release/1.0
git pull --ff-only origin release/1.0
sh deploy/fly.sh my-swb --existing
```

To return to 1.0.0, switch to the release tag. Run the same deploy script.

```sh
git fetch origin tag v1.0.0
git switch --detach v1.0.0
sh deploy/fly.sh my-swb --existing
```

## Render [#render]

The SwB Blueprint sets Render to deploy on request. In the SwB service, open **Deploys**. Open **Manual Deploy**. Select **Deploy latest commit**.

To return to 1.0.0, use the Git commit from the release tag. A Git commit identifies one copy of the source.

```sh
git fetch origin tag v1.0.0
git rev-parse v1.0.0^{commit}
```

In **Manual Deploy**, select **Deploy a specific commit**. Paste the commit ID. Select **Deploy Commit**.

## Railway [#railway]

The SwB template builds from the connected `release/1.0` branch. With automatic deploys on, Railway builds and starts SwB when that branch changes.

For a manual update, open the command palette with `Cmd+K` or `Ctrl+K`. Select **Deploy Latest Commit** for the SwB service.

To return to a specific release, open **Deployments** in the SwB service. Find the deployment for the commit you want. Select **Rollback** in its menu. Confirm the rollback.

## Cloudflare Tunnel [#cloudflare-tunnel]

A tunnel connects your SwB server to its public address through Cloudflare. Keep the tunnel, public address and SwB port as they are. Use your SwB install method to update or return to a specific release.

For the Compose tunnel, use the Compose commands above. They replace only the `switchboard` service. Check `/healthz` at your public address.

## macOS Companion [#macos-companion]

If your companion runs in a terminal, stop it. For uvx, run this command to start the latest release.

```sh
uvx swb-one@latest companion run
```

To return to 1.0.0, stop the companion. Run this command.

```sh
uvx swb-one==1.0.0 companion run
```

For the background service installed with `uv tool install`, upgrade the package. Run the service install command from your macOS desktop session.

```sh
uv tool install swb-one@latest
swb companion service install
```

The install command verifies and replaces the app in `~/Applications` when the version changes. It restarts the service and keeps the pairing in `~/.config/swb/companion.json`.

To return to 1.0.0, install that version of the package. Run the service install command again.

```sh
uv tool install --force swb-one==1.0.0
swb companion service install
```
