Creating A Workspace

Create a ROS 2 workspace and a Python package, then build the workspace successfully.

Concept

A workspace is a folder that contains all your ROS 2 packages and build artifacts. A package is a self-contained module inside a workspace — it holds your nodes, launch files, and configuration.

  • src/ — your source packages go here
  • build/ — colcon build artifacts (auto-generated)
  • install/ — final installed files; sourced to activate packages
  • log/ — build logs

Steps

1. Source ROS 2

Do this in every new terminal, or add to ~/.bashrc:

source /opt/ros/humble/setup.bash

2. Create the workspace

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws

3. Create the package

cd ~/ros2_ws/src
ros2 pkg create my_package --build-type ament_python --dependencies rclpy

This creates the folder structure:

my_package/
├── package.xml
├── setup.cfg
├── setup.py
└── my_package/
    └── __init__.py

4. Build the workspace

cd ~/ros2_ws
colcon build

5. Source the workspace

Run this after every build, in every terminal that needs the package:

source ~/ros2_ws/install/setup.bash

6. Verify

ros2 pkg list | grep my_package

Expected output:

my_package