How to recompile a package from source

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
User avatar
xenopeek
Level 25
Level 25
Posts: 29607
Joined: Wed Jul 06, 2011 3:58 am

How to recompile a package from source

Post by xenopeek »

In some cases you might find yourself in need to apply a patch or change a compile time configuration option for a package you installed from the repository. It's easy to do that, as tools are available to download the source of a package and recompile it after you have made the changes you need.

Preparation
  1. sudo apt-get update
    As always, before you install packages from the terminal do an update first so that your local package cache is in sync with the repository.
  2. sudo apt-get install build-essential devscripts
    Installs the base compiler toolchain.
  3. Open Software Sources from your menu, and make sure "Enable source code repositories" is marked. Then click "Update the cache".
    This allows for downloading source for packages.
Recompiling from source
  1. apt-get source package
    Downloads the source for a package to your current directory. Replace package with the name of the package you want to download the source for. Mind that you must not use sudo!
  2. dpkg-source -x filename.dsc
    If the last line output by the previous command is "dpkg-source: info: unpacking […]" you can skip this step as the apt-get source command already did it for you. Otherwise this command extracts the source. Replace filename.dsc with the name of the downloaded .dsc file. You can look in your file manager, or with a command like ls *.dsc to find that.
  3. cd dirname
    Change directory to the newly created source directory. Replace dirname with the name of the extracted directory. You can look in your file manager, or with a command like ls -l to find that.
  4. sudo apt-get build-dep package
    installs the build time dependencies needed to compile the package from source. Replace package with the same name as used in step 1.
  5. You can now apply any patches you need or change any compile time configuration options. That's a manual step that I can't generalize in this tutorial. Recommend you keep the terminal open on the current directory, and use another terminal if needed for doing modifications.
  6. debuild -us -uc
    Recompiles the package.
  7. cd ..
    Goes one directory up, as here you will find your newly created package.
  8. sudo dpkg -i filename.deb
    Installs the recompiled package. Replace filename.deb with the name of the created .deb file. You can look in your file manager, or with a command like ls *.deb to find that.
Cleanup consists of deleting the downloaded files, the extracted source code directory, and the created recompiled package.
Image
vistad
Level 4
Level 4
Posts: 326
Joined: Tue Feb 08, 2011 9:17 am

Re: How to recompile a package from source

Post by vistad »

Thank you for sharing this essential info!
Linux Mint Mate 21.2 64, fanless box with passive cooling
Post Reply

Return to “Tutorials”