You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:将120MB.tar.gz打包为RHEL7 RPM,解决依赖与文件批量处理问题

Got it, let's fix this RPM packaging issue for your 120MB tarball. The problem right now is that you're only copying a single file (my-app) into the buildroot, which is why your RPM is tiny and missing all the dependent files from the tarball's lib directory and elsewhere. Here's how to adjust your spec file to package everything efficiently without listing hundreds of files manually:

Step 1: Update the %install Section to Copy All Files

Your current %install step only copies one file—we need to replicate the entire contents of the extracted tarball into the buildroot's /usr/bin directory. Use cp -a to preserve file permissions, ownership, and directory structure (critical for dependencies to work correctly).

First, check your tarball's structure to make sure you're copying from the right place:

tar tf my-app-2.0.rhel7.x86_64.tar.gz

If the files extract directly into the root of the archive (no top-level folder), use this %install section:

%install
# Create the target directory in the buildroot
mkdir -p %{buildroot}/%{_bindir}
# Copy ALL extracted files/dirs to /usr/bin in the buildroot
cp -a ./* %{buildroot}/%{_bindir}/

If the tarball extracts into a top-level folder (e.g., my-app-2.0/), adjust the source path:

%install
mkdir -p %{buildroot}/%{_bindir}
# Copy from the extracted top-level folder to /usr/bin
cp -a %{name}-%{version}/* %{buildroot}/%{_bindir}/
Step 2: Use Wildcards in %files to Include All Content

Instead of listing every file manually, use a wildcard to include everything under /usr/bin for your app. This will automatically pick up all files, subdirectories, and their contents:

%files
%{_bindir}/

If you want to be more explicit (though the above works perfectly), you can also use:

%files
%{_bindir}/*
Step 3: Finalize the Spec File (Optional Polish)

Add a %clean section to tidy up the buildroot (RHEL7's rpmbuild may handle this automatically, but it's good practice):

%clean
rm -rf %{buildroot}
Full Updated Spec File

Here's the complete working spec file tailored to your needs:

Name: my-app
Version: 2.0
Release: 1%{?dist}
Summary: My application
License: Internal license
URL: <my-website>
Source0: <my-website>/%{name}-%{version}.rhel7.x86_64.tar.gz
Requires: bash
BuildArch: x86_64

%description
My application

%prep
%setup -q

%build
# No build steps needed for a pre-compiled binary tarball

%install
mkdir -p %{buildroot}/%{_bindir}
# Adjust the source path below if your tarball uses a top-level folder
cp -a ./* %{buildroot}/%{_bindir}/

%clean
rm -rf %{buildroot}

%files
%{_bindir}/
Verify Your Package

After building the RPM, check that all files are included with:

rpm -qlp my-app-2.0-1.el7.x86_64.rpm

This will list every file in the RPM—confirm it matches the contents of your original tarball. You can also check dependencies with:

rpm -qp --requires my-app-2.0-1.el7.x86_64.rpm

Add any missing system-level dependencies to the Requires line if needed (e.g., libcurl, openssl-libs).

内容的提问来源于stack exchange,提问作者Armaggedon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 20:12:26