# Install and run Kix

Install Kix with the install script, see how Kix chooses the version of Kix
your project uses, and verify that Kix can discover and evaluate your clusters.

## Install with the install script

<Command commands={["curl -fsSL https://kix.run/install | sh"]} />

The script downloads the release archive for your platform (`x86_64-linux`,
`aarch64-linux`, or `aarch64-darwin`) from kix.run and checks it against the
release's signed `SHA256SUMS`. It unpacks the archive to
`~/.local/share/kix/<version>/` and links `~/.local/bin/kix` to it. It never
edits your shell startup files. If `~/.local/bin` is not on your `PATH`, the
script prints the line to add.

To install a specific version, set `KIX_VERSION` to an exact version:

<Command commands={["curl -fsSL https://kix.run/install | KIX_VERSION=0.8.3 sh"]} />

| Variable | Default | Effect |
| --- | --- | --- |
| `KIX_VERSION` | the latest release | The exact version to install, such as `0.8.3`, or a prerelease such as `0.9.0-rc.1`. A minor such as `0.8` matches no release. The latest release is never a prerelease. |
| `KIX_INSTALL_DIR` | `~/.local/bin` | The directory for the `kix` link. |
| `XDG_DATA_HOME` | `~/.local/share` | Kix versions are installed under `$XDG_DATA_HOME/kix/`. |

The script stops without changing anything if `~/.local/bin/kix` already
exists and the script did not create it, for example a `kix` installed with
Nix. Remove that file, or choose another directory with `KIX_INSTALL_DIR`.

:::note
When the machine's `openssl` supports Ed25519 (OpenSSL 3 does, while macOS's
built-in LibreSSL does not), the script verifies the signatures on both the
release index and `SHA256SUMS`. Otherwise, the script prints a note and checks
only the SHA-256 checksum of the release archive. Kix itself always verifies
both signatures when installing other versions.

The script never selects a withdrawn release by default. If you set
`KIX_VERSION` to a withdrawn version, the script installs it with a warning and
names the version to install instead.
:::

## Choose the version of Kix for a project

By default, a project's version of Kix is the release tag of the `kix` input in
its `flake.nix`, as `flake.lock` records it:

```nix
# flake.nix
inputs.kix.url = "github:kix-run/kix/v0.10.0";
```

This project uses Kix 0.10.0. The tag is the project's version, so
everyone who works on the project, and every CI job, runs Kix 0.10.0 for it.
[`kix upgrade --to <version>`](/docs/reference/cli/upgrade/) sets the tag and
writes `flake.lock`. Commit both files.

A project with a [`[versions]` table](/docs/reference/kix-toml/#the-versions-table)
in `kix.toml` can keep clusters on different versions of Kix, each pinned by its
own input in `flake.nix` (see
[Keep clusters on different versions of Kix](/docs/how-to/start-and-inspect/hold-clusters-on-different-kix-versions/)).
When you run a command for a cluster, such as `kix check prod` or
`kix deploy prod`, Kix looks up that cluster's input in `[versions]` and runs
the version pinned for it in `flake.lock`. Project-wide commands that take no
cluster name (such as `kix list clusters`, `kix doctor`, and `kix status` with
no cluster) use the `kix` input.

Before Kix parses its arguments, it reads `flake.lock`. When the selected input
pins the running version, the command runs directly. Otherwise Kix runs that
version from `~/.local/share/kix/<version>` in its place, with the same
arguments. When that version is not installed, Kix downloads it from kix.run,
checks its signature and SHA-256, and then runs it:

```text
Installing Kix 0.10.0 (this project uses 0.10.0)
```

To stop Kix from downloading versions, set `KIX_AUTO_INSTALL=0`. Kix then
stops and names the command to run:

```text
This project uses Kix 0.10.0 (flake.lock), and Kix 0.10.0 is not installed. Automatic installs are off (KIX_AUTO_INSTALL=0). Run `kix self install 0.10.0`.
```

[`kix self`](/docs/reference/cli/self/), `kix upgrade`, `kix completions`,
`kix init`, `kix help`, and `--help` run in the Kix you started. So does a
command in a directory with no `flake.nix`, or with a remote `--flake` such as
`github:org/repo`. Kix reads `flake.lock` without Nix and without a network
request, so choosing a version is fast.

A project with a `flake.nix` must have a `flake.lock` whose `kix` input pins a
release tag. Kix stops with a message that names the fix when the lock is
missing, when the input has another name, or when the input has no tag. In
each case, run `kix upgrade --to <version>` to pin the Kix library and write
`flake.lock`.

`kix --version` prints the running version and never downloads. On stderr it
adds one line about the project: the Kix that started this one, the project's
version when it is not installed, or that the project uses a development Kix
library. [`kix doctor`](/docs/reference/cli/doctor/) reports the project's
version of Kix too.

## Manage installed versions

[`kix self`](/docs/reference/cli/self/) installs, lists, and removes versions
of Kix:

<Command commands={["kix self list", "kix self install 0.8", "kix self prune", "kix self upgrade"]} />

`kix self upgrade` installs the latest release and moves the `kix` link the
install script made to it, when the install script installed the running Kix.

## When the Kix library does not match Kix

The Kix library and the running Kix match unless `flake.nix` changed after
`flake.lock` was written, for example when someone edited the tag by hand.
Kix then stops:

```text
flake.nix asks for Kix 0.10.1, but flake.lock pins Kix 0.10.0. Run `kix upgrade --to 0.10.1`.
```

Kix compares the two tags before it evaluates anything, so `flake.lock` stays
as it was. Run [`kix upgrade --to 0.10.1`](/docs/reference/cli/upgrade/): it
sets `flake.nix` back to 0.10.0, builds every cluster with it, then moves the
project to 0.10.1 with the usual builds and release notes. Commit both files.

When the tag names an older version than `flake.lock`, `kix upgrade` cannot
help, because it only moves a project to a newer version. Kix says so:

```text
flake.nix asks for Kix 0.9.2, but flake.lock pins Kix 0.10.0. `kix upgrade` only moves a project to a newer version of Kix. To stay on Kix 0.10.0, set the tag in flake.nix back to v0.10.0. To go back to Kix 0.9.2, restore flake.nix and flake.lock from a commit that pinned it.
```

When Kix cannot find the tag in `flake.nix`, for example because the input is
written as an attribute set, it still checks after evaluation that the Kix
library has the same version as the running Kix. Installing a version with
`kix self install` alone does not change which Kix runs, because Kix takes a
project's version only from `flake.lock`.

## Work on the Kix library itself

A project uses a development Kix library when its `kix` input is a local
folder (`path:...`, or a local `git+file://` repository with no ref), a branch,
or an input you replace with
[`--override-input kix <url>`](/docs/reference/cli/global-flags/), and when
`kix.toml` sets [`library = "self"`](/docs/reference/kix-toml/#the-library-setting),
as the Kix repository does because its own flake provides the Kix library. In a
project with a [`[versions]` table](/docs/reference/kix-toml/#the-versions-table),
pointing an input at a local folder or branch (or passing
`--override-input <input> <url>`) uses a development Kix library only for the
clusters on that input, while other clusters keep their pinned versions. A
development Kix library has no release version, so Kix runs the Kix you started
and compares no versions. It prints one line on stderr:

```text
note: this project uses a development Kix library (the input kix is the local folder /home/me/src/kix), so Kix 0.10.0 runs it without checking its version.
```

## Verify the installation

Check the installed version:

<Command {...version} />

Verify that Kix and its runtime tools are healthy:

<Command commands={["kix doctor"]} />

Confirm that the command list is available:

<Command commands={["kix --help"]} />

## Run your first command

Kix evaluates the project in the current directory unless you pass `--flake`.
From a Kix project, list the clusters it defines:

<Command commands={["kix list clusters"]} cwd="kix-examples/" />

If the project is in another directory, pass `--flake`:

<Command commands={["kix --flake /path/to/project list clusters"]} />

By default (`builder = "kix"`), Kix evaluates with the Kix runtime and
downloads the project's locked inputs into Kix's local store
(`~/.cache/kix/store`, or `$XDG_CACHE_HOME/kix/store`). Later commands reuse
the cached inputs. Set `KIX_STORE_ROOT` if you want Kix to keep its local store
in a different directory.
A project can instead use the Nix already installed on the machine. See
[`kix.toml`](/docs/reference/kix-toml/).

## Install from a release archive

Where you cannot run the install script, such as in a container image build,
download a release archive yourself. Replace `0.8.4` with the version you
want, and `x86_64-linux` with `aarch64-linux` on ARM64 Linux or
`aarch64-darwin` on Apple silicon macOS:

<Command
  commands={[
    "curl -fsSLO https://kix.run/download/0.8.4/kix-x86_64-linux.tar.gz",
    "curl -fsSL https://kix.run/releases/v0.8.4/SHA256SUMS | grep ' kix-x86_64-linux.tar.gz$' | sha256sum -c -",
    "mkdir -p ~/.local",
    "tar -xzf kix-x86_64-linux.tar.gz --strip-components=1 -C ~/.local",
  ]}
/>

On macOS, check the archive with `shasum -a 256 -c -` in place of
`sha256sum -c -`. Make sure `~/.local/bin` is on your `PATH`.

:::note
The archive unpacks `bin/kix` alongside its runtime tools in `libexec/kix/`.
Keep both directories in the same parent directory (or symlink
`~/.local/bin/kix` to the unpacked `bin/kix`). If you move `libexec/kix/`
somewhere else, set `KIX_RUNTIME_DIR` to its path.
:::

`kix self upgrade` does not upgrade a Kix installed this way. A project still
gets the version of Kix its `flake.lock` names, which Kix installs under
`~/.local/share/kix/`.

## Install with Nix

If you manage tools with Nix flakes, you can install Kix from its flake:

<Command commands={["nix profile install github:kix-run/kix#kix"]} />

Upgrade it with `nix profile upgrade kix`. `kix self upgrade` prints that
command instead of upgrading a Kix installed this way.

:::note[Reference]
See [`kix self`](/docs/reference/cli/self/) for managing installed versions,
[`kix doctor`](/docs/reference/cli/doctor/) for how Kix verifies its
runtime directory and project builder, [`kix.toml`](/docs/reference/kix-toml/)
for the `builder` setting, and
[Global flags](/docs/reference/cli/global-flags/) for shared CLI flags and
environment variables.
:::

:::tip[Try it as a tutorial]
Work through [local setup and your first Kix deployment](/docs/tutorials/02-local-setup-and-first-run/)
to create a kind cluster and run the complete edit, check, deploy, and verify
loop.
:::