Compile from source
Reading material
What is it?
“Compile from source” refers to the process of taking human-readable source code and converting it into an executable program or library that a computer can run directly. This contrasts with installing pre-compiled binary packages, which are already in a machine-readable format.
The process typically involves:
Obtaining the source code
This usually comes in a compressed archive (like a .tar.gz or .zip file) or by cloning a version control repository (like Git).
Configuring the build
Tools like configure or cmake are often used to check for necessary dependencies and adapt the build process to the specific system environment.
Compiling
A compiler (e.g., GCC for C/C++) translates the source code into object files, which are machine-readable but not yet executable.
Linking
A linker combines the object files and any necessary libraries into the final executable program or shared library.
Installing
The compiled program is then placed in the appropriate directories on the system for use.
After building an executable from source in Linux, the placement depends on whether it’s for personal use or system-wide access.
For System-Wide Use: /usr/local/bin. This is the conventional location for manually installed executables that are intended for all users on the system. When building from source, you can often specify an installation prefix during the make install step, such as
make install --prefix=/usr/local
or
sudo cp <executable_name> /usr/local/bin/
Users might choose to compile from source for various reasons
Customization
Enabling or disabling specific features, or optimizing the software for a particular hardware architecture.
Access to the latest versions
Obtaining software updates that may not yet be available in official package repositories.
Security and auditing
Examining the source code for vulnerabilities or understanding its functionality.
Troubleshooting and development
Making modifications to the code or debugging issues.