How to Install ROS 2 Iron on Ubuntu Linux

In this blog post, I will show you how to install ROS 2 Iron (the latest distribution of ROS 2) on Ubuntu.

You Will Need

In order to complete this tutorial, you will need:

Prerequisites

It is helpful if you’ve completed this tutorial on Linux fundamentals, but it is not required.

Set the Locale

The official steps for installing ROS are at this link at ROS.org, but I will walk you through the process below so that you can see what each step should look like. 

We will install ROS 2 Iron via Debian Packages.

The first thing we are going to do is to set the locale. You can understand what locale means at this link.  

Click the 9 dots on the bottom-left portion of the screen and search for the “Terminal” application.

1-click-9-dots

Open it.

Type this command inside a terminal window.

locale

The locale command is used to display or change the locale settings on a Linux system. A locale is a set of environmental variables that define the language, country, and character encoding settings. These settings are used by system libraries and locale-aware applications to determine how to display text, dates, times, and other information.

1-set-locale

Now type the following command:

sudo apt update && sudo apt install locales

“sudo apt update” updates the package index list, which is a database of all the software packages available for your Linux distribution.

“sudo apt install locales” installs the locales package, which provides support for different languages and regions.

Now type:

sudo locale-gen en_US en_US.UTF-8

The command “sudo locale-gen en_US en_US.UTF-8” generates locale definition files for the specified locales. Locale definition files are used by the system to generate locale data, which is used by programs to determine how to format text, dates, times, and other information.

In this case, the command is generating locale definition files for the English (United States) locale and the English (United States) UTF-8 locale. The UTF-8 locale is a special locale that supports the UTF-8 character encoding, which is the standard encoding for most languages.

Now type:

sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

The command above is updating the locale data for the English (United States) locale and the English (United States) UTF-8 locale. You typically need to run this command after you have changed the locale on your system. This will ensure that all of your programs are using the correct locale data.

Now type:

export LANG=en_US.UTF-8

Setting the LANG environment variable to en_US.UTF-8 will ensure that all of your programs are using the English (United States) UTF-8 locale. This is important for programs that need to display or process text in multiple languages.

Now we need to verify the settings by typing:

locale

Here is what you should see:

2-here-is-what-you-should-see-locale

Enable the Required Repositories

Let’s add the ROS 2 apt repository to our system. Open a terminal window, and type the following two commands:

sudo apt install software-properties-common
sudo add-apt-repository universe

The software-properties-common package provides a number of tools for managing software sources on Ubuntu and Debian systems. One of these tools is the add-apt-repository command, which is used to add new repositories to your system’s software sources.

The universe repository is a software repository that contains a wide variety of software packages, including many that are not included in the default Ubuntu and Debian repositories. Adding the universe repository to your system’s software sources will give you access to a wider selection of software to install.

Now we need to add the ROS 2 GPG key with apt.

The ROS 2 GPG key is a public key that is used to verify the authenticity of ROS 2 packages. It is used by the ROS 2 package manager (apt) to ensure that the packages you are installing are from a trusted source.

To add the ROS 2 GPG key, type these two commands:

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

Add the repository to your sources list (copy and paste all of this below):

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

Type the following command to install ROS 2 development tools.

sudo apt update && sudo apt install ros-dev-tools

The command sudo apt install ros-dev-tools installs the ROS development tools package on Ubuntu systems. This package contains a number of tools that are useful for developing ROS packages, including:

  • ament_cmake: A CMake-based build system for ROS packages.
  • ament_index: A tool for generating and managing ROS package indexes.
  • ament_lint: A tool for linting ROS packages.
  • ament_test: A tool for testing ROS packages.
  • ament_uncrustify: A tool for formatting ROS code according to the ROS coding style guide.

Now update the apt repository:

sudo apt update

Upgrade the packages on your system to make sure you have the newest versions.

sudo apt upgrade

Install ROS 2

Install ROS 2 Iron by opening a terminal window, and typing:

sudo apt install ros-iron-desktop

Some of the tools and resources included in the ROS Iron desktop package include:

  • The ROS desktop environment, which includes a number of tools for developing and using ROS, such as RViz2, and RQt.
  • A number of documentation resources, such as the ROS wiki and tutorials.

Set Up the Environment Variables

Add Iron to your bash file.

echo "source /opt/ros/iron/setup.bash" >> ~/.bashrc

You can verify it is added by typing:

gedit ~/.bashrc
3-gedit-bashrc

If you don’t have gedit installed, you can type:

sudo apt-get install gedit

Close the terminal window, and open a new one.

Type the following command to see what version of ROS you are using:

printenv ROS_DISTRO

Here is what you should see:

4-iron-ros-distro

You can also type:

env | grep ROS
5-env-grep-ros

Install some other useful packages:

sudo apt install -y python3-pip
pip3 install -U argcomplete
sudo apt-get install ros-$ROS_DISTRO-gazebo-ros-pkgs
sudo rosdep init
rosdep update

Test Your Installation

Open a terminal window, and type:

ros2 run demo_nodes_cpp talker
6-run-talker

Open another terminal window, and type:

ros2 run demo_nodes_py listener
7-run-listener

If your output looks like the images above, you have installed ROS 2 successfully. Yay!

That’s it! Keep building!

How to Install Ubuntu 22.04 Virtual Machine on a Windows PC

In this blog post, I will show you how to install Ubuntu 22.04, the latest version of the popular Linux distribution, as a virtual machine on a Windows PC using VMware Workstation Player.

Prerequisites

You have a Windows PC.

Download and Install Ubuntu on VirtualBox

Follow the instructions here to install Ubuntu on VirtualBox. I often use VirtualBox instead of VMWare due to rendering issues with Gazebo, the popular simulator for ROS 2 projects.

If you use VirtualBox, use about 12GB of memory, 50GB for the storage size, and 4 CPU Processors.

Also when you first start up the virtual machine, you are going to want to make sure your user has sudo privileges. Do this by typing the following commands:

whoami

The command above gets your username.

su -
sudo adduser [username] sudo

Replace [username] with your username.

reboot

Download and Install VMware Workstation Player

First, we need to download and install VMware Workstation Player.

Go to the VMware Workstation Player page and click “DOWNLOAD NOW”. You will find the link at the bottom of the page.

VMware Workstation Player is a free virtualization software that allows you to run multiple operating systems on a single computer. This can be useful for a variety of purposes, such as testing new software, running development environments, or learning about other operating systems.

Click on the downloaded file, and follow the prompts to install VMware Workstation Player.

Download the Ubuntu 22.04 ISO File

Now you need to go to this page, and download the Ubuntu 22.04 iso file. You will see a button that says “Download 22.04” or something similar.

You can download this iso file to wherever you would like on your computer.

An ISO file, also known as an ISO image, is a single file that contains an exact copy of the Ubuntu Linux 22.04 operating system.

Create a New Virtual Machine

Open VMware Workstation Player and click on “Create a New Virtual Machine.”

1-create-new-virtual-machine

Click the “Browse” button and locate the .iso image of Ubuntu 22.04 that you downloaded earlier.

2-browse-button

Click Next.

Enter the Full Name, Username, and Password, and then click Next.

3-full-name

Name the virtual machine and select where you would like to store it on your computer.

Click Next.

Choose a maximum disk size. I will use 50GB.

4-50gb

Select “Split virtual disk into multiple files”.

Click Next.

Stick with the default option of “Power on this virtual machine after creation.” Then click Finish.

Follow the on-screen instructions to install Ubuntu 22.04 on your virtual machine.

Once the installation is complete, exit your new Ubuntu 22.04 virtual machine.

Now go to the following folder: Go into the VMWare settings on the C drive (C:\Users\*****\Documents\Virtual Machines\(whatever you have named your virtual machine), and open the configurations file in Notepad.

4b-usb-settings

Change

usb.restrictions.defaultAllow = “FALSE”

To:

usb.restrictions.defaultAllow = “TRUE”

If that line isn’t there, add it at the bottom of the file.

Restart VMware Workstation Player.

On the left part of the panel, right-click on the name of the virtual machine, and click “Settings”.

On the Hardware tab, click Memory.

5-vm-settings

Change the settings so that you have more memory. I set mine to 16384 MB.

I also set the Processors to 4.

Click OK.

On the Hardware tab, click USB Controller.

Make sure “Show all USB input devices” is checked.

You can also put a checkmark in “Share Bluetooth devices with the virtual machine”.

Click on your Virtual Machine and click “Play virtual machine”.

6-play-virtual-machine
7-linux-virtual-machine-ubuntu-22

That’s it! Keep building!

How to Install Docker on Ubuntu

In this blog post, I will explain the step-by-step process for installing Docker on an Ubuntu Linux system. As a reference for you, here are the official instructions.

At the end, I will explain in detail how Docker is used in robotics.

Uninstall Old Versions of Docker

The first thing you need to do is to uninstall any outdated versions of Docker that might be lurking on your computer.

Open a terminal window, and type the following command:

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

You might get a message back saying that you have none of those packages installed. That is just fine.

Set Up the Apt Repository

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Install Docker

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-compose

Verify that Docker Installed

sudo service docker start
sudo docker run hello-world

Post-Installation Configuration

Here are some recommended steps to take after you have successfully installed Docker.

Create the docker group.

sudo groupadd docker

Add your user to the docker group.

sudo usermod -aG docker $USER

Reboot your computer.

sudo reboot

Or you could have activated changes to groups instead of rebooting:

newgrp docker

To test that you can run Docker without using “sudo”, type the following command:

docker run hello-world

Now configure Docker to start on boot:

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

You can stop this startup on boot at any time, by typing:

sudo systemctl disable docker.service
sudo systemctl disable containerd.service

Now you’re all set.

How is Docker Used in Robotics?

Docker is a tool that allows you to package your software, including all its dependencies, into a standalone unit called a “container.” You can then deploy this container on any machine that has Docker installed, regardless of the underlying computer that is being used.

Docker is used in robotics for a number of reasons, including:

  • Reproducibility: Docker containers allow you to create a reproducible development environment for your robotics project. This means that you can be confident that your project will run the same way on any machine that has Docker installed.
  • Portability: Docker containers are portable, meaning that they can be easily moved from one machine to another. This is useful for developing and deploying robotics applications on a variety of platforms, including embedded devices, cloud servers, and robots.
  • Scalability: Docker containers are lightweight and efficient, making them ideal for scaling robotics applications. You can easily start and stop multiple containers on a single machine, or deploy multiple containers across a cluster of machines.

Here are some specific examples of how Docker is used in robotics:

  • Developing and testing robotics software: Docker can be used to create isolated development environments for robotics software. This allows developers to work on different components of a robotics project in parallel, without worrying about conflicts with other dependencies. Docker can also be used to test robotics software on different platforms, without having to install all of the necessary dependencies on each platform.
  • Deploying robotics applications: Docker can be used to deploy robotics applications on a variety of platforms, including embedded devices, cloud servers, and robots. This makes it easy to scale robotics applications and deploy them to production environments.
  • Running ROS 2: Docker is often used to run ROS 2. You can find the official ROS 2 Docker repository here on DockerHub.

If you are looking to simplify your development and deployment of software on to robots, I highly recommend you learn Docker.

That’s it. Keep building!