ROS 2 Tutorial for Beginners ยท Part 1

Create Your First
Workspace & Package

Install ROS 2, understand terminal basics, and set up your very first ROS 2 workspace and Python package from scratch.

Satyarth Shree
Satyarth Shree
ROS 2 Jazzy Ubuntu 24.04 Python

What You'll Learn Today

This tutorial has been made for beginners who are just starting with ROS 2 and are entirely unaware of its features and functionalities. Let's dive in and explore what ROS 2 is and how it works.

๐Ÿ’ก To get the most out of this tutorial, use split-screen so you can read this blog and follow along simultaneously. If you have a phone, open this blog on your phone and use your laptop/PC to follow the instructions.

ROS 2 Distributions

Open this link: https://docs.ros.org/en/foxy/Releases.html. After you scroll down you will find a list of distributions as shown:

List of ROS 2 Distributions
โ†‘ List of available ROS 2 distributions โ€” green = currently supported

Among these, the distributions highlighted green are currently supported by the manufacturers. Some are supported for 5 years while others for shorter durations. It is always recommended to use a distribution with a longer support window so you can receive updates for longer.

If you scroll down you'll find a section titled "Future Distributions":

Future ROS 2 Distributions
โ†‘ Future distributions โ€” Jazzy Jalisco is supported until 2029

A distribution named Jazzy Jalisco is visible here. Released in 2024 with an EOL of 2029 โ€” the most recent long-term support distribution. This tutorial uses Jazzy as it's the most current and will remain relevant longer.

๐Ÿ“… If you're reading this after 2029, install the latest supported distribution of your time. The core ROS 2 fundamentals covered here remain stable across distributions.

Installing ROS 2 Jazzy

Open your browser and search "ROS2 Jazzy Documentation". The following result will appear:

ROS 2 Jazzy Documentation search result
โ†‘ Search result for ROS 2 Jazzy Documentation

Click the first link. The following documentation page will open:

ROS 2 Documentation page
โ†‘ ROS 2 official documentation homepage

Click on "Installation". The following page will open:

Installation page of official ROS 2 Documentation
โ†‘ Installation page โ€” showing options for different operating systems
Operating System Recommendation

Use Ubuntu Linux as it offers the best support, stability, and documentation for ROS 2 development. ROS 2 Jazzy requires specifically Ubuntu 24.04. If you're on Windows 11, dual-boot it. A recommended tutorial: youtube.com/watch?v=alFosqQ1ang

โธ Continue reading only after you have Ubuntu 24.04 set up.

Under the Installation heading, click on "Ubuntu Linux โ†’ deb packages":

Ubuntu deb packages Installation page
โ†‘ Ubuntu deb packages installation section

Scroll down to find a set of commands:

Set of commands for installation
โ†‘ Commands to install ROS 2 โ€” copy & paste these one by one

Open your terminal and copy-paste these commands one by one from start to finish. You'll also find a command to install development tools:

Command to install development tools
โ†‘ Development tools are optional but highly recommended

Finally, you'll see two installation options โ€” Desktop Install or Base Install:

Two different ways to install ROS 2
โ†‘ Always choose Desktop Install โ€” it includes simulation tools
โš ๏ธ Always go with Desktop Install. The Base Install will leave you without simulation tools needed later in the series.

Verifying Your Installation

After running all commands, set up the environment and verify:

source /opt/ros/jazzy/setup.bash
ros2

If you see the following output, ROS 2 is successfully installed:

usage: ros2 [-h] [--use-python-default-buffering] ...

ros2 is an extensible command-line tool for ROS 2.

Commands:
  action     Various action related sub-commands
  bag        Various rosbag related sub-commands
  component  Various component related sub-commands
  node       Various node related sub-commands
  pkg        Various package related sub-commands
  run        Run a package specific executable
  topic      Various topic related sub-commands
  ...
  Call `ros2 <command> -h` for more detailed usage.

If instead you see ros2: command not found โ€” the installation did not complete successfully.

Installing Supporting Tools

We also need VS Code and gedit (text editor) for this tutorial. Install them:

sudo snap install code --classic
sudo apt install gedit

Verify gedit by typing gedit โ€” a text editor window will open:

Gedit Interface
โ†‘ Gedit text editor โ€” if this opens, it's installed successfully

Close gedit and continue with the tutorial.


Understanding Basic Terminal Commands

โญ If you already know cd, ls, and mkdir, you can skip this section.

Before we learn ROS 2, we need to understand some basic Linux terminal commands. Close the current terminal and open a fresh one.

Creating Folders โ€” mkdir

Let's create a folder named my_first_folder:

mkdir my_first_folder

Open the Files app and you'll see the folder was created:

File explorer showing my_first_folder
โ†‘ The folder my_first_folder created in your home (root) directory
๐Ÿ“ When naming folders, avoid spaces. Use underscores (_) to separate words โ€” like my_first_folder.

Navigating Directories โ€” cd

To create a folder inside another folder, you first change your working directory using cd:

cd my_first_folder/

You'll see my_first_folder highlighted in the terminal prompt, confirming you're now inside it:

Terminal after cd command
โ†‘ Terminal prompt now shows you're inside my_first_folder

Now create a folder inside it:

mkdir folder_1
folder_1 inside my_first_folder
โ†‘ folder_1 created inside my_first_folder

To go back one directory level (back to root), use:

cd ..
Terminal after cd .. command
โ†‘ Back in the root/home directory

Now create a second folder at the root level:

Creating my_second_folder
โ†‘ Creating my_second_folder in root directory
my_second_folder in file explorer
โ†‘ Both my_first_folder and my_second_folder visible in Files

To visualize the folder hierarchy we've created:

Folder structure diagram
โ†‘ Visual hierarchy of our created folders

Listing Files โ€” ls

To view files inside your current directory from the terminal, type:

ls
ls command in root directory
โ†‘ ls lists all files and folders in the current working directory

Navigating into my_first_folder and using ls shows its contents:

ls inside my_first_folder
โ†‘ folder_1 is the only item inside my_first_folder
ls inside my_second_folder โ€” empty
โ†‘ my_second_folder is empty โ€” ls returns nothing

Command Summary

  • mkdir <name> โ€” Create a new folder
  • cd <folder>/ โ€” Enter a folder (change working directory)
  • cd .. โ€” Go one level back (to parent directory)
  • ls โ€” List all files and folders in the current directory

Creating a Workspace and Package in ROS 2

Close the current terminal and open a fresh one before continuing.

Setting Up the ROS 2 Environment

Before using ROS 2, you must source its environment every time you open a terminal:

source /opt/ros/jazzy/setup.bash

This is repetitive โ€” let's automate it. Open the .bashrc file with gedit:

gedit .bashrc
.bashrc file open in gedit
โ†‘ .bashrc is a script that runs automatically when you open a terminal

Scroll to the bottom and add the source command:

Adding source command to .bashrc
โ†‘ Add the source command at the end of .bashrc and save

Save the file, close gedit and the terminal. Open a new terminal and type ros2 โ€” it should work without manually sourcing. The ROS 2 environment is now automatically set up every time.

Creating the Workspace

First install the colcon build tool:

sudo apt update
sudo apt install python3-colcon-common-extensions

A ROS 2 workspace is a directory where packages and nodes are organized. Create one named ws_1:

mkdir ws_1
cd ws_1
mkdir src

Verify with ls to see the src folder was created:

src folder inside workspace
โ†‘ src folder created inside ws_1 workspace

Now build the workspace:

colcon build
colcon build output
โ†‘ Successful build output โ€” no errors

Run ls again. You'll see 3 new folders were auto-generated โ€” build, install, and log:

Workspace after colcon build
โ†‘ build, install, and log folders generated by colcon build

To use custom nodes from this workspace, you need to source it. Add this to .bashrc just like we did for ROS 2 itself:

cd ..
gedit .bashrc

Add at the end:

source ~/ws_1/install/setup.bash

Save and close. Now you won't have to source your workspace manually every session.

Creating a Package

Packages live inside the src folder of your workspace. Navigate there:

cd ws_1/src/

Running ls shows nothing โ€” the src folder is still empty:

Empty src folder
โ†‘ src folder is currently empty โ€” ready for our package

There are two types of packages: Python and C++. This tutorial creates a Python package named my_first_package:

ros2 pkg create my_first_package --build-type ament_python --dependencies rclpy
Package Command Breakdown
  • my_first_package โ€” name of your package
  • --build-type ament_python โ€” creates a Python package
  • --dependencies rclpy โ€” adds the ROS 2 Python client library
  • For C++: use --build-type ament_cmake --dependencies rclcpp
Creating a package command output
โ†‘ Package creation output โ€” a set of confirmation messages

Run ls and you'll see the package folder:

src folder after package creation
โ†‘ my_first_package now visible inside the src folder

The package isn't fully built yet. Move back to the workspace root and build:

cd ..
colcon build
colcon build after package creation
โ†‘ "Summary: 1 package finished" โ€” your package is built

Finally, verify the package was created successfully by navigating into it and running ls:

Files inside the package
โ†‘ Auto-generated files inside my_first_package confirm successful creation

The presence of auto-generated files and folders confirms the package was built successfully. You're ready for Part 2.


Up Next in This Series
Part 2 โ€” Create Your First ROS 2 Node
Read Part 2 โ†’

About The Publication: ROS Simplified

ROS Simplified is a learner-driven publication dedicated to making ROS (Robot Operating System) concepts clear, practical, and accessible. We provide tutorials, conceptual explainers, and project walkthroughs designed to help students, hobbyists, and engineers understand and apply ROS efficiently.

View the official page of ROS Simplified โ†’

Satyarth Shree
Satyarth Shree
BTech Robotics & Automation ยท Lovely Professional University, India

An aspiring robotics engineer publicly documenting his learning journey. Focused on ROS, Python, and mathematics. Founder of ROS Simplified โ€” a publication making ROS accessible to everyone through beginner-friendly, free tutorials.

Let's Connect