Ubuntu20.04如何安装Ros2 humble
时间: 2025-07-10 15:30:22 浏览: 5
<think>我们参考了用户提供的多个引用内容,其中涉及在Ubuntu20.04上通过源码编译安装ROS2Humble版本的具体步骤。虽然用户要求的是安装指南,但根据引用内容,Ubuntu20.04官方并不直接支持Humble(官方支持Ubuntu22.04),所以只能通过源码编译安装。因此,我们将整合引用内容中的关键步骤,提供一份清晰的安装指南。关键步骤包括:1.系统配置(包括UTF-8编码设置)2.安装必要工具和依赖3.设置Python版本(需要Python3.8)4.下载ROS2Humble源码5.安装依赖6.编译源码7.设置环境变量注意:引用[3]和[4]中提到了设置UTF-8编码和切换Python版本,这是重要的前置条件。下面我们将详细说明安装步骤:</think>
### Ubuntu 20.04 安装 ROS 2 Humble 指南(源码编译版)
由于 Ubuntu 20.04 (Focal) 官方未提供 Humble 的二进制包,必须通过源码编译安装。以下是完整安装流程:
#### 📝 准备工作
1. **系统更新**
```bash
sudo apt update && sudo apt upgrade
```
2. **设置UTF-8编码**(避免编译错误)[^3]
```bash
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
```
3. **安装基础工具**
```bash
sudo apt install build-essential git software-properties-common curl
```
#### 🐍 Python 环境配置
```bash
# 添加Python 3.8支持(若未安装)
sudo apt install python3.8 python3-dev python3-pip
# 设置Python 3为默认[^4]
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
python --version # 验证应为Python 3.x
```
#### 📦 安装依赖
```bash
# 安装开发依赖工具
sudo apt install libssl-dev libncurses5-dev libgl1-mesa-dev libopencv-dev
# 安装ROS 2基础依赖
sudo apt install libtinyxml2-dev libcunit1-dev libpoco-dev
```
#### 🔧 源码编译安装
```bash
# 创建工作空间
mkdir -p ~/ros2_humble/src
cd ~/ros2_humble
# 下载源码
git clone https://github.com/ros2/ros2.git src
cd src
git checkout humble
# 安装依赖
vcs import < ./ros2.repos
rosdep install --from-paths . --ignore-src -y
# 编译(耗时约1-2小时)
cd ~/ros2_humble
colcon build --symlink-install
```
#### 🌟 环境配置
```bash
echo "source ~/ros2_humble/install/setup.bash" >> ~/.bashrc
source ~/.bashrc
```
#### ✅ 验证安装
```bash
ros2 run demo_nodes_cpp talker & ros2 run demo_nodes_py listener
```
应看到节点间通信信息。
#### ⚠️ 注意事项
1. 编译过程需稳定网络(约1-3GB下载量)
2. 如遇依赖问题使用`rosdep install --ignore-src -y --from-paths .`修复[^2]
3. 可使用`export MAKEFLAGS="-j$(nproc)"`加速编译
阅读全文
相关推荐


















