Installing ROS 2 Galactic on Ubuntu

This tutorial will focus on installing Galactic Geochelone on Ubuntu Focal.
Though it’s possible to install ROS 2 from source or archive, the easiest way to get ROS running on your Ubuntu machine is to install its corresponding Debian packages using apt
, a command line utility for installing and managing packages on Linux distributions.
In this tutorial, we’ll walk you through installing the Debian packages for ROS 2 Galactic Geochelone on Ubuntu Focal (20.04.4 LTS). If you are on Ubuntu Jammy (22.04 LTS), the latest LTS release, you can opt for ROS 2’s Rolling Ridley or Humble Hawksbill release instead.
Set up a UTF-8 system locale
Before installing anything, you’ll need to make sure your system locale supports UTF-8. Locale issues can cause unexpected problems further down the line, when using various ROS tools and libraries.
Run $ locale
in a terminal window to view your currently installed locale – if UTF-8 appears in the listed output, you’re all set!
Otherwise, you'll need to set up your locale in one of two ways – choose a locale on your system or generate a new one.
Show more info.
Set up your source repos
Ubuntu programs are stored in repositories that make installing new software easy and secure. Ubuntu’s four main repositories are as follows:
- Main (Canonical-supported open-source software)
- Universe (community-maintained open source software)
- Restricted (proprietary device drivers)
- Multiverse (proprietary software)
For the purposes of installing ROS, we need to enable the Ubuntu Universe repository:
$ sudo apt install software-properties-common
$ sudo add-apt-repository universe
Now you can add the ROS 2 repository to your system. Authorize the public GPG (GNU Privacy Guard) key provided by ROS, then add the ROS 2 repository to your sources list:
$ sudo apt update && sudo apt install curl gnupg lsb-release
$ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
Install ROS 2 packages
Install your ROS 2 Galactic desktop setup with the following commands:
$ sudo apt update # update your apt repo caches
$ sudo apt install ros-galactic-desktop
This will install a few different components like the core ROS libraries, developer tools like RViz, and a set of beginner-friendly tutorials and demos to help you get started.
Show more info.
Source your setup file
Typically, you would need to source your setup file every time you open a terminal to use ROS:
$ source /opt/ros/galactic/setup.bash
To save yourself the time, you can automatically trigger this step every time you launch a new shell. Run the following commands if you’re using a bash
shell:
echo "source /opt/ros/galactic/setup.bash" >> ~/.bashrc
source ~/.bashrc
Run the following commands if you’re using a zsh
shell:
echo "source /opt/ros/galactic/setup.zsh" >> ~/.zshrc
source ~/.zshrc
Run some examples
After completing the desktop install, let’s make sure that our APIs are working properly.
**Run the example C++ talker **at /opt/ros/galactic/lib/demo_nodes_cpp/talker
:
$ ros2 run demo_nodes_cpp talker
The output should confirm that the talker is successfully publishing messages:
[INFO] [1652382860.246687611] [talker]: Publishing: 'Hello World: 1'
[INFO] [1652382861.250208871] [talker]: Publishing: 'Hello World: 2'
[INFO] [1652382862.246508551] [talker]: Publishing: 'Hello World: 3'
...
In another terminal window, **run the example Python listener **at /opt/ros/galactic/lib/demo_nodes_py/listener
:
$ ros2 run demo_nodes_py listener
The output should confirm that the listener is hearing the published messages:
[INFO] [1652382936.495044030] [listener]: I heard: [Hello World: 1]
[INFO] [1652382937.478216343] [listener]: I heard: [Hello World: 2]
[INFO] [1652382938.487370309] [listener]: I heard: [Hello World: 3]
...
Both the C++ and Python APIs are working properly!
NOTE: If you’re experiencing issues here, make sure that you’ve enabled multicast – the network interface needs this in order to communicate via DDS.
Run the following commands in two separate terminal windows:
$ ros2 multicast receive
$ ros2 multicast send
If the first command does not return a successful output (i.e. Received from xx.xxx.xxx.xx:43751: 'Hello World!'
), try updating your firewall configuration:
$ sudo ufw allow in proto udp to 224.0.0.0/4
$ sudo ufw allow in proto udp from 224.0.0.0/4
Then, restart your terminal and try starting up your talker and listener again.
What’s next
Continue with the official ROS 2 tutorials to configure your environment, record data, and create a workspace and packages.
To uninstall ROS 2, remove the repository from your system completely:
$ sudo apt remove ~nros-galactic-desktop && sudo apt autoremove
$ sudo rm /etc/apt/sources.list.d/ros2.list
$ sudo apt update
$ sudo apt autoremove
$ sudo apt upgrade # for previously shadowed packages
Visualize and analyze your data with Foxglove
Once you’ve gotten the lay of the land and started recording your robots’ data, you’ll need to start visualizing your data to understand what’s going on under the hood of your robots.
This would be a good time to check out the specs for the MCAP file format. Not only are MCAP files smaller (and more performant!) than standard ROS 2 files, they’re also completely self-contained (unlike ROS 2 files that draw from message definitions living on your hard drive), making it possible for you to share these files with teammates for them to visualize. By adhering to a common container format, the MCAP file format encourages interoperability among third-party developer tools like Foxglove Studio and Foxglove Data Platform.
Foxglove provides a convenient mcap
CLI tool to help you convert your ROS 2 (.db3) files into MCAP (.mcap) files. These files can then be imported directly into Foxglove Data Platform, so your whole team can collaborate on organizing and tagging your data:
They can also be dragged-and-dropped into Foxglove Studio for instant rich visualizations. Load up your data to view camera images, display 3D markers, review log messages, and more:
Join the Foxglove Slack community to ask questions and learn more.
Additional resources
- ROS 2 Galactic docs and tutorials
- Ubuntu repositories
- ROS 2 distribution variants
- MCAP file format
- Foxglove Studio docs
- Foxglove Data Platform docs
Read more:
Using the MCAP C++ writer to record robotics data.

What we can expect from the Fourth Industrial Revolution.

Get blog posts sent directly to your inbox.