How to compile that game / program I just downloaded

Let's suppose you have just downloaded the source code of your favorite game or program and want to compile it to be able to enjoy it. How to carry out such a titanic task? Don't worry, compiling and installing that game / program on Linux is not as difficult as it sounds.

Build and install procedure

Whenever you download the source code of a program, it will come compressed into a file that, on Linux, is generally of the type tar.gz or tar.bz2. Sure, it can come in any other format (zip, for example), but that's usually the rule.

So the first step is to unzip that file. The easiest method is by opening Nautilus, right-clicking on the file in question, and selecting Decompress. The method that we will see here, however, is the one used by the terminal.

Once the file is unzipped, a directory will be created, which we must access and from which we will start the configuration and compilation of the program.

When you do all this from the terminal, the commands to use are:

tar xvzf package.tar.gz (or tar xvjf package.tar.bz2) cd package ./configure make make install

These are the commands that one must generally follow, but it would be advisable to analyze each of these steps in greater depth, to understand well what they imply.

Step 1: decompression

The extension tar.gz or tar.bz2 means that the source code you downloaded is compressed into a tar file, also known as a tarball. This greatly simplifies the dissemination of the source code since all the files and folders that comprise it are packaged within a single file. Once packaged, within the tar file, that file is compressed using the gz or bz2 algorithm, depending on the developer's taste.

To unzip a tar.gz file, I wrote:

tar xvzf package.tar.gz

In case of a tar.bz2 file:

tar xvjf package.tar.bz2

In most cases this will create a folder within the directory where the compressed file is located. The folder name will be the same as the compressed file.

Step 2: configuration

Once you entered the folder created by unzipping the tar.gz or tar.bz2 file ...

cd folder

… Time to configure the package. Usually, but not always (that's why it's important to read the README and INSTALL files), this is accomplished by running the setup script:

./configure

When you run this script, nothing will be installed yet, only the system will be checked and values ​​are assigned to some system-dependent variables. These values ​​are used to create a Makefile. The Makefile, in turn, is used to create the binary file that, at the end of the story, will allow the program to run.

When you run this command you will see that the screen fills with a lot of somewhat cryptic messages. In case of error, a message will appear; and if all goes well, we can jump to the next step. 🙂

Step 3: building the binary

It is time to build the binary file, which is nothing more than the executable of the program. In other words, this procedure involves the transformation of files written in a high-level programming language to pure zeros and ones, that is, the only language our computer understands.

make

For this command to be successful, the previous step must have been successful. Without the Makefile, make will fail. This is why it is so important that the setup script runs successfully.

Yes, the screen will fill with strange messages again and it will likely take a while to finish. That will depend on the size of the program and the speed of your computer.

Step 4: installation

Sure, we already have the executable but its installation is missing. This step must be done with administrator privileges.

sudo make install

As in this hypothetical case we have not made any changes to the configuration file, the program will be installed in the default folder. In general, this is usually / usr / local / bin since it allows that from any side when writing the name of the program it is executed (without having to enter the complete path of the program).

Step 5: Execution

No, we did not kill anyone. It is simply the culminating step of the entire build and installation process. To run the program that we so painstakingly converted to a binary, I wrote:

./program name

If the program was installed in another folder, other than / usr / local / bin, you must enter the full path of the program.

Cleaning up the ranch

In case you are very, very low on disk space, you may want to delete all files created during the binary build process. In that case, I accessed the folder created by unzipping the file and typed:

make clean

Note: be sure to keep your Makefile. This file will be necessary when uninstalling the program in the future.

Uninstallation

The program was not what we expected and we want to erase it from the face of our system. How? Is the program I just installed not showing up in the Software Center or Synaptic? And now?

In case you have not deleted your Makefile, it is possible to uninstall the program easily. I wrote the following command inside the folder created when unzipping the file:

make uninstall

If you were unlucky and the uninstallation was unsuccessful, there will be no choice but to delete the files by hand. A real headache. To find out where these files are, you can take a look at your Makefile.

In case you have deleted the Makefile, it is best to reinstall the program, and then do makeuninstall, as this will regenerate the Makefile. Do not forget to install it using the same settings (in this case none) in the ./configure.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Alex said

    Good tuto thank you very much, always when we start in linux one of the main problems is how to compile, well explained, although it is advisable to read the readme or install ...

  2.   Alex said

    Good tuto thank you very much, always when we start in linux one of the main problems is how to compile, well explained, although it is advisable to read the readme or install ...

  3.   emiliano perez said

    «If you were unlucky and the uninstallation was unsuccessful, there will be no choice but to delete the files by hand. A real headache »

    It is more advisable to reinstall it, and then do "make uninstall" since we will have the Makefile re-generated. It is important to install it using the same configurations (in this case none) in configure.

  4.   Juan said

    now if you don't want to run it by putting the name of the program but create a shortcut to the desktop or have it appear in the applications menu, how do you do?
    regards!

  5.   kiwi_kiwi said

    Good tutorial. Now even I can compile.

  6.   marcoshipe said

    I think that the second step would be to read the readme (RTFR xD) and it is the most fundamental of all, since many programs have dependencies that you must fulfill in the installation, or some extra step is needed or it is also good that you read it because it provides good options for the make that may interest us.

    regards!

  7.   Let's use Linux said

    Completely! That is why I recommend always reading README and INSTALL.

  8.   Let's use Linux said

    You are right. That, in case you don't have the Makefile. I was talking about the case that even having the Makefile it could not be uninstalled for some other reason.
    Anyway, I'm going to add your comment to the post, which I think is very pertinent and accurate.

    A hug and thank you for commenting! Paul.

  9.   Let's use Linux said

    Tudo bem Krafty! Nobody is offended. I wrote this post because I had never covered the topic on the blog. Anyway, I take note of the topics you recommend (some very good ones). Surely, I will write about them in the not too distant future.
    A big hug and thank you for leaving your comments! Paul.

  10.   crafty said

    I don't want to be mean, but this topic has already been discussed several times so far this year.

    I propose some topics so that you can see that I do not leave a comment just to make a bard.

    - Telephony over IP
    - Different Torrent Clients (which one to choose).
    - Creation of scripts of those things that we have repeatedly in the console.
    - Remove modules to the kernel so that it initializes Linux more quickly when booting.

    I hope I have not offended / bothered anyone

  11.   guest said

    great, great for those of us who started to get loose with linux

  12.   Let's use Linux said

    Yes. Generally, these are detailed in the README. Otherwise, when compiling an error will appear and based on the error (which will tell which library is missing) we will have to install the appropriate dependency.
    A hug! Paul.

  13.   Cellos said

    Krafty, you're really bad without a doubt. Where have you seen a tutorial like this, so clear and explanatory? for me it is excellent, salu2,

  14.   rv said

    Thank you very much for the guide! It helped me to clarify some things 🙂

    By the way, a tip that has worked quite well for me to resolve the issue of dependencies is to do first of all 'sudo apt-get build-dep program_name'; I don't know if it works in all distros, I have used it in Debian (Squeeze, where I recently compiled MuseScore 1.2 to alleviate the archaic repos of the stable branch ... 😉

    I imagine that someone more informed will be able to give finer details 🙂

    Regards!

  15.   rosgory said

    Shouldn't we take into account the dependencies the program needs before compiling?

  16.   Diego Garcia said

    I have little time using linux, and this is one of my biggest doubts, this will be very useful to me since I had not found any post with this particular topic 😀
    or do you know any?
    Greetings ..

  17.   frameworks said

    great, I had not seen this post, but that is because of a type 1 error or type 2 error

  18.   ibon said

    Is there no other method?
    This method I have already used successfully. The problem is that there are many, many source code programs that do not use this system, we do not have the configure script. I would like how to compile them.