TExcelTAD
Home › C/C++ Packages: Conan 2, vcpkg & CPM.cmake › Conan 2: Install & First Look

Conan 2: Install & First Look

Conan is an open-source, decentralised C and C++ package manager written in Python and maintained by JFrog. Version 2 (released in 2023) was a rewrite: new recipe API, new CMake integration, new lockfiles and a new cache layout. Everything in this course is Conan 2; Conan 1 recipes and commands (conan install -g cmake, conanbuildinfo.cmake, CONAN_PKG::) don't work in it.

Installing Conan

Conan is a Python package. Install it into an isolated environment so its dependencies don't clash with other tools:

bash
pipx install conan            # recommended: isolated, on PATH
# or, in a virtual environment
python3 -m venv ~/.venvs/conan && ~/.venvs/conan/bin/pip install conan
conan --version

There are also standalone installers and system packages (Homebrew has a conan formula). Pin the version in CI, for example pip install conan==2.33.0, because new Conan releases occasionally change output or defaults.

The Conan home and the default profile

All of Conan's state lives in the Conan home, ~/.conan2 by default (override with CONAN_HOME). On a fresh machine the first thing to run is:

bash
conan profile detect --force

It inspects the compiler on your PATH and writes ~/.conan2/profiles/default. Our container has already done this; here is what it contains and what else is in the home folder:

bash · try it yourself
conan --version
conan config home
ls ~/.conan2
cat ~/.conan2/profiles/default
Conan version 2.33.0
/home/learner/.conan2
extensions
global.conf
migrations
p
profiles
remotes.json
settings.yml
version.txt
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
In ~/.conan2 Purpose
profiles/ named sets of settings, options and conf (default plus your own)
global.conf configuration that applies to every command
remotes.json the servers Conan downloads from and uploads to
p/ the package cache: recipes, sources, builds and binaries
extensions/ plugins (compatibility, profile checks), deployers, custom commands
settings.yml every allowed setting value (which compilers, versions, OSes exist)

Note: conan profile detect guesses. On Linux it picks compiler.cppstd from the compiler's default (gnu17 for GCC 13). Always read the generated profile and commit a copy of the profile your team uses, as shown in Profiles & conf.

Remotes and the cache

A remote is a server with recipes and binaries. A fresh install has one, ConanCenter, the community repository with over 1,500 libraries. The local cache holds what you've downloaded or built:

bash · try it yourself
conan remote list
conan list "*"
conancenter: https://center2.conan.io [Verify SSL: True, Enabled: True]
Found 4 pkg/version recipes matching * in local cache
Local Cache
  catch2
    catch2/3.16.0
  cmake
    cmake/4.4.4
  fmt
    fmt/12.1.0
  spdlog
    spdlog/1.17.0

Our container has no network, so ConanCenter is unreachable, but four recipes are already in the cache: the three libraries this course uses, plus cmake, a tool package that the Catch2 recipe needs to build itself.

The commands you'll use most

Command What it does
conan install <path> resolve the dependencies of a conanfile.txt/.py, get or build their binaries, run generators
conan install --requires=fmt/12.1.0 the same for an ad-hoc requirement, without a conanfile
conan create <path> export a recipe to the cache, build its package and run its test_package
conan graph info <path> show the dependency graph without installing
conan list <pattern> list recipes, revisions and binaries in the cache or a remote (-r)
conan search <pattern> search remotes for recipes
conan profile show / detect / list inspect and create profiles
conan lock create <path> write a lockfile
conan upload <pattern> -r <remote> push recipes and binaries to a server
conan remove <pattern> delete from the cache
conan cache path <ref> where a recipe or package lives on disk

Every command has -h, and most take -f json for scripting.

Asking for one package

conan install --requires=... is the quickest way to check that a package resolves for your profile. Here the installed fmt binary is found in the cache, so nothing is built:

bash · try it yourself
conan install --requires=fmt/12.1.0 2>&1 | sed -n '/Computing dependency graph/,/Installing packages/p'
======== Computing dependency graph ========
Graph root
    cli
Requirements
    fmt/12.1.0#6baf0fb8351783472b94ee6e36232391 - Cache

======== Computing necessary packages ========
Requirements
    fmt/12.1.0#6baf0fb8351783472b94ee6e36232391:e02956bd268869d4519cb2b90dc7b4e51911a5d0#a857dc2fda2e0c13d61393798f6a9684 - Cache

======== Installing packages ========

Read the two sections from top to bottom. Computing dependency graph resolves recipes: fmt/12.1.0#6baf… is the recipe revision, found in the Cache. Computing necessary packages picks a binary for that recipe: the part after the colon, e029…, is the package ID computed from your profile, and its own revision follows the second #. Conan prints that format, name/version#rrev:package_id#prev, all the time; the package IDs lesson explains it in full.

Test yourself

Where does Conan 2 keep its profiles, remotes and package cache by default?

  1. /usr/local/conan
  2. ~/.conan2 (or $CONAN_HOME)
  3. The project's build folder
  4. ~/.cache/conan

What does conan profile detect do?

  1. Downloads ConanCenter's profiles
  2. Inspects your compiler and writes a default profile
  3. Detects which packages are installed
  4. Checks your network

In fmt/12.1.0#6baf…:e029…#a857…, what is the part after the colon?

  1. The recipe revision
  2. The package ID (which binary configuration)
  3. The download URL
  4. A timestamp