Append PATH in GitHub Actions

One can globally set environment variables in GitHub Actions by using env: at the top level of a “.github/workflows/ci.yml” file, for example:

name: ci

env:
  CMAKE_GENERATOR: Ninja
  CC: gcc

In other cases like appending to PATH, this must be done dynamically but can still have global scope. In GitHub Actions this is done by writing to environment files.

Prepend PATH

To add “~/.local/bin” to PATH, under a run: stanza per operating system:

Linux / MacOS

echo "${HOME}/.local/bin" >> $GITHUB_PATH

Windows

Windows defaults to PowerShell, so the syntax is distinct from Unix shells:

echo "${HOME}/.local/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append