Bird
Raised Fist0
Linux CLIscripting~10 mins

Building from source basics in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Building from source basics
Download source code
↓
Extract source files
↓
Configure build options
↓
Compile source code
↓
Install compiled program
↓
Clean up build files
↓
DONE
This flow shows the main steps to build a program from source code on Linux.
Execution Sample
Linux CLI
wget http://example.com/app.tar.gz

tar -xzf app.tar.gz

cd app

./configure

make

sudo make install

make clean
This script downloads, extracts, configures, compiles, installs, and cleans up a program from source.
Execution Table
StepCommandActionResult/Output
1wget http://example.com/app.tar.gzDownload source archiveapp.tar.gz downloaded
2tar -xzf app.tar.gzExtract filesSource files extracted to ./app
3cd appChange directoryNow inside source folder ./app
4./configurePrepare buildChecks system, creates Makefile
5makeCompile sourceBuilds executable files
6sudo make installInstall programCopies files to system folders
7make cleanClean build filesRemoves temporary build files
8-EndBuild and install complete
💡 All steps completed successfully, program built and installed.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6After Step 7Final
Current Directory/home/user/home/user/home/user/home/user/app/home/user/app/home/user/app/home/user/app/home/user/app/home/user/app
Source ArchiveNoneapp.tar.gzapp.tar.gzapp.tar.gzapp.tar.gzapp.tar.gzapp.tar.gzapp.tar.gzapp.tar.gz
Build FilesNoneNoneExtractedExtractedConfiguredCompiledCompiledCleanedCleaned
Installed ProgramNoNoNoNoNoNoYesYesYes
Key Moments - 3 Insights
Why do we run './configure' before 'make'?
The './configure' step checks your system and creates the Makefile that 'make' uses to compile. Without it, 'make' won't know how to build the program. See execution_table step 4 and 5.
What happens if we skip 'sudo make install'?
Skipping 'sudo make install' means the program is compiled but not copied to system folders, so you can't run it globally. It stays only in the build folder. See execution_table step 6.
Why do we use 'make clean' at the end?
'make clean' removes temporary build files to free space and keep the folder tidy. It does not remove the installed program. See execution_table step 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of running 'tar -xzf app.tar.gz'?
ASource files extracted to ./app
Bapp.tar.gz downloaded
CBuilds executable files
DCopies files to system folders
💡 Hint
Check execution_table row 2 under Result/Output column.
At which step does the program get installed on the system?
AStep 4
BStep 5
CStep 6
DStep 7
💡 Hint
Look at execution_table step 6 and its Action and Result.
If we skip './configure', what will likely happen when running 'make'?
ACompilation will succeed without issues
BMakefile will be missing or incorrect, causing errors
CProgram will install automatically
DSource files will not extract
💡 Hint
Refer to key_moments about the role of './configure' before 'make'.
Concept Snapshot
Building from source involves these steps:
1. Download source code archive
2. Extract files with tar
3. Run './configure' to prepare build
4. Compile with 'make'
5. Install with 'sudo make install'
6. Clean build files with 'make clean'
Full Transcript
Building from source means creating a program from its original code. First, you download the source archive file. Then you extract it to get the source files. Next, you run './configure' to check your system and prepare the build instructions. After that, you compile the code using 'make'. Once compiled, you install the program with 'sudo make install' so it can be used system-wide. Finally, you can clean up temporary build files with 'make clean'. Each step must be done in order for the build to succeed.

Practice

(1/5)
1. What is the first step you usually perform when building software from source after downloading the archive?
easy
A. Run the make command
B. Extract the archive files
C. Install the software
D. Configure the system settings

Solution

  1. Step 1: Identify the initial action after download

    After downloading source code, you first need to extract the files from the archive (like .tar.gz) to access them.
  2. Step 2: Understand the build sequence

    Extraction comes before configuration, compilation, and installation.
  3. Final Answer:

    Extract the archive files -> Option B
  4. Quick Check:

    First step = Extract [OK]
Hint: Always extract source files before anything else [OK]
Common Mistakes:
  • Trying to compile before extracting files
  • Running make without configuration
  • Skipping extraction step
2. Which command is used to prepare the build environment by checking system settings before compiling?
easy
A. ./configure
B. gcc main.c
C. tar -xvf source.tar.gz
D. make install

Solution

  1. Step 1: Identify the configuration command

    The ./configure script checks your system for required tools and sets up makefiles.
  2. Step 2: Differentiate from other commands

    make install installs, tar -xvf extracts, and gcc compiles single files.
  3. Final Answer:

    ./configure -> Option A
  4. Quick Check:

    Prepare build = ./configure [OK]
Hint: Use ./configure to set up before compiling [OK]
Common Mistakes:
  • Running make install before configure
  • Confusing extraction with configuration
  • Trying to compile without configuration
3. Given these commands run in order inside the source directory:
./configure
make
sudo make install
What is the expected result?
medium
A. An error occurs because sudo is used incorrectly
B. Only the software is compiled but not installed
C. The software is installed without compiling
D. The software is configured, compiled, and installed system-wide

Solution

  1. Step 1: Understand each command's role

    ./configure prepares build files, make compiles the software, and sudo make install installs it with admin rights.
  2. Step 2: Combine the steps' effects

    Running all three in order results in a configured, compiled, and installed program available system-wide.
  3. Final Answer:

    The software is configured, compiled, and installed system-wide -> Option D
  4. Quick Check:

    Configure + make + sudo install = full build [OK]
Hint: Run configure, then make, then sudo make install [OK]
Common Mistakes:
  • Skipping configure step
  • Not using sudo for install
  • Expecting install without compilation
4. You run make install without sudo and get a permission denied error. What is the best fix?
medium
A. Run sudo make install to get admin rights
B. Run make again without install
C. Re-extract the source files
D. Skip installation and use the software from source

Solution

  1. Step 1: Identify cause of permission error

    Installing usually writes to system folders needing admin rights, so permission is denied without sudo.
  2. Step 2: Apply correct fix

    Using sudo make install runs install with admin privileges, fixing the error.
  3. Final Answer:

    Run sudo make install to get admin rights -> Option A
  4. Quick Check:

    Permission denied fix = sudo install [OK]
Hint: Use sudo for install to avoid permission errors [OK]
Common Mistakes:
  • Ignoring permission errors
  • Trying to reinstall without sudo
  • Assuming extraction fixes install errors
5. You want to build a program from source but customize it to install in your home directory instead of system-wide. Which command should you run before make?
hard
A. sudo ./configure
B. make install PREFIX=$HOME/myprogram
C. ./configure --prefix=$HOME/myprogram
D. tar -xvf source.tar.gz --prefix=$HOME/myprogram

Solution

  1. Step 1: Understand how to customize install location

    The --prefix option with ./configure sets the installation directory.
  2. Step 2: Differentiate from other options

    Passing PREFIX to make install is less common; sudo is for admin rights, and tar does not set install paths.
  3. Final Answer:

    ./configure --prefix=$HOME/myprogram -> Option C
  4. Quick Check:

    Customize install path = configure --prefix [OK]
Hint: Use ./configure --prefix=your_path before make [OK]
Common Mistakes:
  • Trying to set prefix during make install
  • Using sudo unnecessarily
  • Misusing tar command for install path
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard