Ubuntu Linux for Robotics · Lesson 42 of 96
Understanding the ROS 2 filesystem layout
/opt/ros/lyrical, share, lib and include, workspace install folders and ~/.ros.
Estimated time · 30–45 min
Learning goals
What you will understand
- Explain understanding the ros 2 filesystem layout in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
The distribution lives in /opt/ros/lyrical: bin (executables), lib (libraries and node executables under lib/<package>), share (each package's launch files, configs, URDFs and package.xml) and include (C++ headers). A workspace's install folder has the same structure, one subfolder per package.
Your own files and logs are in ~/.ros (log folder ~/.ros/log and settings). Knowing the layout lets you find launch files (ros2 pkg prefix, then share/<pkg>/launch), example configs to copy, and the executable that ros2 run starts. A common error is forgetting to install a launch or config folder in CMakeLists.txt so it is missing from share.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the understanding the ros 2 filesystem layout commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
ls /opt/ros/lyrical
# Top-level folders: bin, lib, share, include, etc.
ls /opt/ros/lyrical/share/demo_nodes_cpp
# A package's shared files (package.xml, launch, cmake).
ls /opt/ros/lyrical/lib/demo_nodes_cpp
# The executables that ros2 run can start.
ros2 pkg executables demo_nodes_cpp
# The same list, through the ROS tool.
ls ~/ros2_ws/install
# Your workspace has the same layout, one folder per package.
ls ~/.ros/log | tail -3
# The most recent log folders.What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
Watch it run · The robot's computer
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Understanding the ROS 2 filesystem layout. Expected result: The executables of demo_nodes_cpp, such as talker and listener
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
# TODO: list the executables of demo_nodes_cpp with ros2 pkg executablesExpected output
The executables of demo_nodes_cpp, such as talker and listenerStuck? Show the full solution (try it yourself first)
ros2 pkg executables demo_nodes_cppExpected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
For the package turtlesim, locate its package.xml, its executables and its launch files (if any), and find the log folder of your last ROS run. Write a one-line description of what lives in bin, lib, share and include.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.