How to Install ROS 2 and Gazebo on Ubuntu

Building and testing autonomous vehicle software for a real product is not a job to learn end-to-end from a random blog for sure. On the other hand, if you are looking for a mildly complicated weekend project to learn how to use some cool tools like ROS 2 and Gazebo, you are in the right place.

I’ll try to limit this guide to five-six posts but I will add lots of external links for you to check out depending on what direction you want to dive deeper. I will start with the development environment installation, then I will explain the basics like ROS nodes topics and services, then a bit of Gazebo to simulate the first non-autonomous car, then get some data from LiDAR and cameras, and finally use that data to navigate the vehicle autonomously.

Everything will happen in simulation environment but at the end I am planning to share some tips to get it working on real hardware. Maybe I can try to design and 3D print a very simple platform to get started with.

Let’s start by understanding ROS 2 and Gazebo. Here are the things you need to know about ROS 2:

  • ROS means Robot Operating System but it is not a full OS, it’s a framework. It includes lots of different tools to make robotics-related software development easier.
  • ROS versions are called distributions, they are installed on top of Linux distros. Each ROS distro has its own set of supported OS/version/CPU list. You can check them here: https://www.ros.org/reps/rep-2000.html
  • ROS has a special publish-subscribe structure that helps with the communication with different data sources, control logic and physical output. It also supports many off-the-shelf hardware.

Let’s quickly explain Gazebo too: Gazebo is a 3D simulation environment to simulate a robotic/autonomous system. You have “worlds” and “models”. A Gazebo world is a simulated environment to test your model (like a test track or a street for an autonomous vehicle). There are some worlds and models already distributed in Gazebo and you can create your own to test the specific system you are designing.

I will use Ubuntu 24.04 with ROS 2 Jazzy Jalisco. I strongly recommend you to use a recent Ubuntu LTS distro and check the supported ROS distro for it. I will use the official documentation to put together this guide. Here is the link to the page I am following: https://docs.ros.org/en/jazzy/Installation/Ubuntu-Install-Debs.html

I see that the ROS 2 documentation mentions something about supporting Windows. I would avoid using Windows for anything related to ROS. If you decide to use it, I can’t help you down to that dark road and I suspect that anyone can.

1. Ensure that your locale is UTF-8

You can check your locale by using the locale command on a terminal. Ensure that it’s UTF-8. If not you can set it as below:

sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

2. Add ROS 2 Package Repo to Your System

ROS 2 apt packages are not available on Ubuntu by default. We will add ROS 2 package repo source to the system to be able to install and update them.

Enable “universe repositories” and install curl:

sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y

Add the ROS 2 GPG key:

sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

Add the ROS package repository to the sources list:

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

Of course, fetch the new package list and upgrade your installed packages:

sudo apt update && sudo apt upgrade

3. Install ROS 2

I recommend using the “Desktop” edition because it includes the common tools and content that will be helpful to get started with ROS 2:

sudo apt install ros-jazzy-desktop

This will install hundreds of packages, go grab a coffee 🙂

4. Check the ROS Installation

Now you should have some content under /opt/ros:

The ros2 and other ROS-related commands will be available when you call the setup.bash (or .sh/.zsh depending on your shell).

Now we will open two terminals and run two nodes that are supposed to talk to each other. Run this on the first terminal (“talker”):

source /opt/ros/jazzy/setup.bash
ros2 run demo_nodes_cpp talker

And this on the second terminal (listener):

source /opt/ros/jazzy/setup.bash
ros2 run demo_nodes_py listener

You can see that the first “talker node” is publishing some data when I start it. It’s completely independent from any other nodes. When I start the other “listener node” I can capture the data it’s publishing. I started the listener after the seventh publish of the talker, therefore I have the data published after that point.

Also, if you pay attention to the node names, you can see that we can use Python and C++ nodes together. If you are trying to choose, my recommendation would be to use Python until you hit a performance bottleneck that requires C++ implementation of the high-performance node specifically. Unless you are a C++ expert of course.

5. Install Gazebo

This will install the default Gazebo version for your ROS version:

sudo apt-get install ros-${ROS_DISTRO}-ros-gz

Then call the setup again to refresh the ROS 2 commands:

source /opt/ros/jazzy/setup.bash

You can try the Gazebo installation by running the following command and see the Gazebo window:

gz sim

A small tip: If you encounter any crashes when you start a simulation try to switch to Xorg from Wayland and see if it helps.

6. (Optional) Driving a Prius in Gazebo

  • Select the “Prius on Sonoma Raceway” from the window above, and click run.
  • Find the Prius right behind the start line and right click to it: Follow Options > Follow
  • Scroll down on the right panel and switch to “Keyboard” tab.
  • Set forward maximum velocity to 20 m/s and yaw to 2 rad/s
  • Then click “Run the simulation” (the play button) under the “World Control” of the right panel

You can tweak the parameters and use WASD buttons to do some drifting in Sonoma by using Gazebo…

I will talk about ROS nodes and topics in the next post. Have fun!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *