Install ROS2 Galactic for Ubuntu 20.04


I wrote a manual about installing ROS 2E under Ubuntu 20.04 before. I'm going to use Moveit2 recently. I found that I still need to upgrade to Fox Fitzroy. I've seen that the latest one has arrived at Galactic Geochelone, so I'll record the process of installing ROS 2 Galactic Geochelone under Ubuntu 20.04. Because there are many holes in the installation process of ROS 2 in China, I'll record it to help you avoid them.

Official process

ROS 2 Documentation: Galactic1

preparation

Magic tools

As we all know, all kinds of downloads in China are not smooth, so the first thing is to prepare magic tools. Trojan-Qt5, you can refer to another blog post Trojan-Qt5 under Linux system and the use of terminal Internet access. 2

Replace domestic sources

Ubuntu 20.04 supports the graphical interface to directly change the source, which is much easier to operate. Basic reference links: Implementation method of replacing domestic source with Ubuntu 20.04 apt. 3

After setting up the software source, we can greatly speed up the installation of apt updates.

Installation premise

system requirements

According to the official requirements
Ubuntu Linux - Focal Fossa (20.04)

Installation selection

There are three ways to install ROS2F on Ubuntu

  • Binary package
    • Debian packages
    • "fat" archive
  • Source code compilation

Since I don't need to modify the source code of ROS2 at present, I'm just in the use stage, so I use the simplest Debian packages to install it.

Installation process

Language locale

The official requirement is to confirm the support of UTF-8. Although it doesn't seem necessary, just confirm it.
Especially when used in the docker container, the locale is often minimized to POSIX.

locale  # check for UTF-8

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

locale  # verify settings

The operation results are as follows

TWR:~$ locale  # check for UTF-8
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=
TWR:~$ sudo apt update && sudo apt install locales
Get:1 http://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Hit:2 http://mirrors.ustc.edu.cn/ubuntu focal InRelease
Get:3 http://mirrors.ustc.edu.cn/ubuntu focal-updates InRelease [114 kB]
Get:4 http://mirrors.ustc.edu.cn/ubuntu focal-backports InRelease [101 kB]
Get:5 http://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,101 B]
Get:6 http://mirrors.ustc.edu.cn/ubuntu focal-security InRelease [114 kB]
Get:7 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main amd64 Packages [1,031 kB]
Get:8 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main i386 Packages [490 kB]
Get:9 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main Translation-en [229 kB]
Get:10 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main amd64 DEP-11 Metadata [283 kB]
Get:11 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main amd64 c-n-f Metadata[13.5 kB]
Get:12 http://mirrors.ustc.edu.cn/ubuntu focal-updates/restricted amd64 Packages[272 kB]
Get:13 http://mirrors.ustc.edu.cn/ubuntu focal-updates/restricted Translation-en[39.5 kB]
Get:14 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe i386 Packages [576 kB]
Get:15 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe amd64 Packages [781 kB]
Hit:16 http://ppa.launchpad.net/appimagelauncher-team/stable/ubuntu focal InRelease
Get:17 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe Translation-en [170 kB]
Get:18 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe amd64 DEP-11 Metadata [330 kB]
Get:19 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe DEP-11 48x48 Icons [203 kB]
Get:20 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe amd64 c-n-f Metadata [17.7 kB]
Get:21 http://mirrors.ustc.edu.cn/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
Get:22 http://mirrors.ustc.edu.cn/ubuntu focal-backports/universe amd64 DEP-11 Metadata [1,768 B]
Get:23 http://mirrors.ustc.edu.cn/ubuntu focal-security/main amd64 DEP-11 Metadata [24.4 kB]
Get:24 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe i386 Packages [462 kB]
Get:25 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe amd64 Packages  [588 kB]
Get:26 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe Translation-en [95.2 kB]
Get:27 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe amd64 DEP-11 Metadata [58.3 kB]
Get:28 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe amd64 c-n-f Metadata [11.5 kB]
Get:29 http://mirrors.ustc.edu.cn/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,468 B]
Fetched 6,014 kB in 2s (3,864 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
locales is already the newest version (2.31-0ubuntu9.3).
locales set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
TWR:~$ sudo locale-gen en_US en_US.UTF-8
Generating locales (this might take a while)...
  en_US.ISO-8859-1... done
  en_US.UTF-8... done
Generation complete.
TWR:~$ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
TWR:~$ export LANG=en_US.UTF-8
TWR:~$ locale  # verify settings
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=

Set source

1. Confirm Ubuntu Universe warehouse
We need to add our ROS2 apt software warehouse to the system and run the following command to confirm that the Ubuntu Universe warehouse is enabled.

TWR:~$ apt-cache policy | grep universe
 500 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe i386 Packages
     release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=i386
 500 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe amd64 Packages
     release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=amd64
 100 http://mirrors.ustc.edu.cn/ubuntu focal-backports/universe i386 Packages
     release v=20.04,o=Ubuntu,a=focal-backports,n=focal,l=Ubuntu,c=universe,b=i386
 100 http://mirrors.ustc.edu.cn/ubuntu focal-backports/universe amd64 Packages
     release v=20.04,o=Ubuntu,a=focal-backports,n=focal,l=Ubuntu,c=universe,b=amd64
 500 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe i386 Packages
     release v=20.04,o=Ubuntu,a=focal-updates,n=focal,l=Ubuntu,c=universe,b=i386
 500 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe amd64 Packages
     release v=20.04,o=Ubuntu,a=focal-updates,n=focal,l=Ubuntu,c=universe,b=amd64
 500 http://mirrors.ustc.edu.cn/ubuntu focal/universe i386 Packages
     release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=i386
 500 http://mirrors.ustc.edu.cn/ubuntu focal/universe amd64 Packages
     release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=amd64

Due to the replacement of Tsinghua's domestic source, we can see it in the operation results

 500 http://mirrors.ustc.edu.cn/ubuntu focal/universe amd64 Packages
     release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=amd64

Here is the address of the source

http://mirrors.ustc.edu.cn/ubuntu

It may be inconsistent according to different settings. As long as you confirm that there are focal / universal AMD64 packages, it indicates that the setting has been successful. If you don't see it, go to step 2 to set the Universe warehouse.

2. Set up Ubuntu Universe warehouse
Execute the following command:

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

The results are as follows:

TWR:~$ sudo apt install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (0.98.9.5).
software-properties-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
TWR:~$ sudo add-apt-repository universe
'universe' distribution component is already enabled for all sources.

3. Add ROS 2 apt software warehouse

  1. We need to add our ROS2 apt software warehouse to the system.
    First, verify our GPG key
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
  1. Add the warehouse to our software source
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
  1. The implementation results are as follows
TWR:~$ sudo apt update && sudo apt install curl gnupg lsb-release
Hit:1 http://mirrors.ustc.edu.cn/ubuntu focal InRelease
Hit:2 http://mirrors.ustc.edu.cn/ubuntu focal-updates InRelease
Hit:3 http://mirrors.ustc.edu.cn/ubuntu focal-backports InRelease
Hit:4 http://mirrors.ustc.edu.cn/ubuntu focal-security InRelease
Hit:5 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:6 http://packages.ros.org/ros2/ubuntu focal InRelease
Hit:7 http://ppa.launchpad.net/appimagelauncher-team/stable/ubuntu focal InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
curl is already the newest version (7.68.0-1ubuntu2.5).
gnupg is already the newest version (2.2.19-3ubuntu2.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
TWR:~$ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key  -o /usr/share/keyrings/ros-archive-keyring.gpg
TWR:~$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

be careful:
If you execute it directly here, you may encounter raw githubusercontent. DNS pollution of com.

resolvent:

  1. Via IPAddress COM, you can find raw githubusercontent. The real IP address of COM is. *

  2. Via sudo vi /etc/hosts
    Add the binding of IP and domain name at the end of the hosts file.

***.***.**.*** raw.githubusercontent.com

Install ROS2 package

After setting the warehouse, update the cache of apt warehouse

sudo apt update

Desktop installation (recommended): including ROS, RViz, demos, tutorials

sudo apt install ros-galactic-desktop

ROS base installation (bare skeleton): communication library, message package, command line tool There are no GUI tools

sudo apt install ros-galactic-ros-base

A broken packages error occurred during execution

TWR:~$ sudo apt install ros-galactic-desktop
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-galactic-desktop : Depends: ros-galactic-action-tutorials-cpp but it is not going to be installed
                        Depends: ros-galactic-action-tutorials-interfaces but it is not going to be installed
                        Depends: ros-galactic-action-tutorials-py but it is not going to be installed
                        Depends: ros-galactic-composition but it is not going to be installed
                        Depends: ros-galactic-demo-nodes-cpp but it is not going to be installed
                        Depends: ros-galactic-demo-nodes-cpp-native but it is not going to be installed
                        Depends: ros-galactic-demo-nodes-py but it is not going to be installed
                        Depends: ros-galactic-depthimage-to-laserscan but it is not going to be installed
                        Depends: ros-galactic-dummy-map-server but it is not going to be installed
                        Depends: ros-galactic-dummy-robot-bringup but it is not going to be installed
                        Depends: ros-galactic-dummy-sensors but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-minimal-action-client but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-minimal-action-server but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-minimal-client but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-minimal-composition but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-minimal-publisher but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-minimal-service but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-minimal-subscriber but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-minimal-timer but it is not going to be installed
                        Depends: ros-galactic-examples-rclcpp-multithreaded-executor but it is not going to be installed
                        Depends: ros-galactic-examples-rclpy-executors but it is not going to be installed
                        Depends: ros-galactic-examples-rclpy-minimal-action-client but it is not going to be installed
                        Depends: ros-galactic-examples-rclpy-minimal-action-server but it is not going to be installed
                        Depends: ros-galactic-examples-rclpy-minimal-client but it is not going to be installed
                        Depends: ros-galactic-examples-rclpy-minimal-publisher but it is not going to be installed
                        Depends: ros-galactic-examples-rclpy-minimal-service but it is not going to be installed
                        Depends: ros-galactic-examples-rclpy-minimal-subscriber but it is not going to be installed
                        Depends: ros-galactic-image-tools but it is not going to be installed
                        Depends: ros-galactic-intra-process-demo but it is not going to be installed
                        Depends: ros-galactic-joy but it is not going to be installed
                        Depends: ros-galactic-lifecycle but it is not going to be installed
                        Depends: ros-galactic-logging-demo but it is not going to be installed
                        Depends: ros-galactic-pcl-conversions but it is not going to be installed
                        Depends: ros-galactic-pendulum-control but it is not going to be installed
                        Depends: ros-galactic-pendulum-msgs but it is not going to be installed
                        Depends: ros-galactic-quality-of-service-demo-cpp but it is not going to be installed
                        Depends: ros-galactic-quality-of-service-demo-py but it is not going to be installed
                        Depends: ros-galactic-ros-base but it is not going to be installed
                        Depends: ros-galactic-rqt-common-plugins but it is not going to be installed
                        Depends: ros-galactic-rviz-default-plugins but it is not going to be installed
                        Depends: ros-galactic-rviz2 but it is not going to be installed
                        Depends: ros-galactic-teleop-twist-joy but it is not going to be installed
                        Depends: ros-galactic-teleop-twist-keyboard but it is not going to be installed
                        Depends: ros-galactic-tlsf-cpp but it is not going to be installed
                        Depends: ros-galactic-topic-monitor but it is not going to be installed
                        Depends: ros-galactic-turtlesim but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
TWR:~$ sudo apt install ros-galactic-ros-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-galactic-ros-base : Depends: ros-galactic-geometry2 but it is not going to be installed
                         Depends: ros-galactic-robot-state-publisher but it is not going to be installed
                         Depends: ros-galactic-ros-core but it is not going to be installed
                         Depends: ros-galactic-rosbag2 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

be careful:
Try to repair one by one according to the dependency and find that there are projects that continue to depend on. This is not the way.
Checked around and found Solution to apt install package corruption4.

resolvent:
Mainly speaking, the apt install command is used instead of the apt install command, which is executed in the

sudo aptitude install ros-galactic-desktop

or

sudo aptitude install ros-galactic-ros-base

If there is no aptitude command in the system, first execute the following command to install Aptitude:

sudo apt-get install aptitude

The aptitude command, like the apt get command, is a package management tool in Linux.
But aptitude is better than apt in dealing with dependency issues.
For example, when aptitude deletes a package, it will delete the package it depends on at the same time. In this way, there will be no useless packages left in the system, and the whole system will be cleaner. It manages the software package through text operation menu and command.
Interested students can refer to aptitude command5.

Of course, in the process of resolving dependencies, there are some degradation requirements. You can read another blog post Install ROS package with aptitude instead of apt under Ubuntu 206.

Environment configuration

source /opt/ros/galactic/setup.bash

Validation example

In A terminal (A), run the configuration and start the C + + talker

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

In another terminal (B), run the configuration and start Python listener

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

Display in terminal A

TWR:~$ ros2 run demo_nodes_cpp talker
[INFO] [1623401499.188649472] [talker]: Publishing: 'Hello World: 1'
[INFO] [1623401500.188617681] [talker]: Publishing: 'Hello World: 2'
[INFO] [1623401501.188593316] [talker]: Publishing: 'Hello World: 3'
[INFO] [1623401502.188556101] [talker]: Publishing: 'Hello World: 4'
[INFO] [1623401503.188479541] [talker]: Publishing: 'Hello World: 5'
[INFO] [1623401504.188489280] [talker]: Publishing: 'Hello World: 6'
[INFO] [1623401505.188454974] [talker]: Publishing: 'Hello World: 7'
[INFO] [1623401506.188441022] [talker]: Publishing: 'Hello World: 8'
[INFO] [1623401507.188367939] [talker]: Publishing: 'Hello World: 9'
[INFO] [1623401508.188375095] [talker]: Publishing: 'Hello World: 10'
[INFO] [1623401509.188330276] [talker]: Publishing: 'Hello World: 11'
[INFO] [1623401510.188318712] [talker]: Publishing: 'Hello World: 12'
[INFO] [1623401511.188298142] [talker]: Publishing: 'Hello World: 13'
[INFO] [1623401512.188284017] [talker]: Publishing: 'Hello World: 14'
[INFO] [1623401513.188240477] [talker]: Publishing: 'Hello World: 15'
[INFO] [1623401514.188066415] [talker]: Publishing: 'Hello World: 16'
[INFO] [1623401515.188242309] [talker]: Publishing: 'Hello World: 17'
[INFO] [1623401516.188110920] [talker]: Publishing: 'Hello World: 18'
[INFO] [1623401517.188080784] [talker]: Publishing: 'Hello World: 19'
[INFO] [1623401518.188069913] [talker]: Publishing: 'Hello World: 20'
[INFO] [1623401519.187919954] [talker]: Publishing: 'Hello World: 21'
[INFO] [1623401520.188002262] [talker]: Publishing: 'Hello World: 22'
[INFO] [1623401521.187967031] [talker]: Publishing: 'Hello World: 23'
[INFO] [1623401522.187975595] [talker]: Publishing: 'Hello World: 24'
[INFO] [1623401523.188033320] [talker]: Publishing: 'Hello World: 25'
[INFO] [1623401524.187846522] [talker]: Publishing: 'Hello World: 26'
[INFO] [1623401525.187901371] [talker]: Publishing: 'Hello World: 27'
[INFO] [1623401526.187828211] [talker]: Publishing: 'Hello World: 28'
[INFO] [1623401527.187834611] [talker]: Publishing: 'Hello World: 29'
[INFO] [1623401528.187805688] [talker]: Publishing: 'Hello World: 30'
[INFO] [1623401529.187782235] [talker]: Publishing: 'Hello World: 31'
[INFO] [1623401530.187745137] [talker]: Publishing: 'Hello World: 32'
^C[INFO] [1623401530.710697371] [rclcpp]: signal_handler(signal_value=2)

Until you receive an interrupt from Ctrl^C

Display in terminal B

TWR:~$ ros2 run demo_nodes_py listener
[INFO] [1623401519.208580911] [listener]: I heard: [Hello World: 21]
[INFO] [1623401520.188769293] [listener]: I heard: [Hello World: 22]
[INFO] [1623401521.190202256] [listener]: I heard: [Hello World: 23]
[INFO] [1623401522.190453180] [listener]: I heard: [Hello World: 24]
[INFO] [1623401523.190435333] [listener]: I heard: [Hello World: 25]
[INFO] [1623401524.188595768] [listener]: I heard: [Hello World: 26]
[INFO] [1623401525.190340553] [listener]: I heard: [Hello World: 27]
[INFO] [1623401526.190241530] [listener]: I heard: [Hello World: 28]
[INFO] [1623401527.190022097] [listener]: I heard: [Hello World: 29]
[INFO] [1623401528.190283940] [listener]: I heard: [Hello World: 30]
[INFO] [1623401529.190121333] [listener]: I heard: [Hello World: 31]
[INFO] [1623401530.190186865] [listener]: I heard: [Hello World: 32]

It's done~~~

reference resources

  • https://www.jb51.net/article/187442.htm
  1. https://docs.ros.org/en/galactic/Installation.html ↩︎

  2. https://blog.csdn.net/amuro_ray027/article/details/117789315. ↩︎

  3. https://www.jb51.net/article/187442.htm ↩︎

  4. https://askubuntu.com/questions/363200/e-unable-to-correct-problems-you-have-held-broken-packages ↩︎

  5. https://man.linuxde.net/aptitude ↩︎

  6. https://blog.csdn.net/amuro_ray027/article/details/117820800 ↩︎

Keywords: Python C++ Linux Ubuntu ROS

Added by zxiny_chin on Tue, 01 Feb 2022 05:05:00 +0200