Patch software
When packaging software, you might need to make certain changes to the original source code, such as fixing a bug or changing a configuration file. In RPM packaging, you can instead leave the original source code intact and apply patches on it.
A patch is a piece of text that updates a source code file. The patch has a diff format, because it represents the difference between two versions of the text. You can create a patch by using the diff utility, and then apply the patch to the source code by using the patch utility.
Software developers often use version control systems such as Git to manage their code base. Such tools offer their own methods of creating diffs or patching software.
Create a patch file for a sample C program Copy linkLink copied!
Create a patch from the original source code of a sample Hello world program written in C (cello.c) by using the diff utility. You can then apply this patch to make changes to the packaged software without making changes to the original source code.
Before you begin Copy linkLink copied!
- You installed the
diffutility on your system:# dnf install diffutils
Procedure Copy linkLink copied!
Patch a sample C program Copy linkLink copied!
Apply code patches to a sample Hello world program written in C (cello.c) by using the patch utility.
Before you begin Copy linkLink copied!
- You installed the
patchutility on your system:# dnf install patch - You created a patch from the original source code. For instructions, see Creating a patch file for a sample C program.
Procedure Copy linkLink copied!
Results Copy linkLink copied!
- Build the patched
cello.cprogram:$ makegcc -g -o cello cello.c - Run the built
cello.cprogram:$ ./celloHello World from my very first patch!