Ubuntu 22.04 安装 ROS 2 Humble 笔记

1. 前置条件

更新系统:

bash 复制代码
sudo apt update && sudo apt upgrade -y

安装工具:

bash 复制代码
sudo apt install -y software-properties-common curl gnupg lsb-release
  • software-properties-common → 管理 apt 源
  • curl → 命令行下载工具
  • gnupg → 导入签名用
  • lsb-release → 获取系统版本号(比如 jammy)

2. 添加 ROS 2 软件源

官方源(国外较慢)

bash 复制代码
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 $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

国内镜像(推荐 ARM / 国内环境)

例如:清华源

bash 复制代码
sudo curl -sSL https://mirrors.tuna.tsinghua.edu.cn/rosdistro/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] https://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

3. 更新索引

bash 复制代码
sudo apt update

4. 安装 ROS 2 Humble

桌面版(推荐,含 RViz、开发工具)

bash 复制代码
sudo apt install -y ros-humble-desktop

基础版(不含 GUI,仅通信框架)

bash 复制代码
sudo apt install -y ros-humble-ros-base

5. 环境配置

让 ROS 2 环境变量自动加载:

bash 复制代码
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc

Zsh 用户:

bash 复制代码
echo "source /opt/ros/humble/setup.zsh" >> ~/.zshrc

6. 测试安装

bash 复制代码
ros2 run demo_nodes_cpp talker

再开一个终端:

bash 复制代码
ros2 run demo_nodes_cpp listener

如果能看到消息输出,说明安装成功 🎉


7. 常见问题

  1. 下载失败 502 Bad Gateway

    • 切换到国内源(清华、中科大、阿里云)

    • 或者加 --fix-missing 再试:

      bash 复制代码
      sudo apt-get update --fix-missing
  2. 卡在 tzdata 配置

    • 安装时要求选择时区,选 Asia -> Shanghai

    • 或自动设置:

      bash 复制代码
      sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
      sudo dpkg-reconfigure -f noninteractive tzdata
  3. 环境变量没生效

    • 确认 source /opt/ros/humble/setup.bash 已加到 ~/.bashrc

8. 目录结构说明

ROS 2 默认安装在:

复制代码
/opt/ros/humble/

包含:

  • bin/ → 命令行工具(ros2、colcon 等)
  • include/ → 头文件
  • lib/ → 动态库
  • share/ → 配置与资源

9. ROS 2 Humble 简介

  • 名称:Humble Hawksbill(谦逊的鹰嘴海龟)
  • 类型:LTS(长期支持版)
  • 发布:2022.05
  • 支持至:2027.05
  • 匹配系统:Ubuntu 22.04 (Jammy)
  • 特点:稳定、长期维护,工业/科研推荐
相关推荐
何伯特7 天前
ROS与Conda的兼容性问题深度解析与解决方案
conda·ros
hhzz11 天前
利用Terraform格式模板文件创建和部署基本网络资源
阿里云·云原生·ros·terraform·资源编排
github5actions12 天前
ROS开发实战:如何用rviz文件保存和加载你的SLAM可视化配置(附避坑指南)
ros·slam·rviz·机器人开发
REDcker12 天前
DDS 协议详解
机器人·ros·ros2·dds
铁头七娃15 天前
Solidworks 2024 根据机器人装配体,生成urdf文件
机器人·ros·solidworks
三克的油16 天前
ros-day5
ros
元让_vincent19 天前
DailyCoding C++ CMake | CMake 踩坑记:解决 ROS 项目中的“循环引用”与库链接依赖问题
c++·机器人·ros·动态库·静态库·cmake·循环引用
元让_vincent20 天前
DaliyCoding C++ ROS | C++ 避坑指南:ROS 回调函数中的对象生命周期陷阱 (Use-After-Free)
开发语言·c++·机器人·ros·ros2
liuniu081821 天前
参数--parameters
ros
liuniu081821 天前
服务--services
ros