ROS 2 cheat sheet
66 commands, grouped by what you are trying to do, each with the one line of why. Works for Humble and Jazzy; differences are marked. Print it: Ctrl/⌘ + P.
install/setup.bash in every new terminal; when a topic is silent run ros2 topic info -v and compare QoS; when the robot does nothing, check tf with view_frames before touching your code.Environment and workspace
Nothing works until the right setup file is sourced in the terminal you are typing in. Most "command not found" and "package not found" errors are this. What ROS 2 is →
| Command | What it is for |
|---|---|
source /opt/ros/jazzy/setup.bash | Load the ROS 2 install into this shell (replace jazzy with humble, iron…). Put it in ~/.bashrc so you stop forgetting. |
mkdir -p ~/ros2_ws/src && cd ~/ros2_ws | A workspace is just a folder with a src/ directory. Packages go in src/. |
colcon build --symlink-install | Build every package in src/. --symlink-install lets Python and launch-file edits take effect without rebuilding. |
colcon build --packages-select my_pkg | Build one package instead of waiting for all of them. |
source install/setup.bash | Overlay your workspace on top of the ROS install. Run it after every build, in every new terminal. |
rosdep install --from-paths src --ignore-src -r -y | Install the system dependencies every package in src/ declares in its package.xml. Run rosdep update first on a fresh machine. |
export ROS_DOMAIN_ID=7 | Isolate your nodes from everyone else on the same network. Pick 0–101; both machines must match. |
export ROS_LOCALHOST_ONLY=1 | Keep discovery traffic on this machine only. Handy on shared Wi-Fi.Jazzy prefers ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST. |
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp | Switch the DDS middleware (Fast DDS is the default). Every node in the system should use the same one. |
Packages
A package is the unit of code you build, share and depend on.
| Command | What it is for |
|---|---|
ros2 pkg create --build-type ament_python my_pkg --dependencies rclpy std_msgs | Scaffold a Python package. Use ament_cmake for C++. |
ros2 pkg create --build-type ament_cmake my_pkg --node-name talker | Scaffold a C++ package with a starter node already wired into CMake. |
ros2 pkg list | Every package the current shell can see. |
ros2 pkg executables my_pkg | What can I actually ros2 run from this package? |
ros2 pkg prefix my_pkg | Where is it installed? Useful when two copies are fighting. |
Nodes
A node is one running program. Everything else is how nodes talk. Nodes explained →
| Command | What it is for |
|---|---|
ros2 run my_pkg my_node | Start one executable from a package. |
ros2 run my_pkg my_node --ros-args -r __node:=left_cam -r /image:=/left/image | Rename the node and remap a topic at launch time, no code change. |
ros2 run my_pkg my_node --ros-args -p rate:=10.0 --params-file cfg.yaml | Set a parameter inline, or load a whole YAML of them. |
ros2 run my_pkg my_node --ros-args --log-level debug | See everything the node logs. Use --log-level my_node:=debug to target one node. |
ros2 node list | Who is running right now? |
ros2 node info /my_node | Every topic, service, action and parameter this node exposes. The first thing to run when something is silent. |
Topics
Streams of messages: sensors publish, controllers subscribe. Most debugging is looking at a topic. Topics explained →
| Command | What it is for |
|---|---|
ros2 topic list -t | All topics with their message types. |
ros2 topic echo /scan | Print messages as they arrive. Add --once for one, --no-arr to hide long arrays. |
ros2 topic echo /scan --qos-reliability best_effort | Sensor topics are often best-effort; a reliable subscriber hears nothing. This is the classic "echo shows nothing" fix. |
ros2 topic hz /scan | Publish rate. A lidar that should be 10 Hz showing 2 Hz tells you where the problem is. |
ros2 topic bw /camera/image_raw | Bandwidth. Cameras over Wi-Fi fail here first. |
ros2 topic info /cmd_vel -v | Who publishes, who subscribes, and with which QoS. Mismatched QoS is why two nodes "cannot see each other". |
ros2 topic pub -r 10 /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.2}, angular: {z: 0.0}}" | Publish by hand at 10 Hz. --once for a single message. Press Ctrl-C to stop the robot. |
ros2 interface show geometry_msgs/msg/Twist | The fields of a message, so you know what to put in the braces above. |
ros2 interface list | grep -i laser | Find a message type when you only remember part of its name. |
Services
Request and reply. Use them for things that happen once: reset, take a photo, switch a mode. Services explained →
| Command | What it is for |
|---|---|
ros2 service list -t | All services and their types. |
ros2 service type /reset | Which request/response type does this service use? |
ros2 service call /reset std_srvs/srv/Trigger "{}" | Call it from the terminal. Empty braces for a request with no fields. |
ros2 interface show std_srvs/srv/SetBool | Request fields above the ---, response fields below it. |
ros2 service find std_srvs/srv/Trigger | Every service of a given type. |
Actions
Long-running goals with feedback and cancel: navigate to a pose, move an arm, dock. Actions explained →
| Command | What it is for |
|---|---|
ros2 action list -t | All action servers and their types. |
ros2 action info /navigate_to_pose | Which nodes serve and which call this action. |
ros2 action send_goal /fibonacci example_interfaces/action/Fibonacci "{order: 5}" --feedback | Send a goal and watch feedback stream back until the result arrives. |
ros2 interface show nav2_msgs/action/NavigateToPose | Goal, result and feedback fields, separated by ---. |
Parameters
Per-node settings you can read and change while the node runs. Parameters explained →
| Command | What it is for |
|---|---|
ros2 param list | Every parameter of every node. Add a node name to narrow it. |
ros2 param get /controller max_speed | Read one value. |
ros2 param set /controller max_speed 0.5 | Change it live. Nodes decide whether to accept the change. |
ros2 param dump /controller > controller.yaml | Save the current configuration to a file you can load next time.Older Humble builds write the file themselves instead of printing; check with --help. |
ros2 param load /controller controller.yaml | Load a YAML of parameters into a running node. |
ros2 param describe /controller max_speed | Type, description and allowed range, if the node declared them. |
Launch files
Start many nodes with their parameters and remaps in one command. Real robots are launched, not ros2 run one at a time. Launch files explained →
| Command | What it is for |
|---|---|
ros2 launch my_pkg bringup.launch.py | Run a launch file from a package. |
ros2 launch my_pkg bringup.launch.py use_sim_time:=true | Pass a launch argument. use_sim_time is the one you will set most, for Gazebo and bag playback. |
ros2 launch my_pkg bringup.launch.py -s | Show the arguments a launch file accepts without starting anything. |
ros2 launch ./my.launch.py | Run a launch file by path, outside any package. |
Recording and playback (rosbag2)
Record the real robot once, replay it a hundred times on your laptop.
| Command | What it is for |
|---|---|
ros2 bag record -a | Record every topic. Big files fast — prefer naming topics. |
ros2 bag record -o run1 /scan /odom /tf /tf_static | Record chosen topics into a folder named run1. Always include /tf and /tf_static. |
ros2 bag info run1 | Duration, topics, message counts, storage format. |
ros2 bag play run1 --clock | Replay and publish /clock so nodes started with use_sim_time:=true follow the recording. |
ros2 bag play run1 -r 0.5 -l | Half speed, looping. |
ros2 bag record -s mcap -a | Record in MCAP, the default storage from Iron onwards and faster to seek than SQLite. |
Coordinate frames (tf2)
Where is the lidar relative to the base, and the base relative to the map? When navigation "does nothing", check tf first. tf2 explained →
| Command | What it is for |
|---|---|
ros2 run tf2_tools view_frames | Writes a PDF of the whole frame tree. Broken trees are obvious on paper. |
ros2 run tf2_ros tf2_echo map base_link | The live transform between two frames, and an error if there is no path between them. |
ros2 run tf2_ros static_transform_publisher --x 0.1 --y 0 --z 0.2 --yaw 0 --pitch 0 --roll 0 --frame-id base_link --child-frame-id laser | Publish a fixed transform from the command line (named flags since Humble). |
ros2 topic echo /tf_static --qos-durability transient_local | Static transforms are latched; a plain echo misses them. |
Debugging and tools
In rough order of how often they save the day.
| Command | What it is for |
|---|---|
ros2 doctor | Checks your install, network and environment and names what is wrong. ros2 doctor --report for the long version. |
ros2 daemon stop && ros2 daemon start | The discovery daemon caches node lists. When ros2 node list is stale or empty, restart it. |
rqt_graph | A picture of who talks to whom. The fastest way to spot a topic-name typo. |
ros2 run rqt_console rqt_console | All log messages from all nodes, filterable by level. |
ros2 run rviz2 rviz2 -d my.rviz | 3D visualisation of frames, scans, maps and paths. -d loads a saved layout. |
ros2 run plotjuggler plotjuggler | Plot any numeric field of any topic over time. Needs the plotjuggler-ros package. |
ros2 lifecycle list /my_node && ros2 lifecycle set /my_node configure | Managed (lifecycle) nodes, as used by Nav2, must be configured and activated before they do anything. |
ros2 component list | Nodes loaded into a composed container. Composition is why one process can hold many nodes. |
Go deeper
- ROS 2 — what it is and why robots use it
- Quality of Service (QoS) — why two nodes cannot see each other
- ROS 2 Playground — try these commands in your browser
- Wire track — Arduino to ROS 2, six written lessons
Source of truth for every command: the ROS 2 documentation at docs.ros.org (Humble and Jazzy CLI tools pages) and the ros2cli package. Found a flag that changed? Tell us.