Table of Contents

A Look Inside Linux series

A series of short topics on how Linux works and how to make it work the way you want it to, which I present during the weekly sessions of the Linux User Net. The target audience is Hams who are new to Linux and want to know more about it, as well as experienced Linux users who can learn more about their chosen operating system. These are my notes for the presentations. (Russ, KC7MM)

21: Installing software in Linux, part 2: from source code

In the previous Look Inside Linux, we covered installing pre-packaged software on a Linux system. That certainly is the easiest way to get the programs you need, and is ideal if that software is available in a package.

But what happens when you want to install an application that isn't available as a package, or you need a different version than the one in a package? You might be able to obtain the app's source code, and install it from that.

This is a feature that is exclusive to FOSSFree and Open Source Software. You can obtain and modify the source code. You can't do that with proprietary software.

What is source code?

Programming

Explain how a program is written.

Compiling

The source code itself can't be executed. In order to run the program, the plain-text source code needs to be transformed into a set of instructions that the computer's CPU can understand: machine language. That conversion process is called compiling. There are several ways of dealing with this:

  1. Compile to an executable. Many programming languages use a compiler program to read the source code, and from it create a machine-language executable file that can then be run directly on the operating system with no additional software required. The source code is compiled only once, at what is termed compile-time. This works for languages such as C and C++. (The Linux kernel is written in C.)
  2. Compile in real-time as the program is executed. Here the compilation is performed by an interpreter application: an executable program that runs on the operating system at the time the program is run. The interpreter reads the source code, then compiles and executes it one line at a time. This process is repeated each time the program is run (run-time). An interpreted program can be expected to run much slower than one that has been compiled. Most varieties of the BASIC language work this way, and it's how JavaScript is run in a Web browser.
  3. Compile to an intermediate code, which is executed in a virtual machine. This is a hybrid method that falls between the two:
    • First, a compiler reads the source code and produces a language-specific bytecode file. This is done automatically the first time the program is run, and is repeated each time the program is changed. Because it performs only part of the process of converting to machine language, it takes less time than, say, compiling a C++ program.
    • At run time, the bytecode is fed into the language's virtual machine (VM), which is effectively an interpreter for the bytecode. The bytecode and VM can be optimized to run much faster than a source-code interpreter can – though still slower than a compiled program.
    • This is how Java works. The Java JDK (Java Development Kit) contains the javac bytecode compiler that produces Class files (file extension .class) and the VM in which to run them. Python works in a similar fashion, but without the separate compiler. It automatically produces its bytecode files the first time a program is run (with a .pyc extension).

In all cases, the program needs to have the correct compiler/interpreter and environment – tools and dependencies – installed at the time it is compiled.

How is source code obtained for installation?

There are multiple ways of acquiring source code for installation:

We'll look at each one of these in turn.

Install your own code

One of the many great things about Linux is the ready availability of development tools for just about every programming language – and there are lots of them. Every Linux distro can be expected to provide the end user (you), at a minimum, the tools used in its development. The major distributions – such as Debian, Red Hat, Arch, and their derivatives – include dozens of development languages in their repositories.

If you use any of these to develop an application, you can run it using the language's tools – compiler, interpreter, VM. When the application is complete, place the necessary files at an appropriate location in the Linux file system, and you're good to go.

Install from tarball

The simplest method of obtaining the source code for an application that will compile to an executable is to download an archive file – a tarball – that contains both the program's source code and instructions that guide compiling and installing it.

What is a tarball?

It's a compressed archive file made with the tar utility. When used for program installation, it contains the source code, along with related files that are used in the process of compiling and installing the application. These latter include:

What is a MAKEFILE?

A standard utility on Linux systems is make, which can be used to control code compilation. Compiling programs can be a lengthy and complicated process. which make simplifies by allowing the developer to write a script that can be executed in lieu of having to manually run each step at the command line.

The process is configured by way of a MAKEFILE. It contains instructions regarding dependencies, file locations, compiler execution, and more.

This file is read by make, and the instructions it contains are followed to complete the compilation.

The general procedure

  1. Download the tarball into a subdirectory of your home directory.
  2. Extract the contents of the archive.
  3. At the command line, run make to compile the code.
  4. Run sudo make install to install the application on the host.

Before compiling

After compiling

Clearly, this is much more complicated that installing packages from a distribution's repository.

Install from a source code repository

An alternative to downloading tarballs is to use a source code version control system (VCS) to draw code from an online source code repository.

Git is the most widely used VCS these days. To use it for installing programs:

Getting source code for interpreted programs

Interpreted languages are too numerous and varied to be able to cover in detail. But, since there is no need to compile them, they are much simpler to deal with.

In general, installing them involves:

Finally

That wraps up our look at installing software on Linux.

This is yet another area in which Linux grants the user tremendous flexibility and power. Most of the software you'll install can be done the easy way – from a repository using a package manager. But if that doesn't work for you, there are other avenues available that are likely to do the trick. How you go about it is yours to choose.

Return to series index