$npx -y skills add clickhouse/agent-skills --skill clickhousectl-local-devUse when a user wants to build an application with ClickHouse, set up a local ClickHouse development environment, install ClickHouse, create a local server, create tables, or start developing with ClickHouse. Covers the full flow from zero to a working local ClickHouse setup.
| 1 | # Local ClickHouse Development Setup |
| 2 | |
| 3 | This skill walks through setting up a complete local ClickHouse development environment using `clickhousectl`. Follow these steps in order. |
| 4 | |
| 5 | ## When to Apply |
| 6 | |
| 7 | Use this skill when the user wants to: |
| 8 | - Build an application that needs an analytical database or ClickHouse specifically |
| 9 | - Set up a local ClickHouse instance for development |
| 10 | - Install ClickHouse on their machine |
| 11 | - Create tables and start querying ClickHouse locally |
| 12 | - Prototype or experiment with ClickHouse |
| 13 | |
| 14 | --- |
| 15 | |
| 16 | ## Step 1: Install clickhousectl |
| 17 | |
| 18 | Check if `clickhousectl` is already available: |
| 19 | |
| 20 | ```bash |
| 21 | which clickhousectl |
| 22 | ``` |
| 23 | |
| 24 | If not found, install it: |
| 25 | |
| 26 | ```bash |
| 27 | curl -fsSL https://clickhouse.com/cli | sh |
| 28 | ``` |
| 29 | |
| 30 | This installs `clickhousectl` to `~/.local/bin/clickhousectl` and creates a `chctl` alias. |
| 31 | |
| 32 | **If the command is still not found after install:** The user may need to add `~/.local/bin` to their PATH or open a new terminal session. Suggest: |
| 33 | |
| 34 | ```bash |
| 35 | export PATH="$HOME/.local/bin:$PATH" |
| 36 | ``` |
| 37 | |
| 38 | Once installed, `clickhousectl skills` can be used to install the latest ClickHouse Agent Skills. |
| 39 | |
| 40 | --- |
| 41 | |
| 42 | ## Step 2: Install ClickHouse and set the default |
| 43 | |
| 44 | Install the latest ClickHouse version and set it as the system default: |
| 45 | |
| 46 | ```bash |
| 47 | clickhousectl local use latest |
| 48 | ``` |
| 49 | |
| 50 | This installs ClickHouse, sets it as the default version used by `clickhousectl local` commands, and symlinks `~/.local/bin/clickhouse` to the binary, putting `clickhouse` on your PATH (meaning you can invoke `clickhouse` directly, e.g. `clickhouse client` if needed). |
| 51 | |
| 52 | You can use other version specifiers like `stable`, `26.4`, `26.4.2.10` when needed. |
| 53 | |
| 54 | --- |
| 55 | |
| 56 | ## Step 3: Initialize the project |
| 57 | |
| 58 | From the user's project root directory: |
| 59 | |
| 60 | ```bash |
| 61 | clickhousectl local init |
| 62 | ``` |
| 63 | |
| 64 | This creates a standard folder structure: |
| 65 | |
| 66 | ``` |
| 67 | clickhouse/ |
| 68 | tables/ # CREATE TABLE statements |
| 69 | materialized_views/ # Materialized view definitions |
| 70 | queries/ # Saved queries |
| 71 | seed/ # Seed data / INSERT statements |
| 72 | ``` |
| 73 | |
| 74 | **Note:** This step is optional. If the user already has their own folder structure for SQL files, skip this and adapt the later steps to use their paths. |
| 75 | |
| 76 | --- |
| 77 | |
| 78 | ## Step 4: Start a local server |
| 79 | |
| 80 | ```bash |
| 81 | clickhousectl local server start --name <name> |
| 82 | ``` |
| 83 | |
| 84 | This starts a ClickHouse server in the background. |
| 85 | |
| 86 | **To check running servers and see their exposed ports:** |
| 87 | |
| 88 | ```bash |
| 89 | clickhousectl local server list |
| 90 | ``` |
| 91 | |
| 92 | --- |
| 93 | |
| 94 | ## Step 5: Create the schema |
| 95 | |
| 96 | Based on the user's application requirements, write CREATE TABLE SQL files. |
| 97 | |
| 98 | **Write each table definition to its own file** in `clickhouse/tables/`: |
| 99 | |
| 100 | ```bash |
| 101 | # Example: clickhouse/tables/events.sql |
| 102 | ``` |
| 103 | |
| 104 | ```sql |
| 105 | CREATE TABLE IF NOT EXISTS events ( |
| 106 | timestamp DateTime, |
| 107 | user_id UInt32, |
| 108 | event_type LowCardinality(String), |
| 109 | properties String |
| 110 | ) |
| 111 | ENGINE = MergeTree() |
| 112 | ORDER BY (event_type, timestamp) |
| 113 | ``` |
| 114 | |
| 115 | When designing schemas, if the `clickhouse-best-practices` skill is available, consult it for guidance on ORDER BY column selection, data types, and partitioning. |
| 116 | |
| 117 | **Apply the schema to the running server:** |
| 118 | |
| 119 | ```bash |
| 120 | clickhousectl local client --name <name> --queries-file clickhouse/tables/events.sql |
| 121 | ``` |
| 122 | |
| 123 | --- |
| 124 | |
| 125 | ## Step 6: Seed data (optional) |
| 126 | |
| 127 | If the user needs sample data for development, write INSERT statements to `clickhouse/seed/`: |
| 128 | |
| 129 | ```bash |
| 130 | # Example: clickhouse/seed/events.sql |
| 131 | ``` |
| 132 | |
| 133 | ```sql |
| 134 | INSERT INTO events (timestamp, user_id, event_type, properties) VALUES |
| 135 | ('2024-01-01 00:00:00', 1, 'page_view', '{"page": "/home"}'), |
| 136 | ('2024-01-01 00:01:00', 2, 'click', '{"button": "signup"}'); |
| 137 | ``` |
| 138 | |
| 139 | **Apply seed data:** |
| 140 | |
| 141 | ```bash |
| 142 | clickhousectl local client --name <name> --queries-file clickhouse/seed/events.sql |
| 143 | ``` |
| 144 | |
| 145 | --- |
| 146 | |
| 147 | ## Step 7: Verify the setup |
| 148 | |
| 149 | Confirm tables were created: |
| 150 | |
| 151 | ```bash |
| 152 | clickhousectl local client --name <name> --query "SHOW TABLES" |
| 153 | ``` |
| 154 | |
| 155 | Run a test query: |
| 156 | |
| 157 | ```bash |
| 158 | clickhousectl local client --name <name> --query "SELECT count() FROM events" |
| 159 | ``` |
| 160 | |
| 161 | --- |
| 162 | |
| 163 | If the user wants to use a managed ClickHouse service, use the `clickhousectl-cloud-deploy` skill to help the user deploy to ClickHouse Cloud. |