Install Tools
Table of Contents
Why one binary
k6 ships as a single compiled Go binary. There is no JVM to size, no plugin manager, no separate GUI to install — one download (or one Docker pull) and you can run a script. That is the whole appeal over JMeter for a developer-centric workflow: k6 run script.js and you are testing.
How: install k6
Pick one:
# macOS
brew install k6
# Windows
winget install k6 --source winget
# Docker (no local install)
docker run --rm -i grafana/k6 run - <script.js
The stdin form above (run - <script.js) only works for a single self-contained file — no local import. Every script in this track imports from ./lib/, so see the volume-mount form in the Tips section below.
Verify:
k6 version
k6 v2.2.0 (commit/devel, go1.26.5, darwin/arm64)
Optional: the k6 VS Code extension adds snippets for http.get, check, SharedArray and the rest of the API. Not required — the sample scripts in this track cover the patterns you need.
How: run against the playground
Every script in this track targets the Pizza Playground. If it is not already running, follow Run It Locally first — this page does not repeat that setup.
With the playground up, download the sample, unzip it and run the first script from k6/sample/:
cd k6/sample
k6 run 01-first-test.js
running (10.1s), 0/1 VUs, 10 complete and 0 interrupted iterations
default ✓ [ 100% ] 1 VUs 10s
█ THRESHOLDS
checks
✓ 'rate==1' rate=100.00%
http_req_duration
✓ 'p(95)<500' p(95)=10.66ms
█ TOTAL RESULTS
checks_total.......: 20 1.981358/s
checks_succeeded...: 100.00% 20 out of 20
checks_failed......: 0.00% 0 out of 20
✓ status is 200
✓ menu has pizzas
HTTP
http_req_duration..............: avg=6.53ms min=3.74ms med=5.92ms max=11.92ms p(90)=9.4ms p(95)=10.66ms
http_req_failed................: 0.00% 0 out of 10
http_reqs......................: 10 0.990679/s
Green thresholds and two checks passing means the toolchain and the playground are both wired up correctly.
Tips
-
Docker can't reach
127.0.0.1on the host. The playground listens on your machine, but inside thegrafana/k6container127.0.0.1means the container itself. Point the script at the host instead — and mount the sample directory rather than piping the script over stdin, since stdin gives k6 no local disk to resolve./lib/config.jsfrom:cd k6/sampledocker run --rm -v "$PWD":/scripts -w /scripts -e BASE_URL=http://host.docker.internal:8080 grafana/k6 run 01-first-test.jsThe stdin form (
run - <01-first-test.js) fails here withcould not load JS test, because k6 has no filesystem to resolve the script'simports from — it only works for a script with no local imports. The volume mount above gives the container the wholek6/samplefolder, so./lib/config.jsresolves.host.docker.internalworks on Docker Desktop (macOS/Windows). On Linux, add--add-host=host.docker.internal:host-gatewayto thedocker runcommand first.