Compiling from Source
Sometimes the software you need isn't packaged. Or you need a specific version. Or you want custom compile options. Time to build from source.
When to Compile from Source
- Software not in any repository
- Need latest version (packages lag behind)
- Need specific compile-time options
- Learning how software is built
- Contributing to open source
Prefer Packages When Possible
Compiling means no automatic updates, harder uninstalls, and potential dependency conflicts. Only compile when you have a good reason.
Install Build Tools
build-essential includes:
gcc- C compilerg++- C++ compilermake- Build automation- Development libraries
The Classic Pattern
Most source code follows this pattern:
Real Example: htop from Source
Understanding ./configure
configure checks your system and creates a Makefile. Common options:
Missing Dependencies
Configure fails? Usually missing a library:
Dev Packages
Libraries have two packages: libfoo (runtime) and libfoo-dev (headers for compiling). You need the -dev package.
Uninstalling
If you kept the source directory:
If you didn't keep it... manually delete from /usr/local/.
Alternative: checkinstall
checkinstall creates a .deb package from your compiled software:
What command checks your system and creates a Makefile before compiling?
Quick Reference
| Step | Command | Purpose |
|---|---|---|
| 1 | ./configure | Check system, create Makefile |
| 2 | make | Compile source code |
| 3 | sudo make install | Install to system |
| 4 | sudo make uninstall | Remove (if available) |
Key Takeaways
./configure && make && sudo make installis the classic pattern- Install
build-essentialfor compilers -devpackages provide headers for compiling- Configure fails? Install missing dev packages
- Use
checkinstallfor cleaner uninstalls - Prefer packages when available
Congratulations! You've completed Chapter 10: Package Management.
Next chapter: Text Editors - editing files from the command line.