What is a ROS2 workspace?
Atlasbot · 16/8/2026 · 10 min read
Before writing your first ROS2 node, create a workspace — a working directory with a standard structure where package source code is stored, compiled and installed for use in the system.
Key concepts
A minimal ROS2 workspace needs only a src/ directory containing package source code. Building with colcon automatically generates three more directories:
ros2_ws/
├── src/ ← package source code (write/clone here)
├── build/ ← intermediate compilation files
├── install/ ← built packages, ready to use
└── log/ ← logs from the latest build
Only src/ is edited by hand — build/, install/ and log/ are generated by colcon build and can be deleted and rebuilt at any time without losing source code.
Underlay and overlay
System ROS2 (installed through apt install ros-humble-desktop) is also a prebuilt workspace, called the underlay. Your development workspace is the overlay. When you source both environments in the correct order, the overlay takes priority if package names overlap, letting you use system packages and develop your own alongside them.
In short: A workspace is simply a directory following conventions that tell
colconwhere to find source code and where to put usable build results.
How it works
mkdir -p ~/ros2_ws/src # create a workspace; only src is needed
cd ~/ros2_ws
colcon build # build all packages in src/
source install/setup.bash # load the overlay into the current shell
After source, the newly built packages and their nodes become visible to ros2 run and ros2 launch in that terminal.
Technical details
Parameters
Commonly used colcon build options:
| Option | Effect |
|---|---|
--symlink-install | Install symlinks instead of copying files — Python edits need no rebuild |
--packages-select <name> | Build only the specified package(s), saving time |
--parallel-workers N | Limit parallel package builds, useful on machines with little RAM |
colcon also tracks the dependency graph between packages (from package.xml declarations). Rerunning colcon build after changing one package usually rebuilds only that package and its dependents, rather than the entire workspace from scratch.
Practical applications
Robot development teams often use several overlay layers: system underlay (ROS2 installed through apt) → shared overlay (team-wide drivers/libraries, built once and rarely changed) → personal overlay (each developer's workspace for new features). Each person can then rebuild only the code they are changing, rather than rebuilding the entire shared driver system for every experiment.
Practical example
$ colcon build --symlink-install
Output:
Starting >>> my_robot_msgs
Starting >>> my_robot_driver
Finished <<< my_robot_msgs [3.21s]
Starting >>> my_robot_navigation
Finished <<< my_robot_driver [8.45s]
Finished <<< my_robot_navigation [5.02s]
Summary: 3 packages finished [9.87s]
colcon recognizes that my_robot_navigation depends on my_robot_msgs (containing custom message definitions) and builds the latter first. Build order is inferred entirely from each package's <depend> declarations in package.xml.
Common mistakes
- Forgetting
source install/setup.bashin a new terminal or after rebuilding — the node builds, butros2 runreports "package not found" because that terminal has not loaded the latest overlay. This is the most common beginner mistake; check sourcing before suspecting the code. - The same package name exists in multiple workspaces — if overlay and underlay (or two overlays) have matching package names, the last sourced workspace wins. This can mislead you into thinking you are running edited code while actually running an older copy from another workspace.
- Not cleaning
build//install/after major package restructuring — renamed files or major CMakeLists.txt changes can leave stale artifacts and confusing build errors. Removing these directories and rebuilding (rm -rf build install log && colcon build) is a quick diagnostic when errors seem inexplicable. - Sourcing an underlay from a different ROS2 distribution — if both Humble and Jazzy are installed, sourcing the wrong distribution's
setup.bashcan cause hard-to-diagnose version dependency errors.
Conclusion
A workspace follows the src/build/install/log convention, but understanding underlays/overlays and remembering to source after builds are everyday ROS2 development skills. The next article covers Packages — the smallest code organization unit inside a workspace.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.