> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Install ClickHouse on NixOS and using Nix

# Install ClickHouse on NixOS

<h1 id="install-from-nix">
  Install ClickHouse on NixOS
</h1>

> ClickHouse is available in the Nixpkgs repository and can be installed using Nix on **Linux** and **macOS**.

<Steps>
  <Step>
    <h2 id="review-recommendations">
      Review recommendations
    </h2>

    Before installing ClickHouse, review the following recommendations:

    * **Swap:** Disable the operating system's swap file in production environments.
    * **Disk space:** The ClickHouse binary requires at least 2.5 GB of disk space for installation.
    * **Network:** For distributed deployments (clustering), use at least 10 Gbit network connectivity. Network bandwidth is critical for processing distributed queries with large amounts of intermediate data, as well as for replication.

    **Estimating storage requirements**

    To estimate the disk space needed for your data:

    1. **Estimate data volume:** Take a sample of your data and calculate the average row size, then multiply by the number of rows you plan to store.
    2. **Apply the compression coefficient:** Load a sample into ClickHouse and compare the original data size with the stored table size. Clickstream data, for example, is typically compressed 6-10x.
    3. **Account for replicas:** If you plan to store data in multiple replicas, multiply the estimated volume by the number of replicas.

    For more detailed hardware requirements, see ["Sizing and hardware recommendations"](/guides/oss/best-practices/sizing-and-hardware-recommendations)
  </Step>

  <Step>
    <h2 id="install-clickhouse-using-nix">
      Install ClickHouse using Nix
    </h2>

    You can use Nix to install ClickHouse without permanently adding it to your system:

    ```bash theme={null}
    # Install the latest stable version
    nix shell nixpkgs#clickhouse

    # Or install the LTS version
    nix shell nixpkgs#clickhouse-lts
    ```

    This will make the `clickhouse` binary available in your current shell session.

    * The `nixpkgs#clickhouse` package provides the latest stable version.
    * The `nixpkgs#clickhouse-lts` package provides the Long Term Support version.
    * Both packages work on Linux and macOS.
  </Step>

  <Step>
    <h2 id="permanent-installation">
      Permanent installation
    </h2>

    To install ClickHouse permanently on your system:

    **For NixOS users**, add to your `configuration.nix`:

    ```nix theme={null}
    environment.systemPackages = with pkgs; [
      clickhouse
    ];
    ```

    Then rebuild your system:

    ```bash theme={null}
    sudo nixos-rebuild switch
    ```

    **For non-NixOS users**, install using Nix profile:

    ```bash theme={null}
    # Install the latest stable version
    nix profile install nixpkgs#clickhouse

    # Or install the LTS version
    nix profile install nixpkgs#clickhouse-lts
    ```
  </Step>

  <Step>
    <h2 id="start-clickhouse-server">
      Start ClickHouse server
    </h2>

    After installation, you can start the ClickHouse server:

    ```bash theme={null}
    clickhouse-server
    ```

    By default, the server will start with a basic configuration and listen on `localhost:9000`.

    For production use on NixOS, you may want to configure ClickHouse as a system service. Refer to the [NixOS manual](https://search.nixos.org/options?query=clickhouse) for available configuration options.
  </Step>

  <Step>
    <h2 id="start-clickhouse-client">
      Start ClickHouse client
    </h2>

    To connect to the ClickHouse server, open a new terminal and run:

    ```bash theme={null}
    clickhouse-client
    ```
  </Step>
</Steps>

<h2 id="about-nix-package">
  About the Nix Package
</h2>

The ClickHouse package in Nixpkgs includes:

* `clickhouse-server` - The ClickHouse database server
* `clickhouse-client` - The command-line client for connecting to ClickHouse
* `clickhouse-local` - A tool for running SQL queries on local files
* Other ClickHouse utilities

For more information about the ClickHouse package in Nixpkgs, visit:

* [Nixpkgs ClickHouse package](https://search.nixos.org/packages?query=clickhouse)
* [NixOS ClickHouse service options](https://search.nixos.org/options?query=clickhouse)
