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

> Guide for building ClickHouse from source on macOS systems

# Build on macOS for macOS

<Info>
  **This build guide is for contributors modifying ClickHouse itself.**

  If you are not changing ClickHouse source code, you can install pre-built ClickHouse as described in [Quick Start](/get-started/setup/install).
</Info>

ClickHouse can be compiled on macOS x86\_64 (Intel) and arm64 (Apple Silicon) using on macOS 10.15 (Catalina) or higher.

As compiler, only Clang from homebrew is supported.

<h2 id="install-prerequisites">
  Install prerequisites
</h2>

First, see the generic [prerequisites documentation](/resources/develop-contribute/introduction/developer-instruction).

Next, install [Homebrew](https://brew.sh/) and run

Then run:

```bash theme={null}
brew update
brew install ccache cmake ninja libtool gettext llvm lld binutils grep findutils nasm bash rust rustup
```

<Note>
  Apple uses a case-insensitive file system by default. While this usually does not affect compilation (especially scratch makes will work), it can confuse file operations like `git mv`.
  For serious development on macOS, make sure that the source code is stored on a case-sensitive disk volume, e.g. see [these instructions](https://brianboyko.medium.com/a-case-sensitive-src-folder-for-mac-programmers-176cc82a3830).
</Note>

<h2 id="build-clickhouse">
  Build ClickHouse
</h2>

To build you must use Homebrew's Clang compiler:

```bash theme={null}
cd ClickHouse
mkdir build
export PATH=$(brew --prefix llvm)/bin:$PATH
cmake -S . -B build
cmake --build build
# The resulting binary will be created at: build/programs/clickhouse
```

<Note>
  If you are running into `ld: archive member '/' not a mach-o file in ...` errors during linking, you may need
  to use llvm-ar by setting flag `-DCMAKE_AR=/opt/homebrew/opt/llvm/bin/llvm-ar`.
</Note>

<h2 id="caveats">
  Caveats
</h2>

If you intend to run `clickhouse-server`, make sure to increase the system's `maxfiles` variable.

<Note>
  You'll need to use sudo.
</Note>

To do so, create the `/Library/LaunchDaemons/limit.maxfiles.plist` file with the following content:

```xml theme={null}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>524288</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>
```

Give the file correct permissions:

```bash theme={null}
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
```

Validate that the file is correct:

```bash theme={null}
plutil /Library/LaunchDaemons/limit.maxfiles.plist
```

Load the file (or reboot):

```bash theme={null}
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
```

To check if it's working, use the `ulimit -n` or `launchctl limit maxfiles` commands.
