Platform Engineering · Lesson 02

Set Up Your Practice Machine: Windows with WSL, Linux, or macOS

Every lab in this course runs in a Linux shell on your own computer, so the first job is a practice machine you can trust and reset. On Windows that means WSL (Windows Subsystem for Linux), which runs a real Linux distribution beside Windows; on a Mac it is the built-in Terminal plus Homebrew for tools; on Linux you already have it. This lesson walks one setup from a new laptop to a verified shell with the base tools, a ~/labs folder for all practice work, and a way to start again cleanly. It also shows the two setups that go wrong most often: virtualisation switched off, and working inside the Windows drive.

Difficulty: Beginner · Know this first: Lesson F11, Lesson F25

What you will learn

By the end of this lesson you can work at four levels:

This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.

Run it as:

When it breaks, I check

One thing to remember

Where the time goes

This bar adds up minutes from a new laptop to running the first lab. It is a worked example, not a measurement; downloads depend on your connection. The install and "where files live" hops decide whether the setup works at all, and how well.

Try it: how long until your first lab?

Pick your system, whether virtualisation is on (Windows only), and where you keep your practice work.

38minutes to the first lab
fastfile-heavy commands
noneknown problems

Check yourself

Three questions. No score is saved anywhere — this is just you against the material.

Basic to master

Setting up a practice machine grows in four levels: a working shell, a verified toolset, a reproducible setup, and environments you can rebuild at will.

Basic — A working shell

At the basic level you have a Linux shell you can type commands into.

  • WSL 2 on Windows, Terminal on macOS, or a terminal on Linux.
  • Updated packages.
  • A labs folder in your home directory.

Where it breaks: working on the Windows drive, or in your real project folders.

Try it: Basic

What does wsl -l -v show you?

Now do it: Run it and check VERSION.

Intermediate — A verified toolset

At the intermediate level you know exactly what you have.

  • A check that prints the system, distribution, and tool versions.
  • Tools from the package manager, updated regularly.
  • Your editor opening files inside Linux (for example VS Code with its WSL extension).

Try it: Intermediate

Why install tools with apt or brew rather than downloading installers?

Now do it: List your tools and where each came from.

Advanced — A reproducible setup

At the advanced level you can rebuild the machine from a script.

  • A setup script that installs pinned tools and checks them.
  • Dotfiles (shell, Git, editor settings) in a Git repository.
  • An exported clean image of the environment.

Try it: Advanced

Your laptop is replaced. What gets you back to a working setup fastest?

Now do it: Write a setup script for the tools in this lesson.

Master — Disposable environments

At the master level environments are cheap to create and throw away.

  • Dev containers or virtual machines defined in code, per project.
  • Separate environments for work and practice, with no shared credentials.
  • A regular reset to prove the setup still builds from scratch.

Trade-off: disposable environments take effort to define; a hand-built machine is quick today and impossible to reproduce next year.

Try it: Master

Why keep practice and work environments separate?

Now do it: Check which credentials your practice shell can see.

Go deeper

Useful WSL commands, run in Windows PowerShell (not inside Linux):

wsl --install                       # install WSL 2 and Ubuntu (administrator PowerShell, then restart)
wsl -l -v                           # distributions, running state, WSL version
wsl --update                        # update the WSL kernel and components
wsl --shutdown                      # stop every running distribution (frees memory)
wsl --export Ubuntu ubuntu.tar      # back up a distribution to a file
wsl --import Ubuntu2 C:\wsl\u2 ubuntu.tar   # restore it under a new name
wsl --unregister Ubuntu             # DELETE the distribution and all files in it

Line endings: Git for Windows can convert LF to CR LF on checkout. Inside WSL use Linux Git, or set git config --global core.autocrlf input, and set your editor to save files with LF. cat -A file shows a CR as ^M at the end of each line; sed -i 's/\r$//' file removes them.

On Apple silicon Macs, most tools run natively; container images must be built for ARM (linux/arm64) or run under emulation, which is slower. Docker Desktop and Podman Desktop both handle this, and the container lesson covers it.

One time it broke

This is a composite of a failure pattern that keeps repeating; the details are illustrative. The script that worked on everyone else's machine.

Timeline

  • Day 1A new engineer clones the team's tools repository into C:\Users\sam\work with Git for Windows, which converts line endings to CR LF, then opens WSL to run the setup script from /mnt/c/Users/sam/work.
  • Day 1The script fails on its first line: "/bin/bash^M: bad interpreter: No such file or directory". Re-saving it in another editor fixes that script; three others fail the same way.
  • Day 2The repository is cloned again inside WSL, into ~/work, with Linux Git. Everything works, and the test suite runs four times faster.

What changed after

The onboarding guide now says to clone inside WSL, and the repository has a .gitattributes file with * text=auto eol=lf, so line endings stay LF on every machine.

Try it yourself, from scratch

Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.

Before you start: A Linux shell: WSL on Windows (wsl --install in an administrator PowerShell, then restart), Terminal on macOS, or a terminal on Linux. Nothing else; this lab checks what you have.

1. Linux commands

Type each one, read what it prints, and compare it with the note above it.

  1. What system are you on? Print the kernel name, the CPU architecture, and the distribution.

    Read-only

    uname -s
    uname -m
    . /etc/os-release && echo "$NAME $VERSION_ID"

    Options: uname -s prints the kernel name, -m the machine (CPU) type. /etc/os-release is a file of NAME=value lines; . (source) reads it into the shell so $NAME and $VERSION_ID are set. On macOS use sw_vers instead of os-release.

    Expect: Linux, then x86_64 (or aarch64 on ARM), then your distribution, such as Ubuntu 24.04. On macOS, uname -s prints Darwin and uname -m prints arm64 on Apple silicon.

  2. Check that each base tool is installed. Nothing is changed: command -v only looks a name up.

    Read-only

    for t in git curl jq python3 sqlite3; do
      command -v "$t" >/dev/null && echo "$t ok" || echo "$t MISSING"
    done

    Options: command -v name prints where a command is and succeeds, or prints nothing and fails; >/dev/null hides the path; && runs the next command only on success, || only on failure.

    Expect: Five lines, each ok: git ok, curl ok, jq ok, python3 ok, sqlite3 ok.

    If it fails: A MISSING line: install it with sudo apt update && sudo apt install -y git curl jq python3 python3-venv sqlite3 (macOS: brew install git curl jq python sqlite), then run the check again.

  3. Make the labs folder and check you are in the Linux filesystem, not the Windows drive.

    Reversible

    mkdir -p ~/labs/setup && cd ~/labs/setup
    pwd
    case "$PWD" in /mnt/*) echo "WARNING: this is the Windows drive; use ~/labs instead" ;; *) echo "good: Linux filesystem" ;; esac

    Options: mkdir -p creates parent folders as needed and does not complain if they exist; case matches $PWD (the current folder) against a pattern.

    Expect: A path such as /home/you/labs/setup (or /root/labs/setup when you are root), then good: Linux filesystem.

    Clean up: cd ~ && rm -rf ~/labs/setup removes everything this lab creates.

  4. See the line-ending trap for yourself: a script with Windows (CR LF) endings, then the same script fixed.

    Reversible

    printf 'cd /tmp\r\npwd\r\n' > crlf.sh
    bash crlf.sh; echo "exit status $?"
    cat -A crlf.sh
    sed -i 's/\r$//' crlf.sh && bash crlf.sh

    Options: printf writes \r\n (carriage return, newline) the way Windows editors do; cat -A shows invisible characters (a CR appears as ^M, a line end as $); sed -i 's/\r$//' removes a CR at the end of each line, in place. On macOS use sed -i '' 's/\r$//'.

    Expect: First crlf.sh: line 1: cd: $'/tmp\r': No such file or directory and crlf.sh: line 2: $'pwd\r': command not found, then exit status 127; cat -A shows cd /tmp^M$ and pwd^M$; after the fix, /tmp.

    If it fails: If your own scripts fail like this, set your editor to save with LF line endings, and in Git use core.autocrlf input or a .gitattributes with * text=auto eol=lf.

  5. Clean up.

    Potentially destructive

    cd ~ && rm -rf ~/labs/setup
    ls ~/labs

    Expect: No error; ls ~/labs no longer lists setup (it may print nothing).

2. Python: setup_check.py

This program compares the tool versions a machine reports with the minimum versions the course needs, the way a setup script would: it parses version strings into numbers, compares them properly (so 2.9 is older than 2.40), and prints what to install or upgrade. Save it as setup_check.py, then run it.

# setup_check.py
NEED = {"git": "2.34", "python3": "3.10", "sqlite3": "3.37", "jq": "1.6", "curl": "7.81"}

def parse(v):                                   # "3.12.3" -> (3, 12, 3); ignores anything after a space
    return tuple(int(p) for p in v.split()[0].split(".") if p.isdigit())

def check(found):
    for tool, minimum in NEED.items():
        have = found.get(tool)
        if have is None:
            print(f"  {tool:<8} MISSING          install it")
        elif parse(have) < parse(minimum):
            print(f"  {tool:<8} {have:<16} too old: need {minimum} or newer")
        else:
            print(f"  {tool:<8} {have:<16} ok")

print("laptop A (Ubuntu 24.04):")
check({"git": "2.43.0", "python3": "3.12.3", "sqlite3": "3.45.1", "jq": "1.7.1", "curl": "8.5.0"})
print("laptop B (an old image):")
check({"git": "2.9.5", "python3": "3.8.10", "sqlite3": "3.31.1", "curl": "7.68.0"})
print()
print("string comparison would say", "'2.9.5' > '2.34':", "2.9.5" > "2.34")
print("number comparison says     ", "(2, 9, 5) > (2, 34):", parse("2.9.5") > parse("2.34"))

Run it, and you should see this output:

$ python3 setup_check.py
laptop A (Ubuntu 24.04):
  git      2.43.0           ok
  python3  3.12.3           ok
  sqlite3  3.45.1           ok
  jq       1.7.1            ok
  curl     8.5.0            ok
laptop B (an old image):
  git      2.9.5            too old: need 2.34 or newer
  python3  3.8.10           too old: need 3.10 or newer
  sqlite3  3.31.1           too old: need 3.37 or newer
  jq       MISSING          install it
  curl     7.68.0           too old: need 7.81 or newer

string comparison would say '2.9.5' > '2.34': True
number comparison says      (2, 9, 5) > (2, 34): False

3. What to notice

4. Advanced: every step as one Bash script

The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/set-up-your-practice-machine-wsl-linux-or-macos && cd ~/labs/set-up-your-practice-machine-wsl-linux-or-macos) and save this as lab.sh.

#!/usr/bin/env bash
# The Linux steps of "Set Up Your Practice Machine: Windows with WSL, Linux, or macOS", as one script (save it as lab.sh).
#
#   ./lab.sh          run every step, in order
#   ./lab.sh 2 4      run only steps 2 and 4
#   ./lab.sh --list   list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.

STEPS=(
  'What system are you on? Print the kernel name, the CPU architecture, and the distribution.'
  'Check that each base tool is installed. Nothing is changed: command -v only looks a name up.'
  'Make the labs folder and check you are in the Linux filesystem, not the Windows drive.'
  'See the line-ending trap for yourself: a script with Windows (CR LF) endings, then the same script fixed.'
  'Clean up.'
)

step_1() {
uname -s
uname -m
. /etc/os-release && echo "$NAME $VERSION_ID"
}

step_2() {
for t in git curl jq python3 sqlite3; do
  command -v "$t" >/dev/null && echo "$t ok" || echo "$t MISSING"
done
}

step_3() {
mkdir -p ~/labs/setup && cd ~/labs/setup
pwd
case "$PWD" in /mnt/*) echo "WARNING: this is the Windows drive; use ~/labs instead" ;; *) echo "good: Linux filesystem" ;; esac
}

step_4() {
printf 'cd /tmp\r\npwd\r\n' > crlf.sh
bash crlf.sh; echo "exit status $?"
cat -A crlf.sh
sed -i 's/\r$//' crlf.sh && bash crlf.sh
}

step_5() {
cd ~ && rm -rf ~/labs/setup
ls ~/labs
}

# print a step that has to be run by hand, instead of running it
by_hand() {
  echo "  (run this one yourself: $1)"
  sed 's/^/    /'
}

RESULTS=()
run_step() {
  local n=$1 start=$SECONDS code
  printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
  "step_$n"
  code=$?
  RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}

summary() {
  echo
  echo "== summary"
  local r
  for r in "${RESULTS[@]}"; do echo "  $r"; done
}

case "${1:-}" in
  -h|--help) sed -n '2,6p' "$0"; exit 0 ;;
  --list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac

[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
  if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
    echo "there is no step '$n'; try --list" >&2
    exit 2
  fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done

Then make it executable and run it:

chmod +x lab.sh
./lab.sh --list     # the steps
./lab.sh            # every step, then a summary of exit codes and times
./lab.sh 2 3        # only steps 2 and 3

5. Learn the basics behind it

New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.

If you remember nothing else

Design exercise

You are writing the setup guide for a team of 12 new engineers: 8 on Windows laptops, 3 on Apple silicon Macs, and 1 on Linux. Design the practice environment.

Clarifying questions to ask

What does each person install, in what order? How do they check it worked? Where do they keep practice work? How do they reset? What goes wrong most often on each system, and how does the guide prevent it?

Rough sizing

Say one hour of setup time per person, a 20 GB disk budget, and the first lab on day one.

Shape of the answer

Windows: wsl --install with Ubuntu, a firmware virtualisation check, work in ~/labs; macOS: Homebrew and Terminal, ARM images noted; Linux: the package manager. Everyone runs the same verification script and keeps a .gitattributes with LF endings in team repositories. A reset section covers lab folders and wsl --export / --unregister.

Trade-offs to name

A single dev container would give everyone identical tools but adds Docker to day one; native setups are lighter and differ slightly per system, so the verification script matters more.

Failure modes and how to troubleshoot them

Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.

ScenarioWhereEffectWhat goes wrong
Virtualisation offHop 2: Install a shellBreaksUbuntu opens and stops: "WslRegisterDistribution failed with error: 0x80370102. Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS." The Windows feature is on; virtualisation is off in the firmware.
Working in the Windows driveHop 5: Labs folderDegradesCreated as /mnt/c/Users/asha/labs, "so it shows in Windows Explorer".
Working in the Windows driveHop 7: Where files liveBreaksIn /mnt/c/Users/asha/labs, cloning and installing take several times longer, and the first script, saved from a Windows editor, fails: "$'\r': command not found", because every line ends with an invisible carriage return.

How to troubleshoot

  1. Write down the symptom and when it started: what users see, which number moved, and what changed just before (a deploy, a config change, traffic).
  2. Walk the path in order, from the first hop to the last: Your system → Install a shell → Update → Base tools → Labs folder → Verify → Where files live → Reset plan → First lab. The first hop whose evidence is wrong is where to dig.
  3. At that hop, run the read-only check from the diagram or the lab first; change nothing until the evidence points at a cause.
  4. Fix the smallest thing that restores service, or roll back the last change, and confirm the symptom is gone with the same check.
  5. Write down what you found and the check that would have caught it sooner, so the next person starts there.

References and review

The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.

Last updated . Next review due by November 2027. Found something out of date? Tell me.

Saved on this device, in this browser.
Next in this series · Lesson 03
The Shell Without Surprises: Quoting, Pipes, Redirects, Globs, Variables, and Exit Codes

Before a command runs, the shell rewrites the line you typed: it expands variables, splits words, matches file names against wildcards, and sets up redirects and pipes.

Go to Lesson 03 →

Or browse the full course from the Lessons index.