`

Installing software from source in Linux

阅读更多

Installing software from source in Linux - 1.2 >

So you've downloaded a software package with tar.gz or tar.bz2 extension and have no idea what to do with it. Or perhaps you already know that it's most likely the source code of the program you want to install and you have to compile it, but don't know how. Don't worry, compiling and installing software from source in Linux isn't as hard as it may sound!

Author: Nana Långstedt < nana.langstedt at gmail.com >
tuXfile created: 13 July 2002
Last modified: 22 September 2005


The procedure >

The installation procedure for software that comes in tar.gz and tar.bz2 packages isn't always the same, but usually it's like this:

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

If you're lucky, by issuing these simple commands you unpack, configure, compile, and install the software package and you don't even have to know what you're doing. However, it's healthy to take a closer look at the installation procedure and see what these steps mean.


Step 1. Unpacking >

Maybe you've already noticed that the package containing the source code of the program has a tar.gz or atar.bz2 extension. This means that the package is a compressed tar archive, also known as a tarball. When making the package, the source code and the other needed files were piled together in a single tar archive, hence the tar extension. After piling them all together in the tar archive, the archive was compressed with gzip, hence thegz extension.

Some people want to compress the tar archive with bzip2 instead of gzip. In these cases the package has atar.bz2 extension. You install these packages exactly the same way as tar.gz packages, but you use a bit different command when unpacking.

It doesn't matter where you put the tarballs you download from the internet but I suggest creating a special directory for downloaded tarballs. In this tutorial I assume you keep tarballs in a directory called dls that you've created under your home directory. However, the dls directory is just an example. You can put your downloaded tar.gz ortar.bz2 software packages into any directory you want. In this example I assume your username is me and you've downloaded a package called pkg.tar.gz into the dls directory you've created (/home/me/dls).

Ok, finally on to unpacking the tarball. After downloading the package, you unpack it with this command:

me@puter: ~/dls$ tar xvzf pkg.tar.gz

As you can see, you use the tar command with the appropriate options (xvzf) for unpacking the tarball. If you have a package with tar.bz2 extension instead, you must tell tar that this isn't a gzipped tar archive. You do so by using the j option instead of z, like this:

me@puter: ~/dls$ tar xvjf pkg.tar.bz2

What happens after unpacking, depends on the package, but in most cases a directory with the package's name is created. The newly created directory goes under the directory where you are right now. To be sure, you can give thels command:

me@puter: ~/dls$ ls
pkg pkg.tar.gz
me@puter: ~/dls$

In our example unpacking our package pkg.tar.gz did what expected and created a directory with the package's name. Now you must cd into that newly created directory:

me@puter: ~/dls$ cd pkg
me@puter: ~/dls/pkg$

Read any documentation you find in this directory, like README or INSTALL files, before continuing!


Step 2. Configuring >

Now, after we've changed into the package's directory (and done a little RTFM'ing), it's time to configure the package. Usually, but not always (that's why you need to check out the README and INSTALL files) it's done by running theconfigure script.

You run the script with this command:

me@puter: ~/dls/pkg$ ./configure

When you run the configure script, you don't actually compile anything yet. configure just checks your system and assigns values for system-dependent variables. These values are used for generating a Makefile. The Makefilein turn is used for generating the actual binary.

When you run the configure script, you'll see a bunch of weird messages scrolling on your screen. This is normal and you shouldn't worry about it. If configure finds an error, it complains about it and exits. However, if everything works like it should, configure doesn't complain about anything, exits, and shuts up.

If configure exited without errors, it's time to move on to the next step.


Step 3. Building >

It's finally time to actually build the binary, the executable program, from the source code. This is done by running themake command:

me@puter: ~/dls/pkg$ make

Note that make needs the Makefile for building the program. Otherwise it doesn't know what to do. This is why it's so important to run the configure script successfully, or generate the Makefile some other way.

When you run make, you'll see again a bunch of strange messages filling your screen. This is also perfectly normal and nothing you should worry about. This step may take some time, depending on how big the program is and how fast your computer is. If you're doing this on an old dementic rig with a snail processor, go grab yourself some coffee. At this point I usually lose my patience completely.

If all goes as it should, your executable is finished and ready to run after make has done its job. Now, the final step is to install the program.


Step 4. Installing >

Now it's finally time to install the program. When doing this you must be root. If you've done things as a normal user, you can become root with the su command. It'll ask you the root password and then you're ready for the final step!

me@puter: ~/dls/pkg$ su
Password:
root@puter: /home/me/dls/pkg#

Now when you're root, you can install the program with the make install command:

root@puter: /home/me/dls/pkg# make install

Again, you'll get some weird messages scrolling on the screen. After it's stopped, congrats: you've installed the software and you're ready to run it!

Because in this example we didn't change the behavior of the configure script, the program was installed in the default place. In many cases it's /usr/local/bin. If /usr/local/bin (or whatever place your program was installed in) is already in your PATH, you can just run the program by typing its name.

And one more thing: if you became root with su, you'd better get back your normal user privileges before you do something stupid. Type exit to become a normal user again:

root@puter: /home/me/dls/pkg# exit
exit
me@puter: ~/dls/pkg$


Cleaning up the mess >

I bet you want to save some disk space. If this is the case, you'll want to get rid of some files you don't need. When you ran make it created all sorts of files that were needed during the build process but are useless now and are just taking up disk space. This is why you'll want to make clean:

me@puter: ~/dls/pkg$ make clean

However, make sure you keep your Makefile. It's needed if you later decide to uninstall the program and want to do it as painlessly as possible!


Uninstalling >

So, you decided you didn't like the program after all? Uninstalling the programs you've compiled yourself isn't as easy as uninstalling programs you've installed with a package manager, like rpm.

If you want to uninstall the software you've compiled yourself, do the obvious: do some old-fashioned RTFM'ig. Read the documentation that came with your software package and see if it says anything about uninstalling. If it doesn't, you can start pulling your hair out.

If you didn't delete your Makefile, you may be able to remove the program by doing a make uninstall:

root@puter: /home/me/dls/pkg# make uninstall

If you see weird text scrolling on your screen (but at this point you've probably got used to weird text filling the screen? :-) that's a good sign. If make starts complaining at you, that's a bad sign. Then you'll have to remove the program files manually.

If you know where the program was installed, you'll have to manually delete the installed files or the directory where your program is. If you have no idea where all the files are, you'll have to read the Makefile and see where all the files got installed, and then delete them.

分享到:
评论

相关推荐

    The Linux-HA User’s Guide

    Building and installing Cluster Glue from source 3.1.1. Cluster Glue build prerequisites 3.1.2. Downloading Cluster Glue sources 3.1.3. Building Cluster Glue 3.1.4. Building Packages 3.2. ...

    Building Embedded Linux Systems, 2nd

    this new edition gives you the basics of building embedded Linux systems, along with the configuration, setup, and use of more than 40 different open source and free software packages in common use....

    The Linux Programmer’s Toolbox

    You'll start by learning the basics of downloading, building, and installing open source projects. You'll then learn how open source tools are distributed, and what to look for to avoid wasting time ...

    英文原版-The Linux Programmers Toolbox 1st Edition

    and may even show you a few new tricks in your favorite text editor.You’ll enhance your knowledge of the Linux kernel by learning how it interacts with your software. Fusco walks you through the ...

    Developing Statistical Software in Fortran 95

    7 1.4.6 Pseudo Object-Oriented Programming in Fortran . . 8 1.4.7 Fortran 2003 . . . . . . . . . . . . . . . . . . . . . . 8 1.4.8 Which Compiler Should I Use? . . . . . . . . . . . . 8 ...

    linuxdeploy-2.1.0-237.apk

    This application is open source software for quick and easy installation of the operating system (OS) GNU/Linux on your Android device. The application creates a disk image or a directory on a flash ...

    nvxdsync.exe

    Notwithstanding the foregoing terms of Section 2.1.1, SOFTWARE designed exclusively for use on the Linux or FreeBSD operating systems, or other operating systems derived from the source code to these...

    OpenStack Cloud Computing Cookbook, 2nd edition

    OpenStack is an open source cloud operating stack that was born from Rackspace and NASA and became a global success, developed by scores of people around the globe and backed by some of the leading ...

    BeagleBone.Black.Cookbook.1783982926

    from connecting the necessary hardware and using the command line with Linux commands to installing new software and controlling your system remotely. Following these recipes, more advanced examples ...

    Microsoft Windows 7 In Depth.pdf

    Although this book advances logically from beginning to end, it’s written so that you can jump in at any location, quickly get the information you need, and get out. You don’t have to read it from ...

    eric5-5.3.1

    If you want to run eric5 from within the source tree you have to execute the compileUiFiles.py script once after a fresh checkout from the source repository or when new dialogs have been added. ...

    KCF源码代码

    for linux: open terminal in the directory with the code $ mkdir build; cd build; cmake .. ; make This code compiles into binary **kcf_vot** ./kcf_vot - using VOT 2014 methodology ...

    Elastix.Unified.Communications.Server.Cookbook.184951934X

    Elastix brings together the most useful tools and features from the Unified Communications and Open Source worlds: IP-PBX, Chat, Call Center, Multisite, Video, and so on, in a modular way. Beginning ...

    avrusb实现数据传输

    BUILDING AND INSTALLING ======================= This project can be built on Unix (Linux, FreeBSD or Mac OS X) or Windows. Building on Windows: You need WinAVR to compile the firmware. A package can ...

    SQLMemTable for Delphi / C++ Builder

    SQLMemTable for Delphi / C++ Builder: README============================================Please read this file carefully (especially the INSTALLATION chapter) before installing the program to your ...

    Python安装包version 3.1.5

    is incomplete, and also doesn't list anything merged in from the 2.7 release under development). If you want to install multiple versions of Python see the section below entitled "Installing multiple...

    OpenStack Cloud Computing Cookbook

    OpenStack Open Source Cloud software is one of the most used cloud infrastructures to support a wide variety of use cases, from software development to big data analysis. It is developed by a thriving...

    ICS delphixe10源码版

    .\Source\Include (was Delphi\Vc32) .inc files (including OverbyteIcsDefs.inc) .\Source\Extras (was Delphi\Vc32) Extra source code not built into packages .\Source\zobj125 (was Delphi\Vc32) ZLIB C OBJ ...

    CalcExpress

    CalcExpress: README==============... Kylix 2.0Software type: Freeware with source codeCompany information-------------------Company Name: AidAim SoftwareContact E-mail Address: support@aidaim.comContact ...

    Tesseract-OCR.rar

    ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either ...

Global site tag (gtag.js) - Google Analytics