# Installation

> Install Brine with one command on Linux, macOS or Windows, check your toolchain with brine doctor, and upgrade, uninstall or build from source.

Source: https://docs.brinelang.org/getting-started/installation/

One command installs the `brine` tool into `~/.brine/bin` and adds it to your `PATH`. Brine also needs a C compiler on your machine; run `brine doctor` afterwards to check that everything works.

## Quick install

[Section titled “Quick install”](#quick-install)

* Linux and macOS

  ```sh
  curl -fsSL https://raw.githubusercontent.com/brinelang/brine/main/install.sh | sh
  ```

  The script picks the build for your system (`linux` or `macos`, `x64` or `arm64`), checks it against the release’s `SHA256SUMS`, and puts `brine` in `~/.brine/bin`. It adds that folder to your `PATH` in your shell’s startup file (`~/.zshrc`, `~/.bashrc`, `~/.bash_profile` on macOS bash, `~/.config/fish/conf.d/brine.fish`, or `~/.profile`). Open a new terminal, or run the `export` line it prints.

* Windows

  In PowerShell (5.1 or later):

  ```powershell
  irm https://raw.githubusercontent.com/brinelang/brine/main/install.ps1 | iex
  ```

  The script downloads `brine-windows-x64.zip`, checks it against the release’s `SHA256SUMS`, puts `brine.exe` in `%USERPROFILE%\.brine\bin` and adds that folder to your user `PATH`. New terminals see it; the current PowerShell session can use it right away. On Windows on ARM it installs the x64 build, which runs under emulation.

Then check the install:

```sh
brine --version
```

```text
brine 0.4.0
```

Run the installer again to upgrade to the latest release.

### Installer settings

[Section titled “Installer settings”](#installer-settings)

Set these environment variables before running the installer:

| Variable                 | Effect                                                                           |
| ------------------------ | -------------------------------------------------------------------------------- |
| `BRINE_VERSION=0.4.0`    | install a given version (default: the latest release)                            |
| `BRINE_INSTALL=~/.brine` | where to install; the binary goes in `$BRINE_INSTALL/bin`                        |
| `BRINE_NO_MODIFY_PATH=1` | don’t add Brine to your `PATH` (the installer prints the folder to add yourself) |
| `BRINE_DOWNLOAD_URL=...` | where the release files are, for mirrors (default: GitHub releases)              |

* Linux and macOS

  ```sh
  curl -fsSL https://raw.githubusercontent.com/brinelang/brine/main/install.sh | BRINE_VERSION=0.4.0 sh
  ```

* Windows

  ```powershell
  $env:BRINE_VERSION = '0.4.0'
  irm https://raw.githubusercontent.com/brinelang/brine/main/install.ps1 | iex
  ```

## Requirements

[Section titled “Requirements”](#requirements)

Brine needs a C compiler: `gcc` or `clang`, or MinGW on Windows. It uses it to build the runtime, to link your program, and for `--release` builds. The installer warns you if it can’t find one.

* Linux and macOS

  ```sh
  xcode-select --install       # macOS
  sudo apt install gcc         # Debian, Ubuntu
  sudo dnf install gcc         # Fedora
  ```

* Windows

  ```powershell
  winget install -e --id BrechtSanders.WinLibs.POSIX.UCRT
  # or
  scoop install mingw-winlibs
  ```

To use a specific compiler, set `BRINE_CC` (or `CC`) to its name or path.

### Check your setup

[Section titled “Check your setup”](#check-your-setup)

`brine doctor` checks each part of the toolchain and builds and runs a small parallel program:

```sh
brine doctor
```

Output on Windows

```text
  ✓ brine            0.4.0 (windows x86_64)
  ✓ C compiler       gcc — gcc (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders, r1) 16.2.0
  ✓ parallelism      32 hardware threads
  ✓ local sockets    needed for `brine run --ranks`
  ✓ build + run      compiled and ran a parallel program
  ✓ debugger         gdb
```

A `✗` line says what’s missing. The debugger (gdb or lldb) is optional; you only need it for `brine debug`.

### GPUs

[Section titled “GPUs”](#gpus)

GPU offload needs nothing at build time. If an NVIDIA driver or an Apple silicon GPU is present when your program runs, Brine can use it; otherwise everything runs on the CPU. There is no CUDA toolkit or SDK to install. See [GPU offload](/parallelism/gpu/).

### WebAssembly

[Section titled “WebAssembly”](#webassembly)

Building for WebAssembly (`--target wasm` or `--target web`) also needs [wasi-sdk](https://github.com/WebAssembly/wasi-sdk/releases): unpack it and set `WASI_SDK_PATH` to its folder. `brine run --target wasm` runs the result with Node.js. Both are optional, and WebAssembly support isn’t in a release yet: build Brine [from source](#build-from-source) to use it. See [WebAssembly](/tooling/webassembly/).

## Supported platforms

[Section titled “Supported platforms”](#supported-platforms)

| Platform            | Prebuilt | Native dev builds | GPU               |
| ------------------- | -------- | ----------------- | ----------------- |
| Linux x86-64        | ✅        | ✅                 | NVIDIA (CUDA)     |
| Linux ARM64         | ✅        | ✅                 | NVIDIA (CUDA)     |
| Windows x86-64      | ✅        | ✅                 | NVIDIA (CUDA)     |
| macOS Apple silicon | ✅        | via C             | Apple GPU (Metal) |
| macOS Intel         | ✅        | via C             | –                 |

“Native dev builds” means the compiler writes machine code itself, so dev builds are fast. Everywhere else, and for every `--release` build, it goes through the C compiler. See [Platforms](/reference/platforms/) and [Builds and backends](/tooling/builds-and-backends/).

## Prebuilt archives

[Section titled “Prebuilt archives”](#prebuilt-archives)

Every release on the [releases page](https://github.com/brinelang/brine/releases) has an archive per platform and a `SHA256SUMS` file:

| File                       | Contains                      |
| -------------------------- | ----------------------------- |
| `brine-linux-x64.tar.gz`   | `brine-linux-x64/brine`       |
| `brine-linux-arm64.tar.gz` | `brine-linux-arm64/brine`     |
| `brine-macos-arm64.tar.gz` | `brine-macos-arm64/brine`     |
| `brine-macos-x64.tar.gz`   | `brine-macos-x64/brine`       |
| `brine-windows-x64.zip`    | `brine-windows-x64\brine.exe` |

The archive holds a single executable. Put it anywhere on your `PATH`.

## Uninstall

[Section titled “Uninstall”](#uninstall)

* Linux and macOS

  Delete `~/.brine` (or your `BRINE_INSTALL` folder), then remove the lines the installer added to your shell’s startup file: a `# brine` comment followed by an `export PATH=...` (or `fish_add_path`) line.

  ```sh
  rm -rf ~/.brine
  ```

* Windows

  Delete `%USERPROFILE%\.brine` and remove its `bin` folder from your user `PATH` (Settings → System → About → Advanced system settings → Environment Variables).

  ```powershell
  Remove-Item -Recurse -Force "$HOME\.brine"
  ```

## Build from source

[Section titled “Build from source”](#build-from-source)

The compiler is written in Brine, so the first build starts from the C that Brine generates for itself, the bootstrap seed `bootstrap/brinec.c`. All you need is a C11 compiler.

* Linux and macOS

  ```sh
  git clone https://github.com/brinelang/brine && cd brine
  cc -std=c11 -O2 -fno-strict-aliasing -w -Iruntime bootstrap/brinec.c runtime/brine_rt.c -o brine -lm -lpthread -ldl
  ./brine build compiler/main.br -o brine2   # brine rebuilding itself
  ```

* Windows

  With MinGW gcc or clang:

  ```sh
  git clone https://github.com/brinelang/brine && cd brine
  gcc -std=c11 -O2 -fno-strict-aliasing -w -Iruntime bootstrap/brinec.c runtime/brine_rt.c -o brine.exe -lws2_32 -lshell32
  ./brine build compiler/main.br -o brine2
  ```

The first command gives you the full `brine` tool. The second has it rebuild the compiler from its Brine sources. A correct compiler reaches a fixed point: building again with `brine2` gives the same C.

## Next

[Section titled “Next”](#next)

* [Your first project](/getting-started/first-project/): `brine new`, `run`, `check` and `test`.
* [A tour of Brine](/getting-started/tour/): the whole language, one example at a time.
