ROS2 and workspace are both just project folders where our code lives. Our shell can’t find them if we don’t source them.
#if I try to run a ros2 node without sourcing
ros2 run my_package my_node
#the shell will print as below to indicate that such command does not exist.
#it can't track our package
ros2: command not found
Correct Steps
Suppose you have a ROS2 workspace at:
~/ros2_ws/
After building (colcon build
), you do:
source ~/ros2_ws/install/setup.bash
Now your shell knows where to find the nodes, packages, and executables you just built.
Steps to Simplify Sourcing Process
so adding “alias” in bashrc we can make a shortcut to sourcing the workspace,