How to Install Software from Source on Debian 12 (Bookworm)
Categories:
4 minute read
Introduction
Debian 12 (Bookworm) is a stable and robust Linux distribution widely used for servers, desktops, and development environments. While Debian provides a vast repository of precompiled packages, sometimes you may need to install software from the source. This could be due to reasons such as needing a newer version of a package, applying custom patches, or optimizing the build for your hardware.
In this guide, we will walk you through the process of installing software from the source on Debian 12, covering prerequisites, downloading and compiling software, resolving dependencies, and managing installation paths.
Prerequisites
Before you begin, ensure that your system is up to date by running:
sudo apt update && sudo apt upgrade -y
You will also need a set of essential tools for compiling software. Install them with:
sudo apt install build-essential
This package includes GCC (GNU Compiler Collection), G++, make, and other necessary tools. Additionally, depending on the software you are compiling, you might need other dependencies such as development libraries and headers.
Step 1: Install Required Dependencies
Many software projects rely on external libraries. The easiest way to find missing dependencies is to check the documentation of the software or use the apt
package manager to install commonly required tools:
sudo apt install autoconf automake libtool pkg-config cmake
If you are building a graphical application, you may need additional dependencies:
sudo apt install libgtk-3-dev qtbase5-dev
Step 2: Download the Source Code
The source code of most open-source software is available from official websites, GitHub, GitLab, or SourceForge. For example, to download the source code of a program like htop
, you can use:
wget https://github.com/htop-dev/htop/archive/refs/tags/3.2.2.tar.gz
Extract the tarball:
tar -xvzf 3.2.2.tar.gz
cd htop-3.2.2
Alternatively, if the software is managed with Git, you can clone the repository:
git clone https://github.com/htop-dev/htop.git
cd htop
Step 3: Configure the Build System
Most source packages use either autotools
, CMake
, or Meson
as their build system. Here’s how to configure them:
Using configure
If the software uses autotools
, run:
./autogen.sh # If provided by the software
./configure --prefix=/usr/local
The --prefix=/usr/local
option ensures that the software is installed under /usr/local
instead of overwriting system binaries in /usr
.
Using CMake
If the software uses CMake, create a build directory and run:
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
Using Meson
If the software uses Meson:
meson setup build --prefix=/usr/local
cd build
Step 4: Compile the Software
After configuring, compile the software using:
make -j$(nproc)
This command tells make
to compile using all available CPU cores, speeding up the process.
For CMake-based builds, run:
cmake --build . -- -j$(nproc)
For Meson:
ninja
Step 5: Install the Compiled Software
Once the compilation is successful, install the software system-wide with:
sudo make install
For CMake:
sudo cmake --install .
For Meson:
sudo ninja install
After installation, update the system’s library cache if necessary:
sudo ldconfig
Step 6: Verify the Installation
Once installed, check if the software is available:
which htop
htop --version
If the binary is not found, try adding /usr/local/bin
to your PATH
:
export PATH=/usr/local/bin:$PATH
To make this change permanent, add the above line to ~/.bashrc
or ~/.profile
.
Step 7: Uninstalling Software Installed from Source
Unlike apt
-installed packages, software installed from source does not have a package manager tracking it. To uninstall manually:
sudo make uninstall
If the software does not provide an uninstall target, remove it manually:
sudo rm -rf /usr/local/bin/htop /usr/local/share/man/man1/htop.1
Using stow
can help manage source installations better:
sudo apt install stow
stow -d /usr/local -S htop
stow -d /usr/local -D htop # To remove
Conclusion
Compiling and installing software from source on Debian 12 (Bookworm) gives you control over versions, optimizations, and configurations. While it requires more effort than using apt
, it is a valuable skill for system administrators and developers. By following the steps outlined—installing dependencies, downloading and compiling source code, configuring paths, and handling uninstallation—you can efficiently manage source-based software on your Debian system.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.