在机器人开发领域,ROS2 Humble 是一个非常长期支持(LTS)的版本。虽然它官方原生支持 Ubuntu 22.04,但许多开发者由于环境限制,仍需在 Ubuntu 20.04 安装 ROS2 Humble。本文将通过详细的 Ubuntu 20.04 ROS2 Humble 教程,带你一步步完成 ROS2 Humble 源码编译,实现 ROS2 Humble source installation。
首先,我们需要确保 Ubuntu 20.04 系统是最新的,并设置好语言环境(Locale),防止字符编码问题导致编译失败。
sudo apt update && sudo apt install localessudo locale-gen en_US en_US.UTF-8sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8export LANG=en_US.UTF-8
我们需要添加 ROS2 的 apt 仓库来获取必要的构建工具和依赖库。
sudo apt install software-properties-commonsudo add-apt-repository universesudo apt update && sudo apt install curl -ysudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpgecho "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
ROS2 Humble 源码编译 需要大量的编译工具。请执行以下命令安装:
sudo apt update && sudo apt install -y \ build-essential cmake git python3-colcon-common-extensions \ python3-flake8 python3-pip python3-pytest-cov python3-rosdep \ python3-setuptools python3-vcstool wget
创建一个工作空间并获取 Humble 的源码:
mkdir -p ~/ros2_humble/srccd ~/ros2_humblevcs import src --input https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos# 初始化 rosdep 安装依赖sudo rosdep initrosdep updaterosdep install --from-paths src --ignore-src -y --rosdistro humble --skip-keys "fastrtps libopenssl-dev"
注意:在 Ubuntu 20.04 上,某些包可能由于版本不匹配需要跳过或手动解决。
这是 ROS2 Humble source installation 中最耗时的步骤。使用 colcon 工具进行编译:
cd ~/ros2_humblecolcon build --symlink-install
根据你的电脑性能,这可能需要 30 分钟到数小时不等。
编译完成后,激活环境并测试经典的 Talker/Listener 例子:
source ~/ros2_humble/install/setup.bash# 运行发布者ros2 run demo_nodes_cpp talker
如果看到 "Publishing: 'Hello World'",恭喜你!Ubuntu 20.04 安装 ROS2 Humble 大功告成。
总结: 虽然 Ubuntu 20.04 不是 Humble 的官方首选,但通过 Ubuntu 20.04 ROS2 Humble 教程 进行源码安装,依然可以让你享受到最新版 ROS2 的强大功能。
本文由主机测评网于2026-04-06发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://www.vpshk.cn/20260434196.html