Cannot run program "rpmbuild"
# 一、报错现象
在使用 mvn clean install package rpm:rpm
编译 Ambari 或其他大数据组件时,出现如下报错:
[INFO] Creating directory /opt/modules/ambari/target/rpm/ambari/SOURCES
[INFO] Creating directory /opt/modules/ambari/target/rpm/ambari/SPECS
[INFO] Creating directory /opt/modules/ambari/target/rpm/ambari/SRPMS
[INFO] Creating directory /opt/modules/ambari/target/rpm/ambari/tmp-buildroot
[INFO] Creating directory /opt/modules/ambari/target/rpm/ambari/buildroot
[INFO] Creating spec file /opt/modules/ambari/target/rpm/ambari/SPECS/ambari.spec
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Ambari Main 2.8.0.0.0:
[INFO]
[INFO] Ambari Main ........................................ FAILURE [ 7.398 s]
[INFO] Apache Ambari Project POM .......................... SKIPPED
[INFO] Ambari Web ......................................... SKIPPED
[INFO] Ambari Views ....................................... SKIPPED
[INFO] Ambari Admin View .................................. SKIPPED
[INFO] ambari-utility ..................................... SKIPPED
[INFO] Ambari Server SPI .................................. SKIPPED
[INFO] Ambari Service Advisor ............................. SKIPPED
[INFO] Ambari Server ...................................... SKIPPED
[INFO] Ambari Functional Tests ............................ SKIPPED
[INFO] Ambari Agent ....................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.153 s (Wall Clock)
[INFO] Finished at: 2025-05-24T05:40:59Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.4:rpm (default-cli) on project ambari: Unable to build the RPM: Error wh
ile executing process. Cannot run program "rpmbuild" (in directory "/opt/modules/ambari/target/rpm/ambari/SPECS"): error=2, No such file or di
rectory -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[root@centos5 ambari]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
通常表现为 Maven 调用 rpm-maven-plugin 时,系统找不到 rpmbuild
命令,导致整个 RPM
打包流程中断。环境依赖
# 二、原因分析
常见成因
- rpmbuild 工具未安装:大部分最小化/精简版的 CentOS、RHEL 系统默认并未安装 RPM 构建工具。
- 环境变量缺失:即使已安装,但如果
rpmbuild
不在$PATH
,也会导致找不到命令。 - 相关依赖包缺失:如
rpm-build
、rpmdevtools
等依赖未就绪,间接影响构建。
# 三、解决步骤
# 1. 检查是否已安装 rpmbuild
which rpmbuild
1
如未输出路径,表示未安装。
# 2. 安装 rpm-build 工具包
提示
针对 RHEL/CentOS 及兼容系统,直接执行:
yum install -y rpm-build
1
或(部分系统需加 rpmdevtools)
yum install -y rpm-build rpmdevtools
1