How to Build ClickHouse on macOS for macOS

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/development/build-osx.md)

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](https://clickhouse.com/docs/get-started/quick-start).

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.

## Install prerequisites[​](#install-prerequisites "Direct link to Install prerequisites")

First, see the generic [prerequisites documentation](/docs/development/developer-instruction).

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

Then run:

```
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).

## Build ClickHouse[​](#build-clickhouse "Direct link to Build ClickHouse")

To build you must use Homebrew's Clang compiler:

```
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`.

## Caveats[​](#caveats "Direct link to Caveats")

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

Note

You'll need to use sudo.

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

```
<?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:

```
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
```

Validate that the file is correct:

```
plutil /Library/LaunchDaemons/limit.maxfiles.plist
```

Load the file (or reboot):

```
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
```

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

- [Install prerequisites](#install-prerequisites)- [Build ClickHouse](#build-clickhouse)- [Caveats](#caveats)

Was this page helpful?