# div upgrade

> Install div, upgrade it to the latest release, or switch to a specific version.

## Synopsis

```text
div upgrade [version]
```

Replaces the running `div` binary with the latest release, or with the named version. Needs no API key.

## Arguments

| Argument | Description | Default |
| --- | --- | --- |
| `[version]` | Version to install, such as `0.2.0`. Use an older version to roll back. | latest |

## Behavior

- The download is verified against the release's `SHA256SUMS` before it replaces anything. If verification fails, the current binary is kept.
- `div upgrade` replaces the file it was run from, following symlinks. If that file is in a directory you cannot write to, such as `/usr/local/bin`, run `sudo div upgrade` or reinstall with the install script.

## Install

```bash
curl -fsSL https://div.io/install.sh | sh
```

The script downloads the binary for your OS and CPU, verifies it against `SHA256SUMS`, and installs it in `~/.local/bin`. It does not use root. If the directory is not on your `PATH`, the script prints the line to add.

| Variable | Description | Default |
| --- | --- | --- |
| `DIV_VERSION` | Version to install. | latest |
| `DIV_INSTALL_DIR` | Directory to install into. | `~/.local/bin` |

### Binaries

Each release has one self-contained binary per platform. The Linux builds are static and run on any distribution, including Alpine and distroless images.

| OS | CPU | File |
| --- | --- | --- |
| macOS | Apple silicon | `div-darwin-arm64` |
| macOS | Intel | `div-darwin-x86_64` |
| Linux | x86-64 | `div-linux-x86_64` |
| Linux | ARM64 | `div-linux-arm64` |

To download and verify one manually:

```bash
curl -fsSLO https://github.com/divergentlabsxyz/div/releases/latest/download/div-linux-x86_64
curl -fsSL https://github.com/divergentlabsxyz/div/releases/latest/download/SHA256SUMS | sha256sum -c --ignore-missing
```

## Update notices

Once a day, when you run a command in a terminal, `div` checks for a newer release. If one exists, it prints a notice to stderr after the command finishes.

- The check runs only when stderr is a terminal, so scripts and agents never see it.
- It waits at most half a second and never changes the exit code.
- Set `DIVERGENT_NO_UPDATE_CHECK=1` to turn it off.

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Upgraded, or the version is already installed. |
| `1` | The release could not be downloaded, failed verification, or could not be written. |
| `2` | The argument is not a version. |

## Examples

```bash
div upgrade
div upgrade 0.2.0
curl -fsSL https://div.io/install.sh | DIV_VERSION=0.2.0 sh
```
