ubuntu 20.04 humble安装
时间: 2025-06-12 12:48:45 浏览: 27
### 在 Ubuntu 20.04 上安装 ROS 2 Humble 的方法
在 Ubuntu 20.04 上安装 ROS 2 Humble 需要进行源码编译,因为官方二进制包不支持此操作系统版本。以下是详细的安装指南。
#### 系统准备
确保系统编码为 UTF-8,这是 ROS 2 的运行要求。如果系统未设置为 UTF-8,则需要执行以下命令进行配置:
```bash
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
```
验证设置是否成功可以通过以下命令完成:
```bash
locale
```
若输出中包含 `en_US.UTF-8`,则说明配置正确[^1]。
#### Python 版本切换
Ubuntu 20.04 默认使用 Python 2.7,而 ROS 2 Humble 要求使用 Python 3.8 或更高版本。因此需要将系统默认的 Python 版本切换到 Python 3。可以使用以下命令完成版本切换:
```bash
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
sudo update-alternatives --config python
```
选择 Python 3 作为默认版本后,需确保系统中安装了必要的 Python 工具和依赖项:
```bash
sudo apt install python3-pip python3-venv
pip3 install -U pip setuptools wheel
```
#### 安装依赖项
在开始编译之前,需要安装所有必需的依赖项。首先安装 `rosdep` 工具以自动解析依赖关系:
```bash
sudo apt update
sudo apt install -y curl gnupg2 lsb-release
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 $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update
sudo apt install -y rosdep
```
初始化并更新 `rosdep` 数据库:
```bash
sudo rosdep init
rosdep update
```
#### 下载源码
从 ROS 2 的官方仓库克隆 Humble 源码:
```bash
mkdir -p ~/ros2_humble/src
cd ~/ros2_humble
wget https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos
vcs import src < ros2.repos
```
#### 解决依赖项
使用 `rosdep` 解析并安装所有依赖项:
```bash
sudo rosdep install -i --from-path src --rosdistro humble -y --skip-keys "console_bridge fastcdr rti-connext-dds-6.0.1 urdfdom_headers"
```
#### 编译源码
使用 `colcon` 工具编译源码:
```bash
sudo apt install -y python3-colcon-common-extensions
colcon build --symlink-install --parallel-workers 8
```
编译完成后,设置环境变量以激活 ROS 2 Humble:
```bash
source ~/ros2_humble/install/setup.bash
```
#### 验证安装
验证 ROS 2 Humble 是否成功安装:
```bash
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_py listener
```
若两个节点能够正常通信,则说明安装成功[^2]。
### 注意事项
- 如果网络连接不稳定,可能导致依赖项下载失败。可以尝试使用国内镜像源加速下载。
- 编译过程中可能会遇到特定包的编译错误,建议查阅相关文档或社区支持。
---
阅读全文
相关推荐


















