Docs/Basic tasks/Installing and removing software/Installing from source
Aus Mandriva Community Wiki
Achtung: dieser Artikel bedarf einer Übersetzung! Wenn du dabei helfen möchtest, schaue einmal hier vorbei.
Installing software by building it from the raw source code is the least favored installation method on Mandriva Linux, and should only be used if you cannot find the software you require in any of the official or third party Mandriva software repositories (for more details on other software installation methods, see this page). Sometimes, however, it is unavoidable. This page contains a discussion of the general method for installing software by compiling it from source code on Mandriva Linux.
Inhaltsverzeichnis |
[bearbeiten] Before you start
Before you start, it is best to understand in a general form what is involved in building software from source code, and to do some preparatory organization.
[bearbeiten] What will happen
When you install software from source code, usually three steps take place. In the first, a script will analyze your system, check that all the necessary software is installed for the compilation to succeed, and sometimes configure optional facets of the compilation process. In the second, the code will actually be compiled. In the third, the compiled application, libraries and support files will be copied to the appropriate directories on your system for all users to be able to access them. In the case of very simple software, the first step may not be used; also, some applications are designed so that you can run them without performing the third step.
[bearbeiten] Preparation
It is important to keep the source code available even after you successfully install the application, as without it, it will be very difficult to uninstall. You will therefore probably want to keep your source code neatly organized. It's probably a good idea to create a directory named source or src in your home directory, and keep the source code for any applications you compile in subdirectories of this directory. You will also need to make sure you have some basic applications, needed for almost any software compilation, installed. Install the gcc package, if it is not already installed. Before trying to compile any application, always read any documentation files included in the archive. There will often be a file named INSTALL which contains specific installation instructions and information for the application.
[bearbeiten] Step 1
For most applications, step 1 is accomplished by running the command ./configure in the top level of the source code directory. If the configuration process completes successfully, this script will exit either with no error messages or with a summary of exactly how the software will be compiled - which options will be enabled, and possibly where it will be installed. More complex and mature software will usually have several optional parameters to the configure command which can be used to enable or disable features of the software. You can use the command ./configure --help to list these optional parameters and see if any would be of use to you. In most cases you should not use the --prefix, --sysconfdir or --localstatedir options.
[bearbeiten] Variations
As noted above, for some simple applications, the ./configure stage is omitted entirely. In this case, go straight to #Step 2. In some other cases - usually only for immature software or for unstable snapshots - you will have to run another command before you can run ./configure: ./autogen.sh. This creates the configure script and the files it needs to generate Makefiles (which are the scripts that control the actual compilation process). More unusually, applications may use a completely different compilation system from the traditional one detailed on this page. In this case, it will almost certainly be documented in a README or INSTALL file included with the source.
[bearbeiten] Problems
It is not unusual for this step to fail, particularly the first few times you attempt to install something from source. The configure script will exit with an error suggesting a package or library is not installed. Often, you will find that the package it complains about actually is installed.
Don't panic! This is due to a Mandriva packaging convention. In Mandriva Linux, shared libraries - collections of functions which are stored in common directories and can potentially be used by more than one application - are packaged separately from applications. The library packages are then further split up. Some libraries are only ever useful for compiling: they are never used simply to run applications. In Mandriva Linux, the libraries necessary to actually run applications are contained in one package, and the libraries only useful for compiling are contained in another package. So for the fairly typical situation of an application with an associated library, Mandriva Linux will usually contain three packages. If the application were named 'example', these would be named something like the following:
example libexample libexample-devel
There may be version numbers in one, two or all three packages, but this basic pattern will usually be followed. The 'example' package contains the actual application, configuration files, menu entries, and associated data like sounds, graphics, translations and so on. The 'libexample' package contains the files for the library associated with the application which are useful for running the application (and any others which wish to use the same library). The 'libexample-devel' package contains the files for the library associated with the application which are only useful for compiling applications which use the library.
If you were trying to compile something from the source code, and the configure script were exiting with an error that 'example' was not installed, then it is most likely that the package you actually need to install is libexample-devel.
There will often (again, most often the first few times you try to install something from source) be several -devel packages required that you have not yet installed, so when you install one and re-try the configure script, it will fail again, this time complaining that another package is missing. Persevere and install all the required -devel packages, and eventually the step will succeed.
[bearbeiten] Step 2
Once you have successfully completed Step 1, it's time to move on to Step 2 - compilation. This is usually accomplished by running the command make in the top level directory of the source code. For well-written applications, if the configure script completed successfully, this stage should also complete without problems. In this case the process will run for a period of time (depending on how complex the application is and how fast your system is, this could be anything from a few seconds to several hours) and then exit with a brief completion message: as long as no error is displayed, the process was successful.
[bearbeiten] Problems
Many applications are not perfectly coded, and the authors will forget to write a check in the configure script for a library that is actually required during compilation. In this case, the compilation process will suddenly fail and spit out several error messages. To discover what went wrong, you usually need to look at the first error message. Often this error will complain that -lSOMETHING is not found. This means that a required development library was not installed, just as was discussed in Step 1. Usually the name SOMETHING will bear some resemblance to the name of the required package, but sometimes this can be quite hard to work out. If you cannot work it out, you can try using Google to search for the error message, or you can post a help request on a Mandriva help forum (such as the Mandriva forums or to the site for the application you are trying to compile. You should also check the README and INSTALL files in the source code, as these may well list the required packages. Install the relevant package, then re-run the make command, and it should pick up more or less where it left off. There is no need to restart the process from Step 1.
If the compilation process fails with some other kind of error, you will usually need to request help from an expert in a Mandriva help forum or on the site of the application you are trying to install.
[bearbeiten] Variations
Variations at this stage of the procedure are rare, but occasionally you may need to run the make command with extra parameters to compile optional parts of the application, or run the command again in a subdirectory. Such variations will almost always be outlined in the README or INSTALL files.
[bearbeiten] Step 3
If you successfully completed Step 2, you may now choose to install the application. This involves copying the completed files to directories where they will be available to all users, and (if appropriate) the shared files will be available to other applications. This step is usually accomplished by running the command make install with root privileges (to become root, run the su command and enter your root password: remember to exit after running make install).
In most cases, the application will install in the /usr/local directory. The executable(s) will be placed in /usr/local/bin, libraries will be placed in /usr/local/lib, configuration files will be placed in /usr/local/etc, and other data files will be placed in /usr/local/share. This is a valuable convention: Mandriva Linux (and all other distributions) will never install anything to /usr/local and will never touch any file inside that directory, so you can be very confident that any file in that directory wound up there either as the result of you compiling and installing an application from source code, or as the result of a command you ran manually. If you follow this convention, nothing you install from source code can become inextricably entwined with parts of the system installed by the Mandriva packaging tools.
[bearbeiten] Variations
Occasionally you may come across an application which defaults to installing itself into the system directories: /usr/bin for executables, /usr/lib for libraries, /etc for configuration files, and so on. This is extremely bad behavior as it can cause applications compiled from source to become confusingly and possibly damagingly confused with applications installed by the Mandriva packaging tools, and this behavior should be considered a serious bug in the application unless it absolutely cannot function properly unless it is installed to the system directories. This behavior should be reported as a bug to the application's developers.
[bearbeiten] Problems
It is very unusual to encounter problems during the actual running of this step: if you do, you will need to ask for expert assistance. It is more common to find that you still cannot run an application after installing it using this procedure. This is because the default Mandriva Linux environment does not account for applications installed to the /usr/local directory.
[bearbeiten] command not found
If trying to run the application with the correct command returns a 'command not found' error, first try running the command hash -r, then try again. If this does not resolve the problem, the /usr/local/bin directory may not be in your PATH. PATH is an environment variable which lists directory names containing executables: any executable in a directory listed in PATH can be run simply by typing its name, without specifying which directory it is in. To add /usr/local/bin to your PATH a single time, run the command export PATH=$PATH:/usr/local/bin. To ensure that /usr/local/bin is added to your PATH each time you start the system, edit the file ~/.bash_profile. If there is an existing line reading something like:
PATH=$PATH:$HOME/bin
add /usr/local/bin to the end of it, like so:
PATH=$PATH:$HOME/bin:/usr/local/bin
If there is no such line, then add these two lines:
PATH=$PATH:/usr/local/bin export PATH
After making any changes to PATH, run the command hash -r.
[bearbeiten] libraries not found
If you can run the application but it crashes and complains about being unable to find library files, you need to add the /usr/local/lib directory to the list of directories where the system will look for shared libraries. To do this, edit the file /etc/ld.so.conf - you will need root privileges - and add the following line at the bottom:
/usr/local/lib
Save the file, and run the command ldconfig, also with root privileges. You only ever need to do this once.
[bearbeiten] pkgconfig problems
There is another more obscure problem you may occasionally run into. Some applications - usually GNOME applications - use a system called pkgconfig. This is used when compiling applications as a standardized way to test whether the necessary development libraries from another application are present. If you install an application or library from source that uses the pkgconfig system to let other applications know it is available for compilation purposes, it will install a file named programname.pc to the /usr/local/lib/pkgconfig directory. If you then attempt to build another application which relies on this first application being present, it may complain that it cannot find the first application. This is because the /usr/local/lib/pkgconfig directory is not being taken into consideration by pkgconfig when looking for available libraries. To resolve this problem once, run this command: export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig. To resolve it permanently, add the following two lines to the file ~/.bash_profile:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH
[bearbeiten] Uninstalling
Uninstalling a piece of software you compiled from source is usually as simple as running the command make uninstall (with root privileges) from the top level of the source code directory. Very occasionally, you will be unfortunate enough to come across a piece of software which implements make install but does not implement make uninstall. This is extremely bad behavior and should be reported as a bug with the highest possible priority to the software's maintainers. In this case, the only way to uninstall the software is to manually locate all the files it installed and remove them. As discussed earlier, they will most likely all be located in the /usr/local tree.
If you installed from source, lost the source code, and then wish to uninstall, you have two options. You can manually locate and remove the files, as with applications that do not implement make uninstall. However, there is a useful trick which will save you the trouble in most cases. You can simply re-download the same version of the source code, run through Step 1 and Step 2 in the same way you did when you first installed the application, and then run make uninstall with root privileges.
[bearbeiten] Advanced topics: installing to system directories
Occasionally you will come across an application that will not work correctly unless installed into the system directories - that is, it cannot be installed to /usr/local and work correctly. This will usually be noted in the INSTALL or README file. In this case, you must use some parameters to the ./configure script to tell it where to install the application's files. In this case you should take extreme care not to get the version of the application installed from source confused with a version of the application installed from a Mandriva package. If you wish to install an application from source in this way, first ensure any packaged version of the application is removed, and do not install any packaged version of the application after installing from source until you have completely uninstalled the source compiled version. It is almost never a good idea to install an updated version of a commonly used library in this way, as other software on the system may well not work with the updated library.
To make an application install to the system directories, use the following configure command: ./configure --prefix=usr --sysconfdir=/etc --localstatedir=/var.
[bearbeiten] Advanced topics: generating RPM packages
If you find yourself compiling a lot of software from source code, you may wish to turn it into RPM packages instead of installing it directly, either for your own convenience in installing, removing and tracking it, or for contribution to the Mandriva repositories. If you are interested in this, please read the documentation available on this Wiki about building RPM packages. A good place to start is with the RPM Howto.