Table of Contents
- What is ROS 2?
- Why Learn ROS 2?
- System Requirements
- How to Install ROS 2 Jazzy
- Verify ROS 2 Installation
- Configure ROS 2 Environment
- Run Your First ROS 2 Demo
- What Are ROS 2 Nodes?
- What Are ROS 2 Topics?
- Create a ROS 2 Workspace
- Create a ROS 2 Package
- Create a Publisher
- Create a Subscriber
- Useful ROS 2 Commands
- Troubleshooting
- What to Learn Next
- Frequently Asked Questions
What is ROS 2?
ROS 2, or Robot Operating System 2, is an open-source software development framework used for building robotics applications.
Despite its name, ROS 2 is not a traditional operating system like Windows or Ubuntu. Instead, it provides libraries, tools, communication mechanisms and development frameworks that help developers build complex robotic systems.
ROS 2 can be used for autonomous mobile robots, robotic arms, drones, industrial robots, research platforms, simulations and many other robotic applications.
ROS 2 allows different components of a robot, such as sensors, cameras, motors, navigation software and artificial intelligence modules, to communicate with each other.
Why Should You Learn ROS 2?
ROS 2 is an important technology for students and professionals interested in robotics, autonomous systems and artificial intelligence.
ROS 2 can be used in:
- Autonomous Mobile Robots
- Robotic Arms
- Self-Driving Vehicles
- Drones
- Computer Vision
- SLAM and Navigation
- Industrial Automation
- Robot Simulation
- Research Projects
- AI-powered Robotics
ROS 2 Installation Requirements
This tutorial explains the installation of ROS 2 Jazzy on Ubuntu 24.04 LTS.
- Ubuntu 24.04 LTS
- 64-bit computer
- Stable internet connection
- At least 4 GB RAM recommended
- Sudo / administrator access
How to Install ROS 2 Jazzy on Ubuntu 24.04
Follow the steps below carefully. Open Ubuntu Terminal using:
Ctrl + Alt + T
Step 1 – Update Ubuntu
First update the Ubuntu package information and installed packages.
sudo apt update
sudo apt upgrade -y
Step 2 – Enable the Universe Repository
Install the repository management tools and enable the Universe repository.
sudo apt install software-properties-common -y
sudo add-apt-repository universe
Step 3 – Install Required Utilities
sudo apt install curl gnupg lsb-release -y
Step 4 – Add the ROS 2 Repository Key
Download the ROS repository key.
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key \
-o /usr/share/keyrings/ros-archive-keyring.gpg
Step 5 – Add the ROS 2 Repository
Add the ROS 2 package repository to Ubuntu.
echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] \
http://packages.ros.org/ros2/ubuntu \
$(. /etc/os-release && echo $UBUNTU_CODENAME) main" | \
sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
Step 6 – Update the Package Repository
sudo apt update
Step 7 – Install ROS 2 Desktop
For beginners, the Desktop installation provides a convenient collection of ROS 2 tools and commonly used packages.
sudo apt install ros-jazzy-desktop -y
Step 8 – Install ROS Development Tools
sudo apt install ros-dev-tools -y
The next step is to configure your environment and verify that ROS 2 is working correctly.
How to Verify ROS 2 Installation
After installation, load the ROS 2 environment:
source /opt/ros/jazzy/setup.bash
Now check whether the ROS 2 command is available:
ros2 --help
Automatically Source ROS 2
Normally, you need to source the ROS 2 environment whenever you open a new terminal.
You can automatically source ROS 2 by adding it to your Bash configuration.
echo "source /opt/ros/jazzy/setup.bash" >> ~/.bashrc
Reload the configuration:
source ~/.bashrc
Now new terminal windows will automatically load the ROS 2 environment.
Run Your First ROS 2 Demo
ROS 2 includes example nodes that allow you to test communication between ROS 2 processes.
Terminal 1 – Start the Talker
ros2 run demo_nodes_cpp talker
Terminal 2 – Start the Listener
ros2 run demo_nodes_py listener
The talker publishes messages while the listener receives them. If messages are continuously displayed in the listener terminal, ROS 2 communication is working.
What is a ROS 2 Node?
A node is a process that performs a specific task within a ROS 2 system.
A complex robot usually contains multiple nodes.
For example:
- Camera node
- LiDAR node
- Motor controller node
- Navigation node
- Object detection node
- Robot state node
To see currently running nodes:
ros2 node list
What is a ROS 2 Topic?
A topic is a communication channel through which ROS 2 nodes exchange messages.
A publisher sends data to a topic while a subscriber receives data from that topic.
List Available Topics
ros2 topic list
View Topic Information
ros2 topic info /topic_name
View Messages
ros2 topic echo /topic_name
How to Create a ROS 2 Workspace
A workspace is a directory where you develop and build your own ROS 2 packages.
Step 1 – Create the Workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
The src directory is where your ROS 2 packages
will normally be created.
Create Your First ROS 2 Package
ROS 2 applications are usually organized into packages.
Step 1 – Go to the Source Directory
cd ~/ros2_ws/src
Step 2 – Create a Python Package
ros2 pkg create --build-type ament_python --dependencies rclpy std_msgs my_first_package
Step 3 – Return to the Workspace
cd ~/ros2_ws
Step 4 – Build the Workspace
colcon build
Step 5 – Source the Workspace
source install/setup.bash
Create a Simple ROS 2 Publisher
A publisher sends messages to a ROS 2 topic. In this example, we will create a Python node that publishes Hello from ROS 2! every second.
Step 1 – Navigate to the Package
cd ~/ros2_ws/src/my_first_package/my_first_package
Step 2 – Create the Python File
nano publisher.py
Step 3 – Add the Publisher Code
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class PublisherNode(Node):
def __init__(self):
super().__init__('simple_publisher')
self.publisher = self.create_publisher(
String,
'chatter',
10
)
self.timer = self.create_timer(
1.0,
self.publish_message
)
def publish_message(self):
message = String()
message.data = 'Hello from ROS 2!'
self.publisher.publish(message)
self.get_logger().info(
'Publishing: "%s"' % message.data
)
def main(args=None):
rclpy.init(args=args)
node = PublisherNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Save the file and exit the editor.
Create a Simple ROS 2 Subscriber
A subscriber receives messages from a ROS 2 topic.
Step 1 – Create the Subscriber File
cd ~/ros2_ws/src/my_first_package/my_first_package
nano subscriber.py
Step 2 – Add the Subscriber Code
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class SubscriberNode(Node):
def __init__(self):
super().__init__('simple_subscriber')
self.subscription = self.create_subscription(
String,
'chatter',
self.listener_callback,
10
)
def listener_callback(self, message):
self.get_logger().info(
'Received: "%s"' % message.data
)
def main(args=None):
rclpy.init(args=args)
node = SubscriberNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Configure the Python Package
To run the Python nodes using the ros2 run command,
add executable entry points to the package's
setup.py file.
Open setup.py
cd ~/ros2_ws/src/my_first_package
nano setup.py
Find the entry_points section and configure it like this:
entry_points={
'console_scripts': [
'publisher = my_first_package.publisher:main',
'subscriber = my_first_package.subscriber:main',
],
},
Save the file and rebuild your workspace.
cd ~/ros2_ws
colcon build
source install/setup.bash
Run Your Publisher
Open a terminal and source the workspace.
cd ~/ros2_ws
source install/setup.bash
ros2 run my_first_package publisher
You should see messages similar to:
Publishing: "Hello from ROS 2!"
Run Your Subscriber
Open another terminal.
cd ~/ros2_ws
source install/setup.bash
ros2 run my_first_package subscriber
The subscriber should receive:
Received: "Hello from ROS 2!"
Useful ROS 2 Commands for Beginners
ROS 2 Help
ros2 --help
List Nodes
ros2 node list
List Topics
ros2 topic list
View Topic Messages
ros2 topic echo /chatter
List Packages
ros2 pkg list
Build Workspace
colcon build
Source ROS 2
source /opt/ros/jazzy/setup.bash
Source Workspace
source install/setup.bash
Common ROS 2 Problems and Solutions
Problem 1 – ros2: command not found
If Ubuntu says that the ros2 command cannot be found,
source the ROS 2 environment.
source /opt/ros/jazzy/setup.bash
Problem 2 – colcon: command not found
Install the ROS development tools.
sudo apt install ros-dev-tools -y
Problem 3 – Package Cannot Be Found
Update the Ubuntu package repository.
sudo apt update
Also make sure that the Ubuntu version and ROS 2 distribution are compatible.
Problem 4 – ROS 2 Environment Disappears
Add the ROS 2 environment to your Bash configuration.
echo "source /opt/ros/jazzy/setup.bash" >> ~/.bashrc
source ~/.bashrc
Problem 5 – Publisher and Subscriber Do Not Communicate
Make sure both terminals have the ROS 2 environment sourced.
source /opt/ros/jazzy/setup.bash
source ~/ros2_ws/install/setup.bash
Also verify that both nodes are using the same topic name.
What Should You Learn After Installing ROS 2?
Installing ROS 2 is only the beginning. Once you understand the basic concepts, you can move toward more advanced robotics development.
- ROS 2 Nodes
- Topics
- Services
- Actions
- Parameters
- Launch Files
- ROS 2 Packages
- Python and C++
- TF2
- URDF
- RViz
- Gazebo Simulation
- SLAM
- Navigation
- ROS 2 Control
- Real Robot Integration
Installation → Nodes → Topics → Services → Packages → Python/C++ → URDF → RViz → Simulation → SLAM → Navigation → Real Robot
ROS 2 Beginner Concepts
| Concept | Purpose |
|---|---|
| Node | Performs a specific task |
| Topic | Allows nodes to exchange messages |
| Publisher | Sends messages |
| Subscriber | Receives messages |
| Service | Request and response communication |
| Action | Long-running tasks with feedback |
| Package | Organizes ROS 2 software |
| Workspace | Development and build environment |
Frequently Asked Questions
What is ROS 2?
ROS 2 is an open-source software development framework designed for robotics applications. It provides tools and communication mechanisms that allow different components of a robotic system to work together.
Is ROS 2 an operating system?
No. ROS 2 is not a traditional operating system. It is a robotics software development framework that runs on operating systems such as Ubuntu Linux.
Which Ubuntu version is used in this tutorial?
This tutorial uses Ubuntu 24.04 LTS with ROS 2 Jazzy.
Is ROS 2 free?
ROS 2 is open-source software and can be used for robotics development without purchasing a traditional software license.
Can beginners learn ROS 2?
Yes. ROS 2 can initially seem complicated because it introduces concepts such as nodes, topics, services, actions and packages. Starting with simple publisher and subscriber examples makes learning easier.
Can ROS 2 be used for real robots?
Yes. ROS 2 can be used for robotics research, simulation, prototyping and real robotic systems.
Can ROS 2 run on Windows and macOS?
ROS 2 supports multiple operating systems, although the installation process and level of support can vary depending on the ROS 2 distribution and platform.
Final Thoughts
ROS 2 is a powerful framework for robotics development and is an excellent technology to learn if you are interested in autonomous robots, artificial intelligence, computer vision or robotic systems.
The best way to learn ROS 2 is through hands-on projects. Start with nodes and topics, then gradually move toward sensors, simulation, navigation and real robot integration.