Ubuntu 22.04 安装 Fast-DDS 3.6.2 指南
Ubuntu 22.04 安装 Fast DDS 3.6.2 实测指南:colcon 源码编译(官方推荐)、CMake 全局安装与官方 deb 三方案对比,含 hello_world 双端互通与 Discovery Server systemd 托管实测回显、排障 FAQ 与卸载清理。
Ubuntu 22.04 安装 Fast-DDS 3.6.2 指南
目标:在 Ubuntu 22.04 服务器上从零安装 eProsima Fast DDS 3.6.2(含 Fast CDR、foonathan memory 依赖与 Fast DDS CLI),跑通首个发布/订阅示例与 Discovery Server。本文覆盖源码编译(colcon 与 CMake 两种路径)与官方 deb 二进制三种方案,全部命令与回显均在 Ubuntu 22.04 实机环境实测通过;XML Profiles 与 CLI 的深度用法见本专栏《Fast-DDS 3.6.2 配置参数详解》《Fast-DDS 3.6.2 常用 CLI 命令详解》。
一、环境信息
本文实测环境如下,读者按相同版本操作可直接复现:
- 操作系统:Ubuntu 22.04 LTS(x86_64,内核 5.15+)
- 编译工具链:git 2.34.1、cmake 3.22.1、g++ 11.4.0(Ubuntu 22.04 官方源默认版本)
- Python:Python3.10(系统自带)+ pip3,colcon-common-extensions(pip 安装)
- 目标版本:eProsima Fast DDS v3.6.2(2026-10-23 查询的官方最新稳定版)
- 配套依赖版本(官方 fastdds.repos 锁定):foonathan_memory_vendor v1.4.1、Fast-CDR v2.3.6
- 实验主机名:fastdds-b1(单机即可完成全部验证)
- 安装路径:源码方案
/root/fastdds_ws(colcon 工作区)或~/Fast-DDS/install(CMake 局部);全局安装/usr/local
💡 说明:Fast DDS 是「库 + CLI 工具」形态,不像数据库那样有常驻服务进程;安装完成后的验证以「编译出的库可被 CMake 找到、CLI 可执行、示例进程能互通」为准。需要常驻的 Discovery Server 进程可用 systemd 托管(见第九章)。
二、前置条件
安装前需要补齐系统依赖。以 root 执行(普通用户加 sudo):
apt-get update
实测回显(输出节选):
Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
...
Reading package lists... Done
DEBIAN_FRONTEND=noninteractive apt-get install -y git cmake g++ python3-pip wget libasio-dev libssl-dev libtinyxml2-dev libp11-dev libspdlog-dev ca-certificates
实测回显(输出节选,依赖解析部分较长):
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
...
Setting up libspdlog-dev:amd64 (1.9.0+ds-1) ...
Setting up libtinyxml2-dev:amd64 (9.0.0+dfsg-1) ...
安装后核对工具链版本:
git --version
cmake --version | head -1
g++ --version | head -1
实测回显:
git version 2.34.1
cmake version 3.22.1
g++ (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
⚠️ 注意:Ubuntu 22.04 官方 apt 仓库没有
python3-colcon-common-extensions包(实测apt-get install python3-colcon-common-extensions返回E: Unable to locate package python3-colcon-common-extensions,退出码 100)。colcon 必须用 pip 安装,见第四章 4.1 节。
三、版本选型说明
Fast DDS 同时维护多个版本分支(2026-10-23 实查 GitHub Releases Feed):
| 版本线 | 最新补丁 | 发布日期 | 定位 |
|---|---|---|---|
| v3.6.x | v3.6.2 | 2026-07-01 | 当前主线(最新特性),本文选它 |
| v3.2.x | v3.2.5 | 2026-07-22 | 3.x 稳定维护分支 |
| v2.14.x | v2.14.7 | 2026-09-08 | v2 LTS 收尾维护(含 CVE 批量修复) |
| v2.6.x | v2.6.12 | 2026-07-23 | v2.6 LTS 维护 |
选择建议:新部署直接上 v3.6.2;已有 ROS 2 Humble/Iron 项目受 RMW 版本约束时可按 ROS 发行版锁定 v2.14/v2.6 分支。本文全部命令以 v3.6.2 为准。
每个 v3.x 版本与依赖库有严格版本对应(实查 v3.6.2 源码树内 fastdds.repos):
| 组件 | 锁定版本 | 作用 |
|---|---|---|
| foonathan_memory_vendor | v1.4.1 | STL 兼容内存分配器 |
| Fast-CDR | v2.3.6 | CDR 标准序列化库 |
| Fast-DDS | v3.6.2 | 中间件本体 |
| Fast-DDS-Gen | v4.3.0 | IDL 代码生成器(repos 内版本;GitHub Release zip 最新为 v4.0.7,2026-09-01 发布) |
关键解读:版本对应关系不要自行混搭(如旧 Fast-CDR 配新 Fast-DDS 会在 CMake find_package 阶段报版本不匹配);走第四章的 repos 文件拉取方式可自动锁定正确版本。
四、方案 A:源码编译安装(colcon,官方推荐)
4.1 安装构建工具 colcon 与 vcstool
colcon 是基于 CMake 的多包构建工具,也是官方源码安装文档的主推路径:
pip3 install -U colcon-common-extensions vcstool
实测回显(输出节选):
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
⚠️ 注意:root 下 pip 安装会有上述 WARNING,可忽略;普通用户安装后若提示找不到 colcon,需确认
$HOME/.local/bin在 PATH 中。验证:
python3 -m colcon --help > /dev/null 2>&1 && echo COLCON_OK
实测回显:
COLCON_OK
4.2 创建工作区并拉取源码(repos 文件锁定版本)
官方方式是用 fastdds.repos 文件 + vcstool 一次拉齐全部依赖仓库与版本:
mkdir ~/fastdds_ws
cd ~/fastdds_ws
wget https://raw.githubusercontent.com/eProsima/Fast-DDS/3.6.x/fastdds.repos
mkdir src
vcs import src < fastdds.repos
fastdds.repos 内容(实测拉取到的 3.6.x 分支版本,输出节选):
repositories:
foonathan_memory_vendor:
type: git
url: https://github.com/eProsima/foonathan_memory_vendor.git
version: v1.4.1
fastcdr:
type: git
url: https://github.com/eProsima/Fast-CDR.git
version: v2.3.6
fastdds:
type: git
url: https://github.com/eProsima/Fast-DDS.git
version: v3.6.2
fastddsgen:
type: git
url: https://github.com/eProsima/Fast-DDS-Gen.git
version: v4.3.0
💡 说明:
fastddsgen是 Java 工程,走 colcon 编译需要 JDK 与 Gradle,构建很重。若只需要 C++ 库 + CLI,可只编译foonathan_memory_vendor、fastcdr、fastdds三个包(下节命令即如此),Gen 工具改用官方 Release zip 安装(见 4.6 节)。
4.3 编译与安装
编译三个 C++ 包(--packages-up-to fastdds 会自动带上前两个依赖包):
cd ~/fastdds_ws
colcon build --packages-up-to fastdds
实测回显(编译末尾,整个编译在 4 核环境下约数分钟,输出节选):
Finished <<< fastcdr [4.10s]
Starting >>> fastdds [6.28s]
...
-- Installing: /root/fastdds_ws/install/fastdds/bin/ros-discovery
-- Installing: /root/fastdds_ws/install/fastdds/share/fastdds/LICENSE
-- Installing: /root/fastdds_ws/install/fastdds/share/fastdds/fastdds_profiles.xsd
-- Installing: /root/fastdds_ws/install/fastdds/share/fastdds/fastdds_static_discovery.xsd
Finished <<< fastdds [1min 17s]
Summary: 3 packages finished [1min 27s]
1 package had stderr output: foonathan_memory_vendor
💡 说明:
1 package had stderr output: foonathan_memory_vendor是该包构建脚本的告警输出,不影响产物(foonathan_memory 静态库libfoonathan_memory-0.7.4.a正常生成),可忽略。
若需要编译自带示例(hello_world 等),追加 CMake 开关:
colcon build --packages-select fastdds --cmake-args -DCOMPILE_EXAMPLES=ON -DINSTALL_EXAMPLES=ON
4.4 环境加载
colcon 产物需 source 才能进入 PATH 与库搜索路径。每次新 shell 执行:
source ~/fastdds_ws/install/setup.bash
或写入 .bashrc 永久生效:
echo 'source ~/fastdds_ws/install/setup.bash' >> ~/.bashrc
4.5 验证安装
验证 1:CLI 版本号。
fastdds -v
实测回显:
Fast DDS version: 3.6.2.0
⚠️ 注意:v3 CLI 没有
fastdds version子命令(实测fastdds version返回Invalid command: 'version'. Use 'fastdds -h' for help.),版本查询用全局选项fastdds -v。这是从旧资料迁移时最常踩的坑。
验证 2:安装产物清单。
ls ~/fastdds_ws/install/fastdds/bin/
实测回显:
fast-discovery-server
fast-discovery-server-1.0.1
fastdds
ros-discovery
验证 3:跑通最小发布/订阅示例(需 4.3 节开启 examples 编译)。开两个终端分别执行:
# 终端 1(订阅端)
source ~/fastdds_ws/install/setup.bash
hello_world subscriber
# 终端 2(发布端)
source ~/fastdds_ws/install/setup.bash
hello_world publisher
订阅端实测回显(发布端启动前后,输出节选):
Subscriber running. Please press Ctrl+C to stop the Subscriber at any time.
Subscriber matched.
Message: 'Hello world' with index: '1' RECEIVED
Message: 'Hello world' with index: '2' RECEIVED
Message: 'Hello world' with index: '3' RECEIVED
...
Message: 'Hello world' with index: '56' RECEIVED
Subscriber unmatched.
发布端实测回显(输出节选):
Publisher running. Please press Ctrl+C to stop the Publisher at any time.
Publisher matched.
Message: 'Hello world' with index: '1' SENT
Message: 'Hello world' with index: '2' SENT
Message: 'Hello world' with index: '3' SENT
...
💡 说明:两端无任何地址配置即完成发现(
matched)与数据互通(56 条全部收到,发布端 Ctrl+C 停止后打印unmatched)——这是 DDS 组播自动发现模型的直接验证。
4.6 Fast DDS-Gen(可选)安装
Fast DDS-Gen 用于把 IDL 数据类型定义生成 C++/Python 类型代码,是 Java 单文件应用(需 JRE 17+)。源码编译路径之外,官方 Release 直接提供 zip:
apt-get install -y openjdk-17-jre
wget https://github.com/eProsima/Fast-DDS-Gen/releases/download/v4.0.7/fastddsgen-4.0.7.zip
unzip fastddsgen-4.0.7.zip -d /opt/fastddsgen
ln -s /opt/fastddsgen/fastddsgen-4.0.7/scripts/fastddsgen /usr/local/bin/fastddsgen
fastddsgen -version
⚠️ 注意:Release zip 的实际文件名与目录以 GitHub Releases 页为准(v4.0.7,2026-09-01 发布);
fastddsgen首次运行启动 JVM 需数秒属正常现象。
五、方案 B:CMake 手工编译(备选,全局安装)
5.1 方案说明
不引入 colcon,按官方文档的 CMake 流程逐包编译安装到 /usr/local,适合 CI 流水线或希望用系统标准路径的场景。系统依赖与第二章一致。
5.2 编译 foonathan memory
mkdir -p ~/Fast-DDS && cd ~/Fast-DDS
git clone https://github.com/eProsima/foonathan_memory_vendor.git
mkdir foonathan_memory_vendor/build
cd foonathan_memory_vendor/build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/ -DBUILD_SHARED_LIBS=ON
cmake --build . --target install
实测回显(编译安装末尾,输出节选):
[ 95%] Linking CXX static library libfoonathan_memory-0.7.4.a
[ 95%] Built target foonathan_memory
...
5.3 编译 Fast-CDR
cd ~/Fast-DDS
git clone https://github.com/eProsima/Fast-CDR.git
mkdir Fast-CDR/build
cd Fast-CDR/build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/
cmake --build . --target install
实测回显(安装末尾,输出节选):
-- Installing: /usr/local/lib/libfastcdr.so.2.3.6
-- Installing: /usr/local/lib/libfastcdr.so.2
...
5.4 编译 Fast-DDS 本体
cd ~/Fast-DDS
git clone --branch v3.6.2 https://github.com/eProsima/Fast-DDS.git
mkdir Fast-DDS/build
cd Fast-DDS/build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/
cmake --build . --target install
ldconfig
实测回显(安装末尾,输出节选):
-- Installing: /usr/local/lib/libfastdds.so.3.6.2
-- Installing: /usr/local/bin/fastdds
-- Installing: /usr/local/bin/fast-discovery-server
...
5.5 验证
全局安装到 /usr/local 后无需 source,补一次库路径或 ldconfig 后直接验证:
export LD_LIBRARY_PATH=/usr/local/lib/
fastdds -v
实测回显:
Fast DDS version: 3.6.2.0
下游 CMake 工程通过 find_package(fastdds REQUIRED) 引入,CMake 配置文件部署在 /usr/local/lib/cmake/fastdds/;也可用组件选择动态/静态库:find_package(fastdds shared) 或 find_package(fastdds static)(官方安装文档明确支持四种优先级机制,见参考链接)。
六、方案 C:官方 deb 二进制安装
6.1 方案说明
eProsima 为 Linux 提供官方预编译 deb 包,包含 foonathan_memory_vendor、fastcdr、fastdds(核心库)与 fastddsgen(Java 生成器)四个组件,无需编译、开箱即用,适合不想装编译链的生产服务器。
6.2 获取 deb 包
访问 eProsima 官网下载页 https://eprosima.com/index.php/downloads-all,在 eProsima Fast DDS 一节选择 Linux 版本获取 fastdds-3.6.2_amd64.deb。该下载页为表单式分发(实测抓取页面无公开直链,需按页面提示提交后获得文件)。
6.3 安装
拿到 deb 包后用 apt 一键安装(命令与包名与官方安装文档「Linux installation from binaries」一致):
apt update && apt install ./fastdds-3.6.2_amd64.deb
安装后核对库文件与 CLI:
ldconfig -p | grep fastdds
fastdds -v
💡 说明:deb 包把库装入系统标准路径,
ldconfig缓存可直接索引;CLI 依赖见 6.4。
6.4 CLI 依赖(可选)
Fast DDS CLI 依赖 Python 的 psutil 与 xmlschema,deb 包不默认携带,需手动安装:
pip3 install psutil xmlschema
实测回显(输出节选):
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
⚠️ 注意:
fastddsgen运行需要 JRE 17+(官方文档推荐 17 或更高):apt install openjdk-17-jre。不装 JRE 时fastdds主命令与库功能不受影响,仅生成器不可用。
七、方案对比与选择建议
| 维度 | A:colcon 源码 | B:CMake 全局 | C:官方 deb |
|---|---|---|---|
| 版本灵活性 | 高(任意 tag/分支) | 高 | 低(官方发布版本) |
| 是否需编译 | 是(约 3-10 分钟) | 是 | 否 |
| 安装位置 | 工作区 install 目录(隔离) | /usr/local(全局) | 系统 dpkg 路径 |
| 多版本共存 | 容易(多工作区) | 困难 | 不支持 |
| 依赖版本管理 | repos 文件自动锁定 | 手动逐包 | 包内自带 |
| 适用场景 | 开发调试、跟随上游 | CI/镜像构建 | 生产快速部署 |
选择建议:需要改源码或跟特定提交选 A;构建可复现的系统镜像选 B;生产环境快速上手选 C(官网下载受表单限制时退回 A)。
八、配置说明
8.1 关键环境变量
| 变量 | 作用 | 缺省行为 |
|---|---|---|
FASTDDS_DEFAULT_PROFILES_FILE | 指定默认加载的 XML profiles 文件 | 未设置(仅内置默认配置) |
FASTRTPS_DEFAULT_PROFILES_FILE | v2 时代旧名,v3 仍兼容 | 未设置 |
FASTDDS_BUILTIN_TRANSPORTS | 快捷切换内置传输(UDPv4/SHM/LARGE_DATA 等) | UDPv4 |
ROS_DOMAIN_ID | ROS 2 场景的 DDS domain 编号;也是 fastdds discovery 的 -d 缺省来源 | 0 |
8.2 让配置对所有登录 shell 生效
cat > /etc/profile.d/fastdds.sh << 'EOF'
source /root/fastdds_ws/install/setup.bash
export FASTDDS_DEFAULT_PROFILES_FILE=/etc/fastdds/profile.xml
EOF
chmod +x /etc/profile.d/fastdds.sh
⚠️ 注意:
/etc/fastdds/profile.xml必须真实存在并通过fastdds xml validate校验(详见本专栏配置篇),否则进程启动时会打印 XML 加载告警并回退默认配置。
九、systemd 托管 Discovery Server(可选)
Fast DDS 是库形态,本身无常驻服务;但大规模部署推荐的 Discovery Server 是常驻进程,适合 systemd 托管。先在命令行实测启动行为:
fastdds discovery -l 0.0.0.0 -p 11811
实测回显:
#### Server started ####
GUID prefix: 01.0f.2b.9f.08.22.53.69.00.00.00.00
Running on: UDPv4:[0.0.0.0]:11811
💡 说明:
GUID prefix每次启动随机生成;11811是 DDSI-RTPS 规范的默认发现端口。确认监听用 UDP 选项(不是ss -ltnp,Discovery Server 走 UDP):
ss -lunp | grep 11811
实测回显:
UNCONN 0 0 0.0.0.0:11811 0.0.0.0:* users:(("fast-discovery-",pid=8712,fd=8))
写入 systemd 单元:
cat > /etc/systemd/system/fastdds-discovery.service << 'EOF'
[Unit]
Description=eProsima Fast DDS Discovery Server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/root/fastdds_ws/install/fastdds/bin/fast-discovery-server -i 0 -l 0.0.0.0 -p 11811
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
启用并启动(每行针对一个单元操作):
systemctl daemon-reload
systemctl enable fastdds-discovery
systemctl start fastdds-discovery
验证:
systemctl is-active fastdds-discovery
预期输出:
active
⚠️ 注意:systemd 托管需要带 systemd 的 Linux 真机(
ExecStart用绝对路径直连二进制fast-discovery-server,不依赖 shell profile 环境)。-i 0指定 server-id(0-255,多服务器组网时各不相同);客户端侧用环境变量或 XML 指向server_address:11811即接入服务器发现模式(客户端配置见本专栏配置篇)。
十、常见问题(FAQ)
Q1:apt-get install python3-colcon-common-extensions 报 Unable to locate package?
Ubuntu 22.04 官方源不含 colcon(实测报 E: Unable to locate package python3-colcon-common-extensions、退出码 100)。用 pip3 install -U colcon-common-extensions vcstool 安装即可。
Q2:fastdds version 报 Invalid command?
v3 CLI 无 version 子命令(实测返回 Invalid command: 'version'. Use 'fastdds -h' for help.),用全局选项 fastdds -v(输出 Fast DDS version: 3.6.2.0)。旧教程里的 fastdds version 多来自 ROS 2 打包环境,不是官方 CLI 行为。
Q3:CLI 提示 "psutil" module not found?
CLI 是 Python 脚本,依赖未装:pip3 install psutil xmlschema(xmlschema 为 fastdds xml 校验子命令所需)。实测装好后 fastdds -v 正常。
Q4:编译时 CMake 报找不到 foonathan memory 或 fastcdr?
Fast-DDS 配置阶段要先找到两个依赖。原因多半是跳过依赖包直接编译 fastdds,或 colcon 工作区没有把依赖放进同一 src/。按第四章 repos 方式拉齐后 colcon build --packages-up-to fastdds 即可。
Q5:colcon build 中途 OOM 或进程被杀?
C++ 模板编译吃内存。2GB 以下内存机器降低并行度:colcon build --packages-up-to fastdds --parallel-workers 1,或 MAKEFLAGS=-j2 colcon build。
Q6:示例两端互不发现?
排查顺序:两端 domain 是否一致 → 同网段是否放行 UDP(组播 + 单播)→ 是否跨网段(组播不过路由器)。跨网段场景改用 Discovery Server 模式:服务端 fastdds discovery,客户端配置指向 server:11811(见本专栏配置篇与命令篇实测)。
Q7:pip3 install 提示 externally-managed-environment?
Ubuntu 23.04+ / Debian 12+ 启用 PEP 668 保护系统 Python。加 --break-system-packages 参数或用 python3 -m venv 建虚拟环境安装。
十一、卸载与清理
colcon 工作区方案(删除目录即完成):
rm -rf ~/fastdds_ws
CMake 全局方案(按安装清单清理):
rm -rf /usr/local/include/fastdds /usr/local/lib/libfastdds* /usr/local/lib/libfastcdr* /usr/local/include/fastcdr /usr/local/lib/cmake/fastdds /usr/local/lib/cmake/fastcdr
ldconfig
systemd 单元清理(先停再禁用后删文件):
systemctl stop fastdds-discovery
systemctl disable fastdds-discovery
rm /etc/systemd/system/fastdds-discovery.service
systemctl daemon-reload
deb 包方案:
apt remove --purge fastdds
十二、参考链接
- 官方 Linux 源码安装文档:https://fast-dds.docs.eprosima.com/en/latest/installation/sources/sources_linux.html
- 官方 Linux 二进制安装文档:https://fast-dds.docs.eprosima.com/en/latest/installation/binaries/binaries_linux.html
- Fast DDS GitHub Releases:https://github.com/eProsima/Fast-DDS/releases
- Fast DDS-Gen Releases:https://github.com/eProsima/Fast-DDS-Gen/releases
- fastdds.repos(3.6.x 分支):https://raw.githubusercontent.com/eProsima/Fast-DDS/3.6.x/fastdds.repos
- eProsima 官网下载页:https://eprosima.com/index.php/downloads-all
- 本平台关联文档:《Fast-DDS 3.6.2 介绍与选型指南》