Introduction
In this lab, you will learn the fundamental process of building and installing software from its source code on a Linux system. This is a crucial skill for handling applications that are not available in your distribution's package manager or when you need to enable specific custom features. You will work with a real-world example, the Pure-FTPd server, to understand each stage of the source-based installation workflow.
You will begin by extracting the source code from a compressed archive file, commonly known as a tarball, using the tar command. Next, you will prepare the build environment by running the ./configure script and then compile the source code into executable programs with the make command. Following a successful compilation, you will install the software system-wide using make install. Finally, you will learn how to properly uninstall the software and clean up the source files, completing the entire lifecycle of a source code installation.
Extract the Source Code with tar
In this step, you will learn how to extract a source code archive, commonly known as a "tarball," using the tar command. Software source code is often distributed in compressed archive files like .tar.gz to bundle all necessary files together and reduce the overall file size.
First, let's confirm that the source code archive is available in our current working directory, ~/project. Use the ls -l command to list the files and their details.
ls -l
You should see the file pure-ftpd-1.0.53.tar.gz in the output.
total 748
-rw-r--r-- 1 labex labex 765432 Nov 10 12:00 pure-ftpd-1.0.53.tar.gz
Now, we will use the tar command to extract the contents of this archive. The options we will use are:
-x: to extract files from an archive.-z: to decompress the archive using gzip, which is indicated by the.gzextension.-v: for verbose output, which lists all the files as they are being extracted.-f: to specify the filename of the archive to be processed.
Run the following command in your terminal to extract the archive:
tar -zxvf pure-ftpd-1.0.53.tar.gz
The -v option will cause tar to print the name of each file it extracts. The output will be quite long, but it should look similar to the example below, showing the directory structure and files being created.
pure-ftpd-1.0.53/
pure-ftpd-1.0.53/AUTHORS
pure-ftpd-1.0.53/README
pure-ftpd-1.0.53/README.LDAP
pure-ftpd-1.0.53/README.MySQL
pure-ftpd-1.0.53/README.PGSQL
...
pure-ftpd-1.0.53/src/puredb_p.h
pure-ftpd-1.0.53/src/pure-quotacheck.c
pure-ftpd-1.0.53/src/pure-uploadscript.c
Once the command finishes, a new directory containing the source code will have been created. Let's use ls -l again to see this new directory.
ls -l
You should now see the pure-ftpd-1.0.53 directory alongside the original tarball.
total 752
drwxr-xr-x 10 labex labex 4096 Nov 10 12:05 pure-ftpd-1.0.53
-rw-r--r-- 1 labex labex 765432 Nov 10 12:00 pure-ftpd-1.0.53.tar.gz
You have successfully extracted the source code from the archive. In the next step, we will navigate into this new directory and begin the configuration and compilation process.
Configure and Compile the Software with ./configure and make
In this step, you will configure the source code for your specific system and then compile it into executable programs. This is a standard two-part process for building software from source on Linux systems.
First, you need to change your current location to the directory that was created in the previous step. Use the cd command to navigate into the pure-ftpd-1.0.53 directory.
cd ~/project/pure-ftpd-1.0.53
Now that you are inside the source code directory, the first part of the process is to run the configure script. This script checks your system for all the necessary tools, libraries, and dependencies required to build the software. It then generates a Makefile, which contains instructions for the compilation process.
To run the script, you must type ./ before its name. This tells the shell to look for the configure script in the current directory.
./configure
The script will run a series of checks, and you will see a lot of output scrolling by. This is normal. A successful run will end with a summary, similar to the one below.
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
...
checking for OpenSSL... no
...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating man/Makefile
...
config.status: executing depfiles commands
Pure-FTPd has been configured.
Notice the lines config.status: creating Makefile. This confirms the Makefile has been successfully created.
The second part of the process is to compile the code. The make command reads the Makefile and runs the compiler (like gcc) with the correct options to turn the human-readable source code (.c files) into machine-executable binary files.
Now, run the make command.
make
This process can take a few moments. You will see many lines of output as make invokes the compiler for each source file. This is the actual compilation happening.
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /home/labex/project/pure-ftpd-1.0.53/config/missing automake-1.15 --gnu src/Makefile)
...
gcc -g -O2 -Wall -W -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -c pure-ftpd.c
...
gcc -g -O2 -Wall -W -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -o pure-ftpd pure_ftpd-pure-ftpd.o pure_ftpd-log.o ...
...
make[1]: Leaving directory '/home/labex/project/pure-ftpd-1.0.53/src'
Once the make command completes without any errors, the software is successfully compiled. The binary files are now ready to be installed on the system, which you will do in the next step.
Install the Software with make install
In this step, you will install the compiled software onto your system. After compiling the source code with make, the resulting binary files and other necessary components (like documentation and configuration files) are still within the source code directory. The make install command copies these files to the standard, system-wide locations so that the software can be run from anywhere.
Make sure you are still in the ~/project/pure-ftpd-1.0.53 directory.
The installation process typically requires writing files to directories like /usr/local/bin and /usr/local/sbin, which are owned by the root user. Therefore, you must use the sudo command to execute make install with administrative privileges.
Run the following command to install Pure-FTPd:
sudo make install
The make install command will read the Makefile and execute the installation instructions. You will see output showing files being created and copied into system directories.
make[1]: Entering directory '/home/labex/project/pure-ftpd-1.0.53/src'
/usr/bin/mkdir -p '/usr/local/sbin'
/usr/bin/install -c pure-ftpd pure-pw pure-pwconvert pure-authd pure-certd pure-uploadscript pure-quotacheck '/usr/local/sbin'
/usr/bin/mkdir -p '/usr/local/share/man/man8'
/usr/bin/install -c -m 644 ../man/pure-ftpd.8 ../man/pure-pw.8 ../man/pure-pwconvert.8 ../man/pure-authd.8 ../man/pure-certd.8 '/usr/local/share/man/man8'
make[1]: Leaving directory '/home/labex/project/pure-ftpd-1.0.53/src'
make[1]: Entering directory '/home/labex/project/pure-ftpd-1.0.53'
/usr/bin/mkdir -p '/usr/local/etc'
/usr/bin/install -c -m 644 pure-ftpd.conf '/usr/local/etc'
make[1]: Nothing to be done for 'install-data-am'.
make[1]: Leaving directory '/home/labex/project/pure-ftpd-1.0.53'
The software is now installed. A simple way to verify this is to use the which command, which searches the system's PATH for an executable and prints its full path.
which pure-ftpd
If the installation was successful, you should see the following output, indicating that the pure-ftpd executable is now located in a standard system directory.
/usr/local/sbin/pure-ftpd
With the software installed, it is technically ready for configuration and use. However, for this exercise, the next step will guide you through the process of uninstalling it.
Uninstall the Software and Clean Up with make uninstall and rm
In this final step, you will learn how to properly uninstall the software you installed from source and clean up the build files, returning your system to its original state. This is an important part of managing software manually.
Most well-written source packages that use a Makefile provide an uninstall target. This target is designed to reverse the actions of make install, removing all the files that were copied to system directories.
First, ensure you are still in the ~/project/pure-ftpd-1.0.53 directory. Just like the installation process required administrative privileges, so does the uninstallation. Use sudo with the make uninstall command.
sudo make uninstall
You will see output indicating that files are being removed from the system directories where they were installed.
make[1]: Entering directory '/home/labex/project/pure-ftpd-1.0.53/src'
rm -f /usr/local/sbin/pure-ftpd /usr/local/sbin/pure-pw /usr/local/sbin/pure-pwconvert /usr/local/sbin/pure-authd /usr/local/sbin/pure-certd /usr/local/sbin/pure-uploadscript /usr/local/sbin/pure-quotacheck
rm -f /usr/local/share/man/man8/pure-ftpd.8 /usr/local/share/man/man8/pure-pw.8 /usr/local/share/man/man8/pure-pwconvert.8 /usr/local/share/man/man8/pure-authd.8 /usr/local/share/man/man8/pure-certd.8
make[1]: Leaving directory '/home/labex/project/pure-ftpd-1.0.53/src'
make[1]: Entering directory '/home/labex/project/pure-ftpd-1.0.53'
rm -f /usr/local/etc/pure-ftpd.conf
make[1]: Leaving directory '/home/labex/project/pure-ftpd-1.0.53'
To confirm that the software has been removed, you can use the which command again.
which pure-ftpd
This time, the command should produce no output, because the pure-ftpd executable has been deleted from /usr/local/sbin, and it can no longer be found in the system's PATH.
Now that the software is uninstalled, the last step is to remove the source code directory itself. You cannot remove a directory while you are inside it, so first, navigate back to your project's root directory.
cd ~/project
Now, use the rm command with the -r (recursive) option to delete the pure-ftpd-1.0.53 directory and all of its contents.
rm -r pure-ftpd-1.0.53
This command will not produce any output if it is successful. You can verify its deletion by listing the contents of the ~/project directory.
ls -l
The pure-ftpd-1.0.53 directory is now gone, and only the original tarball remains.
total 748
-rw-r--r-- 1 labex labex 765432 Nov 10 12:00 pure-ftpd-1.0.53.tar.gz
Congratulations! You have successfully completed the entire process of building software from source: extracting, configuring, compiling, installing, and finally, uninstalling and cleaning up.
Summary
In this lab, you learned the standard procedure for building and installing software from its source code on a Linux system. You began by extracting a compressed source code archive, also known as a tarball (.tar.gz), using the tar command. Following the extraction, you navigated into the source directory to run the ./configure script, which prepares the software for compilation by checking for system dependencies and creating a Makefile. Finally, you used the make command to compile the source code into executable binaries and make install to copy the software to the appropriate system directories.
Additionally, you practiced the proper method for removing the software and cleaning up the build environment. You learned how to use the make uninstall command to remove the installed files from the system. To complete the cleanup process, you removed the original source code directory using the rm command, ensuring the system was returned to its previous state.



