k6 Installation Guide
What is k6?
k6 is a modern load testing tool that makes performance testing easy and developer-friendly. It's used to validate that our API Gateway meets the performance target of p95 < 200ms.
Installation Options
Option 1: Automatic Installation (Recommended)
We provide an automatic installation script:
# Make script executable
chmod +x scripts/install-k6.sh
# Run installation
./scripts/install-k6.sh
Option 2: Manual Installation
macOS (using Homebrew)
brew install k6
Linux (Ubuntu/Debian)
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D6
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
Linux (CentOS/RHEL/Fedora)
sudo yum install https://dl.k6.io/rpm/repo.rpm
sudo yum install k6
Windows
Option A: Using Chocolatey
choco install k6
Option B: Using Scoop
scoop install k6
Option C: Download Binary
- Visit: https://github.com/grafana/k6/releases
- Download the latest Windows binary
- Extract and add to PATH
Docker (Alternative)
If you don't want to install k6 directly, you can use Docker:
docker run --rm -i grafana/k6 run - <scripts/performance-test.js
Verify Installation
After installation, verify k6 is working:
k6 version
You should see output like:
k6 v0.48.0 (go1.21.3, linux/amd64)
Official Documentation
- Website: https://k6.io
- Installation Guide: https://k6.io/docs/getting-started/installation/
- Documentation: https://k6.io/docs/
Quick Start
Once k6 is installed, you can run performance tests:
# Run performance test
k6 run scripts/performance-test.js
# Run with custom API URL
API_URL=http://localhost:3000 k6 run scripts/performance-test.js
# Run with more concurrent users
k6 run --vus 100 --duration 60s scripts/performance-test.js
Troubleshooting
macOS: "command not found: k6"
If you installed via Homebrew and still get this error:
# Check if Homebrew is in PATH
echo $PATH | grep -q "/opt/homebrew/bin" || echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
# Reload shell
source ~/.zshrc
# Verify
k6 version
Linux: Permission Denied
If you get permission errors:
# Check if k6 is in a directory that requires sudo
which k6
# If needed, add to PATH or use sudo
sudo k6 version
Windows: Not in PATH
- Find where k6 was installed (usually
C:\Program Files\k6\) - Add to System PATH:
- Open System Properties → Environment Variables
- Add k6 directory to PATH
- Restart terminal
Alternative: Use Docker
If installation is problematic, use Docker instead:
# Create a wrapper script
cat > scripts/run-k6-docker.sh << 'EOF'
#!/bin/bash
docker run --rm -i \
-v "$(pwd)/scripts:/scripts" \
grafana/k6 run /scripts/performance-test.js
EOF
chmod +x scripts/run-k6-docker.sh
# Run tests
./scripts/run-k6-docker.sh
Need Help?
- Check k6 documentation: https://k6.io/docs/
- k6 GitHub: https://github.com/grafana/k6
- k6 Community: https://community.k6.io/