How to Compile from Source Code in Linux



This content originally appeared on DEV Community and was authored by Harry Tanama

The standard process for compiling and installing an application from source usually follows these steps:

Download and Extract: Download the source code, which is usually a compressed archive (.tar.gz, .tar.bz2, etc.).

Configure: Run the ./configure script (if it exists) to check for dependencies and prepare the Makefile.

./configure

Compile: Run the make command to compile the code.

make

Install: Run sudo make install to install the final binary and its associated files to the system.

sudo make install

Important Note: Always check the README or INSTALL files that come with the source code, as the build process can vary significantly between projects.

For local installation

./configure --prefix=$HOME/.local

make

make install

Cmake

Build software application using CMake:

mkdir build
cd build

Configure with a CMAKE_INSTALL_PREFIX: You specify the installation directory when running cmake.

cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/.local

The .. tells cmake to look for the CMakeLists.txt file in the parent directory.

Compile and Install:

make

make install

Making the Binaries Accessible

After a local installation, the executable files are in a directory like ~/.local/bin, but your shell might not know where to find them. To fix this, you need to add this directory to your PATH environment variable.

You can do this by adding the following line to your shell’s configuration file (e.g., ~/.bashrc or ~/.zshrc):

export PATH=$HOME/.local/bin:$PATH


This content originally appeared on DEV Community and was authored by Harry Tanama