Ricerca

Questo contenuto non è disponibile nella lingua selezionata.

Chapter 1. Getting started with RPM packaging

download PDF

The following section introduces the concept of RPM packaging and its main advantages.

1.1. Introduction to RPM packaging

The RPM Package Manager (RPM) is a package management system that runs on RHEL, CentOS, and Fedora. You can use RPM to distribute, manage, and update software that you create for any of the operating systems mentioned above.

1.2. RPM advantages

The RPM package management system brings several advantages over distribution of software in conventional archive files.

RPM enables you to:

  • Install, reinstall, remove, upgrade and verify packages with standard package management tools, such as Yum or PackageKit.
  • Use a database of installed packages to query and verify packages.
  • Use metadata to describe packages, their installation instructions, and other package parameters.
  • Package software sources, patches and complete build instructions into source and binary packages.
  • Add packages to Yum repositories.
  • Digitally sign your packages by using GNU Privacy Guard (GPG) signing keys.

1.3. Creating your first rpm package

Creating an RPM package can be complicated. Here is a complete, working RPM Spec file with several things skipped and simplified.

Name:       hello-world
Version:    1
Release:    1
Summary:    Most simple RPM package
License:    FIXME

%description
This is my first RPM package, which does nothing.

%prep
# we have no source, so nothing here

%build
cat > hello-world.sh <<EOF
#!/usr/bin/bash
echo Hello world
EOF

%install
mkdir -p %{buildroot}/usr/bin/
install -m 755 hello-world.sh %{buildroot}/usr/bin/hello-world.sh

%files
/usr/bin/hello-world.sh

%changelog
# let's skip this for now

Save this file as hello-world.spec.

Now use these commands:

$ rpmdev-setuptree
$ rpmbuild -ba hello-world.spec

The command rpmdev-setuptree creates several working directories. As those directories are stored permanently in $HOME, this command does not need to be used again.

The command rpmbuild creates the actual rpm package. The output of this command can be similar to:

... [SNIP]
Wrote: /home/<username>/rpmbuild/SRPMS/hello-world-1-1.src.rpm
Wrote: /home/<username>/rpmbuild/RPMS/x86_64/hello-world-1-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.wgaJzv
+ umask 022
+ cd /home/<username>/rpmbuild/BUILD
+ /usr/bin/rm -rf /home/<username>/rpmbuild/BUILDROOT/hello-world-1-1.x86_64
+ exit 0

The file /home/<username>/rpmbuild/RPMS/x86_64/hello-world-1-1.x86_64.rpm is your first RPM package. It can be installed in the system and tested.

Red Hat logoGithubRedditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita ilBlog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

© 2024 Red Hat, Inc.