fredag 13 mars 2015

Linux - Building .deb Packages from Source in Ubuntu (or Debian)

Written by in Guides

WP Greet Box icon
X
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.
Sometimes, we need to build a package from source. For performance reasons (architecture-specific optimizations), memory reasons (removing features we don’t need), or just for kicks. In Ubuntu (or any other Debian derivative, for that matter), this can often pose a problem, as such hand-built packages are no longer managed by our Package Manager. Removal is rarely clean, and updates are no longer tracked.
At least two solutions exist, each suited to a different purpose.


apt-build
The first method relies on the apt-build package, which fetches the latest source available in the repositories listed in your /etc/apt/sources.list file. This source is then compiled into a package (generally the same configuration as if you had installed the binary, unless you specify otherwise) and installed. Updates should still be managed as normal.
Note: This method is ideal if the package has source available in one of the repositories you have configured.
To install apt-build:

$ sudo apt-get install apt-build

This should add a local repository to /etc/apt/sources.list for any built packages. To make sure that the package manager is aware of this:

$ sudo apt-get update

Building a package with the default options is as simple as installing a precompiled binary package. For example, to build Prism:

$ sudo apt-build install prism

checkinstall
On occasion, the need may arise for an application that is not included in the standard repositories (or any supplemental ones configured). This is common with niche software, software with licensing complications that prevent it from being hosted in one of the repositories, abandonware, and applications that are have no maintainer beyond the upstream developers.
For cases like these, checkinstall is an ideal solution, as it allows us to build a .deb package for easy removal later. This package will not have updates tracked, but does offer the most flexibility.
To install checkinstall:

$ sudo apt-get install checkinstall

With it installed, building from source follows the usual documentation for a package, with one minor adjustment: We substitute the checkinstall command in place of make install. For example:

$ tar xjf package-source.tar.bz2
$ cd package-source
$ ./configure
$ make
$ sudo checkinstall

At this point, checkinstall will ask you for a few details about the application being built (package name, version number and such), and build a .deb package with the relevant metadata. It is automatically, and the package-name.deb will remain in the current directory for convenience. You can back it up or remove it, depending on your need. Reinstalling it is as simple as:

$ sudo dpkg -i package-name.deb

Removal follows the typical style:

$ sudo apt-get remove --purge package-name

Where package-name is the name provided to checkinstall when it asked for it.
Again, it is important to note that packages built with checkinstall are not tracked for updates. You need to stay aware of any important updates for packages built like this, as updates are not built automatically. Many applications have RSS feeds or mailing lists for releases and updates, and subscribing to these could allow you to patch a vulnerable application before it becomes a problem.
Finished reading? Try one of the following:
  • Tell me what you think in the comments!
  • Get the feed, and keep tabs on new content.
  • Write a response on your blog, and post a link in the comments.
Readability - (FRE: 48.1 | FKI: 10.5 | GFI: 13.2)
2 Responses to Building .deb Packages from Source in Ubuntu (or Debian)
  1. [...] HOWTO – Build .deb Packages from Source in Ubuntu (or Debian) (tags: linux debian packaging deb build compile ubuntu) [...]

Inga kommentarer: