This article records the process of installing ROS2 on the Ubuntu 22.04 virtual machine and the problems encountered.
1. Determine the Ubuntu and ROS versions
There is a version correspondence between Ubuntu and ROS2. For details, you can see this page on the official website:
REP 2000 – ROS 2 Releases and Target Platforms (ROS.org)
where the humble version of ROS2 (that is, the latest version as of early October 2022) requires As follows:
So the ROS2 version that should be installed on Ubuntu 22.04 is ros-humble-desktop
.
In addition, if the version number of Ubuntu has the word LTS (Long Term Support), it is a long-term support version, and you should give priority to this version when installing Ubuntu.
2. Configuration and installation
Official installation documentation link: Ubuntu (Debian) — ROS 2 Documentation: Humble documentation
2.1 Set the locale
The official case naturally uses the English locale, but according to the documentation, any locale that supports UTF-8 is fine.
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.2 Set Ubuntu software source
2.2.1 First confirm whether the Universe source has been enabled
Check with the following command:
apt-cache policy | grep universe
The return may have several lines, but should contain the following:
500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
release v=22.04,o=Ubuntu,a=jammy,n=jammy,l=Ubuntu,c=universe,b=amd64
If the above content is not included, enter the following command:
sudo apt install software-properties-common
sudo add-apt-repository universe
2.2.2 Add ROS 2 apt repository
a) Add certificate
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
If you encounter this step
Failed to connect to raw.githubusercontent.com
, please visit https://www.ipaddress.com website, enter: in the query boxraw.githubusercontent.com
and press Enter, and find the corresponding ipv4 address in it:
choose any one of these four IP addresses, usesudo vi /etc/hosts
the IP and the domain name are added to/etc/hosts
the file, as shown below:
b) Add ros repository
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
2.3 Install the ros2 package
sudo apt update
sudo apt upgrade
sudo apt install ros-humble-desktop
You may encounter the following errors:
Solution: Replace all: in "/etc/apt/sources.list"http://cn.archive.ubuntu.com/ubuntu
with available mirrors, such as Alibaba Cloud's:http://mirrors.aliyun.com/ubuntu/
. Then usesudo apt --fix-broken install
the command to repair the incomplete installation. For other mirror lists, please refer to the China section in Mirrors: Ubuntu .
The Desktop version (recommended) includes: ROS, RViz, demos, tutorials.
Veterans can install the base version.sudo apt install ros-humble-ros-base
The base version only includes Communication libraries, message packages, command line tools. GUI tools are not included.
2.4 Configure environment variables
source /opt/ros/humble/setup.bash
echo " source /opt/ros/humble/setup.bash" >> ~/.bashrc
3 tests
Open the first terminal and start a data publisher node:
ros2 run demo_nodes_cpp talker
You should see
Open a second terminal and start a data subscriber node:
ros2 run demo_nodes_py listener
You should see: