📖 Scenario: You want to install a simple program by building it from source code on a Linux system. This is common when you want the latest version or a customized build.We will simulate the steps to prepare, configure, build, and check the output of a source build process using command line commands.
🎯 Goal: Learn the basic commands to build a program from source: unpacking the source, configuring the build, compiling the code, and checking the build output.
📋 What You'll Learn
Use the tar command to unpack a source archive
Use the ./configure script to prepare the build
Use the make command to compile the source
Use the ls command to check the build output files
💡 Why This Matters
🌍 Real World
Building software from source is common when you want the latest features or need to customize the program beyond pre-built packages.
💼 Career
Many IT and developer roles require building and installing software from source to manage dependencies and customize environments.
Progress0 / 4 steps
1
Unpack the source archive
Use the tar command to unpack the source archive named example-1.0.tar.gz in the current directory.
Linux CLI
Hint
The -xzf options tell tar to extract a gzip compressed archive.
2
Run the configure script
Change directory into example-1.0 and run the ./configure script to prepare the build environment.
Linux CLI
Hint
Use cd example-1.0 to enter the source folder, then run ./configure.
3
Compile the source code
Use the make command to compile the source code inside the example-1.0 directory.
Linux CLI
Hint
Simply run make to start compiling after configuration.
4
Check the build output
Use the ls command to list the files in the example-1.0 directory and confirm the build created the executable named example.
Linux CLI
Hint
Run ls and look for the example file in the output.
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
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.
Step 2: Understand the build sequence
Extraction comes before configuration, compilation, and installation.
Final Answer:
Extract the archive files -> Option B
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
Step 1: Identify the configuration command
The ./configure script checks your system for required tools and sets up makefiles.
Step 2: Differentiate from other commands
make install installs, tar -xvf extracts, and gcc compiles single files.
Final Answer:
./configure -> Option A
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
Step 1: Understand each command's role
./configure prepares build files, make compiles the software, and sudo make install installs it with admin rights.
Step 2: Combine the steps' effects
Running all three in order results in a configured, compiled, and installed program available system-wide.
Final Answer:
The software is configured, compiled, and installed system-wide -> Option D
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
Step 1: Identify cause of permission error
Installing usually writes to system folders needing admin rights, so permission is denied without sudo.
Step 2: Apply correct fix
Using sudo make install runs install with admin privileges, fixing the error.
Final Answer:
Run sudo make install to get admin rights -> Option A
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
Step 1: Understand how to customize install location
The --prefix option with ./configure sets the installation directory.
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.
Final Answer:
./configure --prefix=$HOME/myprogram -> Option C
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 unknownstrongwhile earning +1 Grip toward your certificate.