Skybinary

View Categories

1.1.5 Basic Package How to Compile and Install Basic Packages from Source in Linux

30 min

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:

  1. ./configure → Checks dependencies & prepares the build.
  2. make → Compiles the source code.
  3. 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 for make).
  • Command:bash./configure
  • Common Issues & Fixes:
    • Missing dependencies? → Install them first (e.g., gcclibssl-dev).
    • Custom installation path? → Use --prefix:bash./configure –prefix=/usr/local/custom

3. Run make (Compilation) #

  • Purpose:
    • Compiles source code into executable binaries using the Makefile.
  • 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).
  • 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 (aptyum).
  • No automatic updates (must recompile manually).

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top