Table of Contents
Basic Package Compilation from Source in Linux #
When a Linux application is not available as a pre-built package (.deb
, .rpm
), you can compile it from source. The typical process involves three main steps:
./configure
→ Checks dependencies & prepares the build.make
→ Compiles the source code.make install
→ Installs the compiled binaries.
Step-by-Step Guide #
1. Download & Extract the Source Code #
- Source code is usually distributed as a
.tar.gz
or.tar.bz2
file. - Extract it using:bashtar -xzvf package.tar.gz # For .tar.gz tar -xjvf package.tar.bz2 # For .tar.bz2 cd package/ # Enter the extracted directory
2. Run ./configure
(Configuration) #
- Purpose:
- Checks system dependencies (libraries, compilers).
- Generates a
Makefile
(instructions formake
).
- Command:bash./configure
- Common Issues & Fixes:
- Missing dependencies? → Install them first (e.g.,
gcc
,libssl-dev
). - Custom installation path? → Use
--prefix
:bash./configure –prefix=/usr/local/custom
- Missing dependencies? → Install them first (e.g.,
3. Run make
(Compilation) #
- Purpose:
- Compiles source code into executable binaries using the
Makefile
.
- Compiles source code into executable binaries using the
- Command:bashmake
- Troubleshooting:
- If compilation fails, check for missing headers/libraries.
- Clean previous builds:bashmake clean
4. Run make install
(Installation) #
- Purpose:
- Copies compiled binaries to system directories (
/usr/local/bin
,/usr/bin
).
- Copies compiled binaries to system directories (
- Command:bashsudo make install # Needs root for system-wide install
- Uninstalling:
- Some packages support:bashsudo make uninstall
- If not, manually delete installed files (check
make install
logs).
Optional Steps #
make test
or make check
(Testing) #
- Some packages allow testing before installation:bashmake test
Custom Build Options #
- View available options:bash./configure –help
- Example (enable debugging):bash./configure –enable-debug
Example: Compiling htop
from Source #
# 1. Download & extract wget https://github.com/htop-dev/htop/archive/refs/tags/3.2.2.tar.gz tar -xzvf 3.2.2.tar.gz cd htop-3.2.2/ # 2. Configure ./configure # 3. Compile make # 4. Install sudo make install
Key Notes #
✅ Why compile from source?
- Latest version (not in repos).
- Custom optimizations (e.g.,
--enable-optimizations
).
⚠️ Risks?
- May conflict with package manager (
apt
,yum
). - No automatic updates (must recompile manually).