Install Packages

This action installs dependencies from multiple package managers for a workflow. This is usually the next step in your workflow after setting up a C++ compiler with Setup C++.

The action currently supports installing packages with apt-get and vcpkg. A number of auxiliary options are available to customize the behavior of both apt-get and vcpkg.

If vcpkg dependencies are required, vcpkg will be installed and related paths are returned from the action. Both vcpkg and its compiled dependencies are cached.

When your library depends on vcpkg for dependencies, it’s important to run the Setup C++ action before this step because vcpkg packages are built from source and this allows us to use the compiler set up in the previous step.

Next steps

After setting up the dependencies for your C++ project, the next step in your workflow should usually be CMake Workflow.

Alternatively, if your libraries depends on Boost, the next step in your workflow should usually be Boost Clone, which allows the workflow to only download the required subset of Boost libraries required by the project.

Example

steps:
- name: Install packages
  uses: alandefreitas/cpp-actions/package-install@v1
  id: package-install
  with:
    vcpkg: ${{ matrix.vcpkg-packages }}
    vcpkg-triplet: ${{ matrix.triplet }}
    packages: ${{ matrix.install }}
    apt-get-ignore-missing: ${{ matrix.is-container }}
    cc: ${{ steps.setup-cpp.outputs.cc }}
    ccflags: ${{ matrix.ccflags }}
    cxx: ${{ steps.setup-cpp.outputs.cxx }}
    cxxflags: ${{ matrix.cxxflags }}

Input Parameters

Parameter

Description

Default

trace-commands

Trace commands executed by the workflow.

false

vcpkg

List of packages we should install with vcpkg.

If any package is included in this list, vcpkg will be installed and the vcpkg toolchain file will be returned.

Individual packages can define a custom triplet by appending :<triplet> to the package name.

apt-get

List of packages we should install with apt-get.

Additional options are provided to customize the behavior of apt-get.

brew

List of Homebrew formula packages to install.

Accepts formula names (e.g., cmake, gcc) and supports the formula@version syntax for versioned formulae (e.g., gcc@14, llvm@18).

Packages are installed on macOS and Linux (via Linuxbrew). On Windows, this input is silently ignored.

brew-cask

List of Homebrew cask packages to install.

Casks are macOS GUI applications (e.g., visual-studio-code, docker, firefox). The --cask flag is used internally to avoid the formula/cask name ambiguity problem where brew install silently prefers formulae over casks when both share the same name.

On Linux, cask installs are silently skipped since casks are macOS-only (.app bundles). On Windows, this input is silently ignored.

choco

List of Chocolatey packages to install on Windows.

Accepts package names (e.g., cmake, ninja) and supports the --version=X.Y.Z syntax for version pinning (e.g., cmake --version=3.28.0).

Packages are installed on Windows only. On macOS and Linux, this input is silently ignored.

packages

List of packages to install using the OS-native package manager.

Packages are automatically routed to the appropriate package manager based on the runner platform: apt-get on Linux, brew on macOS, and choco on Windows.

Supports the @version syntax for version pinning, which is translated to the PM-native format: - On Linux (apt-get): pkg@14 becomes pkg-14 - On macOS (brew): pkg@14 is passed through as-is (native brew syntax) - On Windows (choco): pkg@14 becomes pkg --version=14

Packages without @version are passed through unchanged on all platforms. Routed packages are merged with any PM-specific packages from dedicated inputs (e.g., apt-get, brew, choco).

cxx

C++ compiler to be used by vcpkg. If the compiler is not specified, the value will be retrieved from the environment variable CXX.

Setting the compiler is particularly important when the compiler being tested is different from the default compiler used by vcpkg.

cxxflags

C++ flags used by vcpkg. If the flags are not specified, the value will be retrieved from the environment variable CXXFLAGS.

cc

C compiler used by vcpkg. If the compiler is not specified, the value will be retrieved from the environment variable CC.

ccflags

C flags used by vcpkg. If the flags are not specified, the value will be retrieved from the environment variable CFLAGS.

vcpkg-triplet

The triplet used by vcpkg to install packages.

If no triplet is specified, a default triplet will be inferred from the platform.

Individual packages can override this value by specifying a triplet in the package name.

vcpkg-dir

The directory where vcpkg should be cloned and installed.

If the directory is unspecified, the runner tool cache is used.

vcpkg-branch

vcpkg branch we should use. This is usually the master branch.

master

vcpkg-cache

Whether we should cache vcpkg and its built dependencies.

This is useful when you want to speed up your workflow by caching vcpkg and its built dependencies for next workflows.

You can disable this option when you want to always build vcpkg and its dependencies from scratch or want to save cache storage.

true

vcpkg-force-install

Whether we should force install vcpkg and even when no vcpkg packages are listed.

This is useful when you want to use vcpkg in manifest mode.

false

retries

Default number of attempts for all package manager operations.

This shared retry count applies to apt-get, brew, and choco installs unless overridden by a PM-specific retry input (e.g., apt-get-retries, brew-retries, choco-retries).

Each retry uses exponential backoff to handle transient network failures.

5

brew-retries

Number of attempts for Homebrew install operations.

Overrides the shared retries input for brew installs specifically.

When not provided, brew installs fall back to the shared retries value (default 5).

Each retry uses exponential backoff to handle transient network failures.

choco-retries

Number of attempts for Chocolatey install operations.

Overrides the shared retries input for choco installs specifically.

When not provided, choco installs fall back to the shared retries value (default 5).

The Chocolatey community repository enforces rate limits (~20 downloads/min per IP), and GitHub-hosted runner IPs are shared across many users. This input allows you to configure more retries for choco specifically to handle rate-limit-induced failures.

Each retry uses exponential backoff to handle transient network and rate-limit failures.

apt-get-retries

Number of attempts when apt-get fails.

Overrides the shared retries input for apt-get operations specifically.

This option is useful when apt-get fails due to a temporary network issue.

When calling apt-get to install packages, this passes the -o Acquire::Retries option to apt-get.

For other commands, the command will be called multiple times until it succeeds or the number of retries is exhausted. Each retry will be separated by a delay with an exponential backoff.

5

apt-get-sources

List of APT repository sources, one per line.

Each line can be a PPA (e.g., ppa:ubuntu-toolchain-r/ppa) or a full deb line (e.g., deb https://apt.llvm.org/noble/ llvm-toolchain-noble-21 main).

When paired positionally with apt-get-source-keys, the source line gets signed-by= injected automatically pointing to the imported key in /etc/apt/keyrings/. Unpaired sources are added via apt-add-repository.

apt-get-source-keys

List of GPG key URLs for APT sources, one per line.

Each key URL is downloaded, dearmored with gpg --dearmor, and stored in /etc/apt/keyrings/. Keys are paired positionally with apt-get-sources entries: key at index N is paired with source at index N. For paired sources, signed-by= is automatically injected into the source line pointing to the imported key.

apt-get-ignore-missing

Whether apt-get should ignore missing packages.

This attempts to install packages one by one and passes the --ignore-missing option to apt-get.

false

apt-get-add-architecture

Argument to pass to dpkg to add an architecture.

This is useful when installing packages that require a different architecture than the default one.

If this string is not empty, it will be passed to dpkg with the --add-architecture flag.

Common values for this parameter are: amd64 (64-bit x86), i386 (32-bit x86), armhf (ARM Hard Float), arm64 (ARM 64-bit), and ppc64el (PowerPC 64-bit Little Endian).

This parameter can also be a list of architectures.

apt-get-bulk-install

This option determines if we should call apt-get once for each package (false) or if we should call apt-get once for all packages (true).

This option is useful when installing a large number of packages, since it can speed up the installation process.

However, installing libraries individually provides more better information in the logs, which can be useful for debugging.

false

Outputs

Output

Description

vcpkg-toolchain

vcpkg toolchain file

This output value can be used to configure CMake to use vcpkg.

vcpkg-executable

vcpkg executable file