Chapter 10.3 - Compilation and Alternative Packages
Learning Objectives
By the end of this chapter, you will be able to:
- Compile software from sources
- Use Snap for universal packages
- Use Flatpak for applications
- Understand the advantages/disadvantages
- Choose the right tool for the case
Compilation from Sources
Prerequisites
# Compilation tools
sudo apt install build-essential # Ubuntu/Debian
sudo yum groupinstall "Development Tools" # Red Hat/CentOS
# Necessary tools
# - gcc/g++ (compiler)
# - make (build system)
# - autoconf, automake
# - libtool
Standard Process
# 1. Download sources
wget http://example.com/software-1.0.tar.gz
tar -xzf software-1.0.tar.gz
cd software-1.0
# 2. Configuration
./configure --prefix=/usr/local
# Common options
./configure --prefix=/usr/local \
--enable-feature \
--disable-other \
--with-library=/usr/lib
# 3. Compilation
make
# 4. Installation
sudo make install
# 5. Cleanup (optional)
make clean
Complete Example
#!/bin/bash
# Compilation example
VERSION="1.0"
SOFTWARE="my-software"
PREFIX="/usr/local"
# Download
wget "http://example.com/${SOFTWARE}-${VERSION}.tar.gz"
tar -xzf "${SOFTWARE}-${VERSION}.tar.gz"
cd "${SOFTWARE}-${VERSION}"
# Configure
./configure --prefix="$PREFIX"
# Compile
make -j$(nproc) # Use all CPUs
# Install
sudo make install
# Verify
which my-software
my-software --version
Snap
What is Snap?
Snap is a universal package system developed by Canonical.
Advantages:
- Universal (all distributions)
- Auto-update
- Isolation (sandbox)
- Dependencies included
Installation
# Ubuntu (already installed)
# Other distributions
sudo apt install snapd # Debian
sudo yum install snapd # Red Hat/CentOS
Usage
# Search
snap find package-name
# Install
sudo snap install package-name
# List installed
snap list
# Update
sudo snap refresh package-name
sudo snap refresh # All
# Remove
sudo snap remove package-name
# Information
snap info package-name
Examples
# Popular applications
sudo snap install code # VS Code
sudo snap install docker # Docker
sudo snap install node --classic # Node.js
sudo snap install chromium # Chromium
Flatpak
What is Flatpak?
Flatpak is a universal application distribution system.
Advantages:
- Universal
- Isolation
- Desktop applications
- Repositories (Flathub)
Installation
# Ubuntu/Debian
sudo apt install flatpak
# Red Hat/CentOS/Fedora
sudo yum install flatpak
# or
sudo dnf install flatpak
Configuration
# Add Flathub (main repository)
flatpak remote-add --if-not-exists flathub \
https://flathub.org/repo/flathub.flatpakrepo
# View repositories
flatpak remotes
Usage
# Search
flatpak search app-name
# Install
flatpak install flathub app-name
# List installed
flatpak list
# Update
flatpak update app-name
flatpak update # All
# Remove
flatpak uninstall app-name
# Information
flatpak info app-name
Examples
# Popular applications
flatpak install flathub org.gimp.GIMP
flatpak install flathub org.videolan.VLC
flatpak install flathub com.spotify.Client
Comparison
| Feature | apt/yum | Snap | Flatpak | Compilation |
|---|---|---|---|---|
| Universal | No | Yes | Yes | Yes |
| Isolation | No | Yes | Yes | No |
| Size | Small | Large | Large | Variable |
| Performance | Excellent | Good | Good | Excellent |
| Updates | Manual | Auto | Auto | Manual |
| Usage | System | Applications | Desktop | Development |
Choosing the Right Tool
apt/yum
When to use:
- System packages
- Server services
- Critical performance
- Full control
Snap
When to use:
- Universal applications
- Automatic updates
- Necessary isolation
- Development
Flatpak
When to use:
- Desktop applications
- Necessary isolation
- Multi-distributions
- Graphical applications
Compilation
When to use:
- Specific version needed
- Custom compilation options
- No package available
- Development
Best Practices
Compilation
# 1. Read README/INSTALL
# 2. Check dependencies
# 3. Use appropriate --prefix
# 4. Test before installation
# 5. Document options used
Snap/Flatpak
# 1. Verify source (official)
# 2. Understand permissions
# 3. Monitor disk space
# 4. Update regularly
Summary
In this chapter, you learned:
Compilation: configure, make, make install
Snap: Universal packages, auto-update, isolation
Flatpak: Desktop applications, Flathub, isolation
Comparison: Choose according to needs
Practice: Compile, install Snap/Flatpak
Next Steps
Module 11: Monitoring and Logs (with monitoring crons)
Module 12: Advanced Administration
Chapter created on: December 2024