ROS2-009-Communication Mechanisms, Wrapping Up: Metapackages (MetaPackage)
Introduction
When you write a big module in ROS2, you generally split it into several sub-packages by function. For a robot navigation module, for instance, it might be split into localisation, path planning, offline maps and other sub-packages written separately. So when we need to install that module, do we have to install those sub-packages one by one before we get the whole feature set?
Metapackage (MetaPackage)
ROS2 gives you a way to bundle several different feature sub-packages into one big package, so that when we need to install some feature module we just install that one big package directly. That package is called a metapackage, i.e. MetaPackage.
A MetaPackage is essentially a concept from Linux file management. As a "fake package" with no substantive content inside ROS2, you can think of it as a book's "table of contents index". It depends on other packages, and through it those other packages come together. When you install a MetaPackage, it tells whoever or whatever is installing it which sub-packages are in this set and where to download them.
What is it for?
Making installation easy for the user. inclusive☝🤓
How do you do it?
Take the following directory as an example — we want to bind all the feature packages below into one metapackage:
A directory with several packages
First move to the workspace where you want to create the metapackage, and add a package under the src directory:
ros2 pkg create tutor_ls_plumbingAfter running the command above, remember to "cd" back to the workspace.
Inside the newly created "tutor_ls_plumbing" package you only need to edit package.xml — no need to touch "CMakeLists.txt"
In package.xml, add <exec_depend></exec_depend>, and inside it add the packages you want in the index:
<exec_depend>base_interfaces_demo</exec_depend>
......Then build it:
colcon build --packages-select tutor_ls_plumbingIn the end it should look something like this:
Afterword
You can also go looking for other people's projects on GitHub to see how they design their metapackages.
For example navigation2/navigation2 at main · ros-navigation/navigation2
Important
This article was translated by Hermes Agent; the original text can be found at here. The translation is for reference only. Translation time: 2026-11-05
