Compiling and installing programs from source. The enchanting magic of configure, make and make install Installing programs on Fedora, Red Hat

💖 Do you like it? Share the link with your friends

Hi all!

This is a short note for Linux beginners about what these three wonderful commands mean and what they are needed for. Let's start, as they say, from the beginning. Most programs must be compiled before use, that is, converted from text that a person can understand into a set of ones and zeros that a computer can understand. The process is divided into three stages: configuration, assembly and installation. Details under the cut :)

./configure

This command searches for libraries and header files necessary for compilation (this is for programs partially or completely written in C/C++ and similar languages), as well as setting special parameters or connecting special libraries, if ./configure will find everything he needs, he will create Makefiles- file required to build the program

You can configure the configurator parameters using the keys and arguments of these same keys, for example:

./configure --prefix=/opt/my_program

With a key --prefix= You can specify a directory that will later act as a prefix for your program (that is, the root directory). This is due to the fact that in the world of Linux and not only, there is a special Hierarchy of the File System (HFS) according to which any program must be compiled and installed in order to work without errors.

There are three main file system prefixes against which most programs are configured, namely:

  • / - root directory of the operating system, so-called ROOT
  • /usr - directory where user environment applications are located
  • /usr/local - additional directory for user programs collected by hand, specifically to operating system didn't turn into a dump

If you open any of these directories, you can see a very similar structure, at least there will be folders: bin, etc, include, libs, sbin.

If you run ./configure without keys, then the default prefix (directory in which the compiled program will be installed) will be /usr/local, remember this, if you can’t run your program, you may not have the path to PATH.

Except the key --prefix In the configurator, as a rule, there are many other keys, you can see them all if you run:

./configure --help

make

The most important and simple command/program runs the application compilation procedure from source code. For your work this program uses special files Makefiles, which describe in detail the process of building the application with all the parameters that we specified to the configurator. The result of a successful make command will be a compiled program in the current directory.

make install

This command directly installs the application into the directory specified at the configuration stage; after executing the make install command, you can run the newly installed program.

Afterword

In order not to write three commands in turn, you can write them in one line:

./configure && make && make install

&& - this is the AND operator, which came from the C/C++ language, however, from the shell’s point of view, it means that the next command needs to be executed only if the previous command has completed successfully, this is very convenient if one of the stages ends with an error.

In fact, make install can also perform a build, because the install task depends on the all task (that is, directly building the application), this means that the make step can be skipped and only two commands can be executed if you write them on one line:

./configure && make install

Good luck to you! And thanks for reading!

terminal and commands

Have you often encountered the problem that the required version of an application for your architecture is Ubuntu distribution Simply no, but this program is available on the developers’ website in the form of source code in the .tar.gz archive. I think many people know it this situation, but not everyone continued to look for ways to solve this issue and simply looked for another analogue of the application or a slightly older version and continued to work.

I would immediately like to add a few words for newcomers to Linux; before doing anything from this article, thoroughly study the terminal and the commands that are used to work with it, read mana or materials on the net.

  • For application builds we will, of course, need developer tools, in our case this is a compiler and other accompanying programs; the main work, of course, will be done by the make utility, and command line(the terminal) will be like our kitchen where we will be prepare/assemble/install our application from source. IN Linux terminal available by default, for your convenience you can of course install any other more functional one that you are used to, for example I use Guake, there are a lot of possibilities compared to the standard one, where it is easy to configure both copying and pasting commands or any text using CTRL +C,CTRL+V and much more, which makes working with the console more comfortable.
  • 1. Where to start when building applications from source is, of course, download the application in the tar.gz or tar.bz2 archive, in my case this is, for example, the Gimp 2.9.2 application, although in our case the archive is not in tar.gz format, and tar.bz2, it doesn’t make any difference, download it, then right-click on the archive - Extract here.

This is probably the first stage, what do we do next? And then we launch the terminal and go to our unpacked folder with files:

Cd /home/linux/Downloads/gimp-2.9.2/ ls

  • 2. Before starting to prepare the sources for assembly, I would advise you to first open and familiarize yourself with the INSTALL file, you will find a lot useful information, V this file describes how to install the application, what commands need to be executed and much more interesting things. Now I advise you to install an additional package called - auto-apt, it does a lot routine work instead of you.
sudo apt-get install auto-apt

What does it mean to do a lot of routine work for me, you ask, if run application source configuration with the prefix of this package, for example in the form:

Auto-apt -y run ./configure

Of course, you can perform the configuration without the help of this package and simply run the command:

./configure

If you perform the configuration with the prefix - auto-apt -y run, then preparing sources for assembly will take place in automatic mode, that is, this command can automatically download and install everything for you necessary files and libraries and will satisfy everything dependencies which will be required.

  • 3. When real work not everything is so smooth, maybe in one case everything will go well and stage of preparing source code for assembly It will pass without errors, but in other cases, and these are probably the majority, you will encounter errors of various kinds, for example, there is not enough of one or another package for further preparation of the source code. In most cases, the name of the package that is missing is written.

We try to install the missing package with the command:

Sudo apt-get install package_name

In the event that a package is not detected when executing the command above, the following combination very often helps me out; we look for packages that we are missing in the cache:

Apt-cache search pakage_name

  • After executing this command, you may find a suitable package, it often happens that you do not find a suitable package, but you can find an exact copy of the package but with dev prefix that is, a package like package_name-dev and you can use it to satisfy dependencies.
  • 4. After successfully completing the configuration of the sources for the build, it is advisable to install the package checkinstall which makes it easier to assemble an application package for your distribution.
sudo apt-get install checkinstall

Install the package, then you can run the command:

Checkinstall -D

  • Attribute -D will create a deb package, attribute -R will create an rpm package that is used in the distributions of Fedora, RHEL, ASP Linux, ALT Linux, Mandriva, openSUSE, there is also an additional attribute -S which will create a package used in Slackware.

In my case I am running on Ubuntu and ran the command with attribute -D, then we will assemble the application into a ready-made Deb format package, we will need some clarifying data, for example, such as adding a description to the package, since you are assembling it and, accordingly, the description is completely clean and, as it were, you are required to provide a brief reference about what kind of application this is for what . In my case, as I checked, the following fields are also automatically filled in:

1 - Summary: [ EOF ] 2 - Name: [ gimp ] 3 - Version: [ 2.9.2 ] 4 - Release: [ 1 ] 5 - License: [ GPL ] 6 - Group: [ checkinstall ] 7 - Architecture: [ i386 ] 8 - Source location: [ gimp-2.9.2 ] 9 - Alternate source location: 10 - Requires: 11 - Provides: [ gimp ] 12 - Conflicts: 13 - Replacements:

  • As you can see, before the build there is a check to see if the configuration was completed successfully, if there are any unsatisfied dependencies or other conflicts; if everything is fine, then the package will be built without problems.

I previously installed it without building the package, running the commands:

Make make install

If you want to delete installed application, you should run the command:

Make uninstall

the command above will automatically delete those related to the application that you installed and will not affect anything third-party, it is advisable not to run through directories and execute it from the same application directory in which you worked, that is, prepared the configuration, etc.

Although everything went without errors, the whole process lasted a very long time, about 20 minutes until I installed Gimp from the source code, I managed to go make coffee and also watch the installation process, everything happens for a long time due to the fact that there are a lot of different folders scatter the application source files, each file has its own purpose and must be located in a specific directory, so after executing make install, the process of installing thousands of source files in the required directories occurs.

This is how installation of an application from source happens, yes, not everything is so simple at first glance, I didn’t say that it would be easy, but if you try, it very well develops your thinking and ways of finding solutions in a given situation, which It's even very good.

That's probably all, if you have questions about the material above, or you tried to install and encountered errors, ask in the comments to the material, we will look for a solution together.

There was a desire to get acquainted with development for Android. I downloaded Android Studio, unpacked it and deleted it. I decided to look for other installation options. While searching, I came across Ubuntu Make (aka Ubuntu Developer Tools Center in the past), and in this short note I want to tell you about it.

Ubuntu Developer Tools Center flashed in the news along with Ubuntu 14.10 (Utopic Unicorn), but, it seems to me, it did not attract widespread attention. Not much later, the project was renamed Ubuntu Make, as it is called to this day, having grown to version 0.4. The development is carried out by Didier Roche, Software Engineer, Canonical. Also noteworthy is the fact that Ubuntu Make is written in Python 3.4.

The main goal of the project is to quickly and easily install common developer needs in Ubuntu. And although it’s still a long way from “general needs” (the list of packages available for installation is still small), with “quick and simple” everything is fine.

On this moment Using Ubuntu Make you can install:

  • Android Studio
  • Eclipse
  • IntelliJ Idea Community Edition
  • PyCharm Community Edition
  • go-lang Google compiler
  • Stencyl game developer IDE

Installation

In ubuntu 15.04, ubuntu-make is available out of the box, users of versions 14.04 and 14.10 are asked to install from ppa:

Sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make sudo apt-get update sudo apt-get install ubuntu-make

Usage

Installation with ubuntu-make is incredibly simple. For Android installations Studio just run in the terminal:

Umake android
A little wait and here is the result:

Icon in dash and openjdk (if Java was not in the system) included. After launch, the “studio” pulled up the sdk and updated to version 1.0.2. “Hello world” was launched on the phone and the functionality test was completed.

Golang is installed similarly:

For PyCharm, Eclipse, Idea, one more argument will be added:

Umake ide pycharm

To remove a package, just add the "-r" argument to the same line:

Umake ide pycharm -r

Opinion

Someone will say: “There’s a lot to do. Download the archive, unpack it, check the icon in dash and check it in Java. Is it necessary ubuntu make?. I agree, there might not be a lot to do, but I found the package useful for myself. He saved me time and got rid of the routine. I hope it will be useful to you too.

The bottom line is that this command in the form of “make install” or “sudo make install” cannot be used in modern distributions.

But the authors of the programs in the installation manuals write that you need to use this command, you might say. Yes, they write. But this only means that they don’t know what distribution you have, or whether it’s a distribution at all, maybe you joined a sect and smoked reading LFS and now decided to compile their creation for your chthonic system. And make install is a universal, although often incorrect, way to do this.

Lyrical digression

As you know, for normal operation, most software must not only be compiled, but also correctly installed on the system. Programs expect to find the files they need in certain places, and these places on most *nix systems are hard-coded into the code at compile time. Besides this aspect, the main difference between the installation process in linux/freebsd/whatever and that in Windows and MacOS is that the program does not just put a bunch of files in a separate directory in Program Files or /Applications, but “spreads” itself throughout the entire file system. Libraries go to lib, executable files to bin, configs to etc, various kinds of data to var, and so on. If you suddenly need to update it, then all this must first be cleaned somehow, because... using new version Remnants of files from the old one can lead to completely unpredictable consequences, often not good. The probability of this event is not so high, but do you need it on a production server?

So what?

So, if you did the installation directly via make install, then it’s normal to remove or update the software, you most likely you can't. Moreover, installing a new version over the old one will most likely will overwrite your changes in configs. make install does exactly what it is told to do - it installs files in the right places, ignoring the fact that something is already there. After this process, it is absolutely impossible to obtain any information about what was placed where and in a digestible form. Sometimes, of course, the Makefile supports the uninstall action, but this is not so common, and it is not a fact that it works correctly. In addition, storing the unpacked source tree and build rules for uninstallation is somehow strange.

How to fight?

Since packages in distributions tend to be updated sometimes, to solve this problem they came up with such a thing as a package manager. When using it, the installation goes something like this:
  1. an archive formed in a certain way is taken
  2. information is extracted from it about what it is, what version it is, what it depends on, what it conflicts with, whether it is necessary to run any scripts to install/uninstall/configure, etc.
  3. Direct installation steps in progress
  4. All data about where and what was delivered is added to the package manager database.

In this case, when updating, you can painlessly remove unnecessary things, and at the same time see if the files marked as configuration have changed in the system and ask what to do if their contents are different in the new version. In addition, the package manager will not allow you to overwrite the files of one package when installing another. In general, a lot useful things he can do.

If you, out of ignorance/laziness, copied and pasted make install from the instructions, then files appear on the system that the package manager does not know about. With all that it implies, if what was listed earlier is not enough for you.

What to do?

You can, of course, configure the source tree so that everything is installed somewhere in /opt/mycoolapp/, and then, if necessary, delete it manually, but a lot of unpleasant things can come out here, starting with the fact that the program expects that it can load your libraries, and the loader knows nothing about the directory where they are located, ending with the fact that the program author can expect that, for example, if he puts a file, say, in $prefix/share/xsessions/, then the display manager will pick it up. Not to mention the paths for pkgconfig and so on.

So you need to collect the package.

I don’t have time to fuck with this, I’d better do make install again, everything is simple and clear!

Calm down, calm down. He's tied to our legs. Everything is not as scary and complicated as it seems at first glance.
checkinstall
This wonderful utility, when launched instead of make install, will ask several questions, after which it will build and install the package. That’s it, when updating you won’t have any problems with cleaning out old junk.
Building the deb package manually
If you are not inclined to trust such automation (which sometimes still messes up) or you want to make a couple of changes, but are still too lazy to deal with the normal process of building packages, then you can assemble the package manually. I present a way to build it for Debian-based systems, since I am most familiar with them. It is not ideologically correct, but the output is a completely correct package without the use of additional entities. This is done as follows.
First, we assemble the software with the --prefix=/usr and --exec-prefix=/usr parameters pre-specified for configure or autogen.sh.
Next, we install it in a temporary directory. We write:

Fakeroot make install DESTDIR=`pwd`/tempinstall
After which we get the entire set of files in the newly created directory. By the way, we are now in a fakeroot environment, i.e. you can change the owner and access rights of files without any restrictions, but physically you will remain the owner of the system. The software inside the fakeroot session will receive changed information, which will allow files with the correct rights to be archived.
Next, create a DEBIAN directory in the “package root” and add a list of all files that should go into /etc into DEBIAN/conffiles:

Cd tempinstall mkdir DEBIAN find etc | sed "s/^/\//" > DEBIAN/conffiles
Then we create a file DEBIAN/control with the following content:

If necessary, you can also create preinst, postinst, prerm and postrm scripts there.

That's it, we do dpkg -b tempinstall and the output is tempinstall.deb, which you can use dpkg -i to install, update or remove correctly.

The “correct” process of preliminary creation of a source code package is beyond the scope of this note, and therefore will not be described, but for your purposes it is usually not necessary.

Conclusion

As you can see, there is absolutely nothing complicated here, but following these steps will save you from a huge number of problems in the future.

Often the necessary packages can only be found in source form; this article describes a method for installing a package from source code.

Unboxing

Programs are usually distributed in packaged archives, these are files with the extensions

.tar.gz (sometimes .tgz) .tar.bz2

You need to understand the difference between an archiver and a packer.

The program is used to archive directories and files tar; the result of its work is a file with the extension .tar. Roughly speaking, this is a copy file system- directories and files with their attributes and access rights, placed in one file.

This file will be slightly larger in size than the total size of the files that were archived. Therefore (or maybe for another reason) they use packers - programs that allow you to reduce the file size without losing data.

Program tar can unpack, so no need to call gunzip, or you can simply tell the program tar that the file must first be unpacked. For example, the command

tar -xvf< some_app_name>.tar.gz

will immediately unpack and unzip. Difference between files and extensions

.tar.gz

.tar.bz2

only that different packers were used, the program tar determines the compression method automatically and no additional options are required in this case.

After unpacking, you need to go to the resulting directory; all the commands described below are executed in the directory with the source code of the package.

CD< имя_пакета>*

Building the package

To build programs in GNU/Linux, you use (mostly) the program make, which runs instructions from Makefile, but since there are many GNU/Linux distributions, and they are all different, in order to build the program, for each distribution you need to separately specify the paths where the libraries and header files are located. Programmers cannot study each distribution and create separately for each Makefile. Therefore, they came up with configurators that “study” the system and, in accordance with the knowledge gained, create Makefile. But they didn’t stop at the configurator and came up with configurators of configurators...that’s where they stopped

To build we need compilers: they are specified in the package dependencies build-essential, so it's enough to install it with all the dependencies. Still needed autoconf And automake.

So, to build something from source, you first need to build a configurator; how to build the configurator is described in the configure.in file. To build the configurator you need to run

./ bootstrap ./ autogen.sh

If there are no such scripts in the archive, you can run the following commands in sequence:

aclocal autoheader automake --gnu --add-missing --copy --foreign autoconf -f -Wall

All of these commands use the file configure.in. After executing these commands, a file will be created configure. After this, you need to run the configurator to check for the presence of all dependencies, as well as install additional build options (if possible) and view the installation result (optional - may not be present)

./ configure

The configurator will build a Makefile based on the knowledge gained and the file makefile.am. You can pass to the configurator the options provided in the program sources, which allow you to enable/disable certain program features; usually you can find out about them with the command

./ configure --help

There is also a set of standard options, like

Prefix=

Which specifies which directory to use for installation. Usually for Ubuntu

--prefix =/ usr --prefix =/ usr/ local

WITHOUT slash at the end! Now you can start the process of building the program itself with the command

make

Enough privileges to build regular user. The end of the build can be considered the moment when the commands in the console stop being executed “randomly” and there is no word error. Now everything is compiled and ready for installation.

Installation

Efforts spent on Correct installation in the future, they will more than pay for themselves in the event of uninstalling or updating the installed software.

Correct installation(Option No. 1)

Installation using the utility checkinstall. To install:

sudo apt-get install checkinstall

Minus this method: checkinstall does not understand all sources, since the program author can write special installation scripts and checkinstall won't understand them.

To create and install a deb package you need to run

sudo checkinstall

Correct installation (Option No. 2)

Quickly create a deb package manually.

Main difference from previous method is that in this case you create the package manually and track all the changes you make. This method will also suit you if the sources do not support building the package with checkinstall.

    We install in a temporary directory, where we get the entire set of installed files:

fakeroot make install DESTDIR=`pwd`/tempinstall

    Let’s create a DEBIAN directory in the “package root” and add a list of all files that should go into /etc into DEBIAN/conffiles:

cd tempinstall mkdir DEBIAN find etc | sed "s/^/\//" > DEBIAN/ conffiles

    Then we create a file DEBIAN/control with the following content:

Package: package_name Version: 1.2.3 Architecture: amd64/i386/armel/all Maintainer: You can enter your name, you can rubbish, but if you leave it empty, then dpkg will swear Depends: Here you can enter a list of packages separated by commas. Priority: optional Description: You also need to enter something so that there are no warnings

    If necessary, you can also create preinst, postinst, prerm and postrm scripts there.

    We create a deb package, for which we execute:

dpkg -b tempinstall

    The output is tempinstall.deb, which we install

sudo dpkg -i tempinstall.deb

Installation (option No. 3)

Incorrect installation

The disadvantage of this method is that if you install directly via make install, then you most likely will not be able to remove or update the package normally. Moreover, installing a new version over the old one will most likely overwrite your changes in the configs. make install does exactly what it is told to do - it installs files in the right places, ignoring the fact that something is already there. After this process, it is absolutely impossible to obtain any information about what was placed where and in a digestible form. Sometimes, of course, the Makefile supports the uninstall action, but this is not so common, and it is not a fact that it works correctly. In addition, you will need to store the unpacked source tree and build rules for uninstallation.

To install you need to do

sudo make install

To remove a package installed using this method, you must execute it in the root directory of the program's sources (where you ran make install).

sudo make uninstall

Errors

Often at the configuration stage, the configurator reports that a particular library is missing. The library name it reports doesn't always match the package name in Ubuntu. From my own experience, I can advise you to search Synaptic for the required package, excluding the lib prefix. If you find several packages that differ with the prefix -dev in the name, then you need to install the -dev package (usually it also entails a non-dev package). You can also search using http://packages.ubuntu.com/ by entering the library name into the search for package contents, similarly, if you find dev and non-dev, you need both. Well, or just search on Google.

Required Software

Packages with mm at the end of the description are packages for C++ programs. List for bmpx, but suitable for almost any GTK2/Gnome program. So if you can’t assemble it, then look at this list and compare it with what you have installed.

Compile:Runtime:
Xlibx11-devlibx11-6
GlibMMlibglibmm-2.4-devlibglibmm-2.4-1c2a
GTK+libgtk2.0-dev,gtk-doc-toolslibgtk2.0-0
GTKMMlibgtkmm-2.4-devlibgtkmm-2.4-1c2a
Gladelibglade2-devlibglade2-0
GladeMMlibglademm-2.4-devlibglademm-2.4-1c2a
XMLlibxml2-devlibxml2
XML++libxml++2.6-devlibxml++2.6c2a
DBuslibdbus-1-dev,libdbus-glib-1-devlibdbus-1-2,libdbus-glib-1-2
Alsalibasound2-devlibasound2
HALlibhal-dev,libhal-storage-devlibhal1,libhal-storage1
Gaminlibgamin-devlibgamin0
Neonlibneon25-devlibneon25
TagLiblibtagc0-devlibtagc0
Startup-Notifylibstartup-notification0-devlibstartup-notification0
Boostlibboost-dev,libboost-filesystem-devlibboost-filesystem1.33.1
MusicBrainzlibmusicbrainz4-devlibmusicbrainz4c2a
GStreamerlibgstreamer0.10-dev,libgstreamer-plugins-base0.10-devlibgstreamer0.10-0,libgstreamer-plugins-base0.10-0


tell friends