Linucate
~ Linucate_

206.1 Make and install programs from source

All Levels

Introduction

Building from source gives control over version and features, but bypassing the package manager creates maintenance responsibility. Record exactly what was built and where it was installed.

What you should be able to do after this lesson:

  • Unpack common source archive formats.
  • Inspect build instructions and prerequisites.
  • Configure and compile a traditional project.
  • Apply a patch and use parallel builds.
  • Install under an appropriate prefix and plan removal.

Big Idea: Source Installation Creates an Ownership Problem

A package manager records which files belong to a package and how to upgrade or remove them. A plain make install may copy files without leaving a complete manifest. Before compiling, decide who will own updates, security fixes, configuration, and removal.

Unpack Source Archives

tar -xf project.tar.gz
tar -xf project.tar.bz2
tar -xf project.tar.xz

Modern tar usually detects compression. Individual decompressors include gunzip, bunzip2, and unxz.

Inspect an archive before extraction when its origin or layout is uncertain:

tar -tf project.tar.xz | head

Read Build Documentation

Look for README, INSTALL, and project-specific security guidance. Confirm the source version, checksum, signature, compiler requirements, and development libraries.

/usr/src/ is a traditional location for system source, but an unprivileged working directory is safer for compilation.

Configure

Traditional Autotools projects use:

./configure --prefix=/usr/local

configure checks dependencies and generates Makefiles. Useful patterns include:

./configure --help
./configure --prefix=/opt/project --sysconfdir=/etc/project

Read the final configure summary; a successful exit can still mean an optional feature was disabled.

Compile and Test

make -j"$(nproc)"
make check

make reads dependency rules and rebuilds required targets. The first compiler or linker error is usually more useful than the final failure line.

Apply a Patch

patch -p1 < fix.patch

Run a dry check when appropriate:

patch --dry-run -p1 < fix.patch

The correct strip level depends on paths stored in the patch.

Install

sudo make install

/usr/local is conventionally reserved for locally installed software. Installing into /usr can overwrite package-managed files. Prefer building a native package or staging with DESTDIR when possible:

make DESTDIR=/tmp/project-package install

Removal and Updates

Not every project implements make uninstall. Keep the build tree, install manifest, configuration flags, and version. Source-installed libraries may require an ldconfig update.

Guided Practice: Audit a Build Before Installation

Download source only from a trusted project in a controlled lab, then inspect it without root privileges:

tar -tf project.tar.xz | head
tar -xf project.tar.xz
cd project-<version>
find . -maxdepth 1 -type f -printf '%f\n'
./configure --help | less

Choose a private staging prefix and run the checks:

./configure --prefix=/opt/project-test
make -j"$(nproc)"
make check
make DESTDIR=/tmp/project-stage install
find /tmp/project-stage -type f | sort

DESTDIR stages the files under a temporary root and reveals what installation would copy. It does not normally replace the compiled prefix stored inside the program. Use the staged file list to design a package or removal manifest.

Troubleshooting Scenario

configure succeeds, but its summary says TLS support is disabled. Compilation and installation would produce a working binary without a required security feature.

Read the configure log, install the correct development headers, rerun configuration from a clean state, and verify the final summary. A zero exit status proves configuration completed, not that every optional capability was enabled.

Exam Focus

  • Recognize gzip, bzip2, xz, tar, and their decompression tools.
  • Know the roles of configure, Makefiles, make, install, patch, and uname.
  • Compile as an unprivileged user and reserve /usr/local or /opt for locally managed software.
  • Use package or staging workflows when maintainability matters.

Recap

  • Verify source provenance before building.
  • configure, make, testing, and installation are separate stages.
  • Compile without root privileges.
  • Prefer /usr/local, /opt, or a distribution package over unmanaged writes into /usr.
🎯

Test Your Knowledge

Complete the quiz to assess your understanding of this course's concepts.