1.设置 ROS 2 的软件包源
sudo apt update
sudo apt install -y curl gnupg2 lsb-release
2.添加ROS2源
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] https://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2.list'
3.安装ROS2
sudo apt update
sudo apt install -y ros-humble-desktop
注意:可能会报错https://packages.ros.org/ros2/ubuntu jammy InRelease
Certificate verification failed: The certificate is NOT trusted. The name in the certificate does not match the expected. Could not handshake: Error in the certificate verification
解决方法:
1)进入文件夹 : cd /etc/apt/sources.list.d
2)打开文件: sudo vim ros2.list
3)将https改为http 后保存。重新执行以上代码
4.设置环境变量
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
5.安装开发工具
sudo apt install -y python3-colcon-common-extensions
6.查看版本
echo $ROS_DISTRO
7.创建一个ros2工作区
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
colcon build
source install/setup.bash
8.运行一个示例
sudo apt-get install ros-humble-demo-nodes-cpp
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_cpp listener
参考:Ubuntu (source) — ROS 2 Documentation: Rolling documentation