k6 Installation and CLI
Install k6 and get familiar with its command-line interface for executing tests.
k6 Installation and CLI is a free Load Testing & Performance Benchmarking (JMeter & k6) lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Load Testing & Performance Benchmarking (JMeter & k6) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Meet k6: Load Testing Tool
Welcome! In this lesson, we'll get started with k6, a powerful open-source load testing tool. k6 is built with Go and allows you to write performance tests using JavaScript.
It's designed for developers and QA engineers who want to integrate performance testing into their modern development workflows.
Why Choose k6?
k6 offers several advantages for performance testing:
- JavaScript API: Write tests in familiar JavaScript.
- CLI-focused: Easy to integrate into CI/CD pipelines.
- Performance: Built on Go, it's efficient and fast.
- Modern Approach: Treats performance tests as code, enabling version control and code reviews.
Installation Overview
Before we write our first test, we need to install k6 on your system. k6 supports various operating systems like Windows, macOS, and Linux.
The recommended way to install k6 is through package managers, which makes the process straightforward and quick.
macOS and Linux Setup
For macOS users, the easiest way to install k6 is using Homebrew. Open your terminal and run:
brew install k6On Debian/Ubuntu Linux, you can install k6 from its official repository with these commands:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E34A0A
echo "deb https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt update
sudo apt install k6Windows Installation
Windows users have a couple of easy options using popular package managers.
Using Chocolatey (run in an elevated PowerShell or CMD):
choco install k6Using Scoop (run in PowerShell):
scoop install k6Check Your k6 Version
After installation, it's important to verify that k6 is correctly installed and accessible from your command line. Open a new terminal or command prompt and type:
k6 versionYou should see the installed k6 version number displayed, confirming a successful setup.
The `k6 run` Command
The core of k6 is its powerful Command Line Interface (CLI). The most frequently used command is k6 run.
This command is used to execute your k6 test scripts. You simply point it to your JavaScript file, and k6 takes care of the rest.
k6 run your_script.jsA Minimal k6 Test
Let's create a super simple k6 script. This script will make a single HTTP GET request to example.com. We'll save this as script.js.
Notice the import http statement – k6 provides built-in modules like http for making requests.
import http from 'k6/http';
import { sleep } from 'k6/execution';
export default function () {
http.get('https://test.k6.io');
sleep(1);
}Run Your k6 Test
Now that you have your script.js file, open your terminal in the same directory where you saved the file. Then, execute the script using the k6 run command:
k6 run script.jsk6 will execute the test, and you'll see output in your terminal showing metrics like requests, duration, and checks.
Customizing Your Run
The k6 run command supports various options to customize your test. Two common ones are:
--vus: Sets the number of Virtual Users.--duration: Defines how long the test should run.
For example, to run with 5 VUs for 10 seconds:
k6 run --vus 5 --duration 10s script.jsCLI Command Check
You've learned how to install k6 and run a basic script. Let's test your understanding of the essential k6 CLI command.
k6 Ready: What's Next?
Fantastic! You've successfully installed k6 and run your very first performance test script. We covered:
- What k6 is and its benefits.
- How to install k6 on different operating systems.
- Verifying your installation.
- Using the essential
k6 runcommand to execute a JavaScript test script.
In the next lesson, we'll dive deeper into writing more complex k6 scripts and understanding their structure.
Frequently asked questions
Is the “k6 Installation and CLI” lesson free?
Yes — the full text of “k6 Installation and CLI” is free to read here on the web, and the Load Testing & Performance Benchmarking (JMeter & k6) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Load Testing & Performance Benchmarking (JMeter & k6) course, upgrade to CoddyKit PRO.
What will I learn in “k6 Installation and CLI”?
Install k6 and get familiar with its command-line interface for executing tests. You practise Load Testing & Performance Benchmarking (JMeter & k6) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Load Testing & Performance Benchmarking (JMeter & k6)?
No prior experience is required. Load Testing & Performance Benchmarking (JMeter & k6) on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “k6 Installation and CLI” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Load Testing & Performance Benchmarking (JMeter & k6) lesson?
Yes. Every Load Testing & Performance Benchmarking (JMeter & k6) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- k6 Installation and CLI
- Writing Basic k6 Scripts
- Checks, Thresholds, and Metrics
- Groups and Tags for Organizing Tests