Manually Installing from Source Code

Manually Installing from Source Code

Most of the Unix software you are likely to want to use is available via Fink, but as you get into more advanced uses of Unix, you will find that some software isn't available through Fink. You need to know how to compile and install software manually. The process for installing virtually all open -source Unix software is described here (except for using the CPAN system to install Perl modules, which we describe later in this chapter).

For the following task, we will use a sample program that is designed to demonstrate the process of manually downloading, compiling, and installing a Unix application from the command line. The program is the classic sample program hello world .

You use the wget program to download the source code from the command line. If you haven't already installed wget using Fink, do that now (described in the previous section).

To manually install a package from source code:

1.
sudo -s

The installation process must be performed as root, because you will be adding files to directories owned and writable only by root.

To avoid typing sudo before every command, you are simply spawning a new shell as root. Notice that your shell prompt changes ( Figure 13.21 ). Remember to exit from the new shell (with the exit command) after the installation is done. We'll remind you.

Figure 13.21. Your shell prompt changes when you start a new shell as root.
 localhost:~ vanilla$  sudo -s  Password: localhost:~ root# 

2.
Enter your password, and press .

The next step is to create the directory where you are saving the source code.

The conventional place for all user -installed software is in subdirectories of /usr/local .

The source code goes in a subdirectory of /usr/local/src , and the actual program (the compiled executable file itself) goes in /usr/local/bin .

3.
mkdir -p /usr/local/src/hello

That command creates the directory /usr/local/src/hello and any intermediate directories that may not exist (such as the src directory).

4.
cd /usr/local/src/hello

This changes your current directory to /usr/local/src/hello .

(Here's a mini-tip: You can also do

cd !$

because !$ translates to the last argument of the previous command, in this case /usr/local/src/hello .)

5.
wget http://ftp.gnu.org/gnu/hello/

hello-2.1.1.tar.gz

The wget command retrieves the compressed tar file (also known as a tarball ) and saves it in the current directory ( Figure 13.22 ).

Figure 13.22. Using wget to retrieve a compressed tar file (a tarball ) of source code.
 localhost:/usr/local/src/hello root#  wget http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz  06:56:06 http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz   => `hello-2.1.1.tar.gz' Resolving ftp.gnu.org... done. Connecting to ftp.gnu.org[199.232.41.7]:80... connected. HTTP request sent, awaiting response... 200 OK Length: 389,363 [application/x-tar] 100%[====================================>] 389,363      103.52K/s   ETA 00:00 06:56:10 (103.52 KB/s) - `hello-2.1.1.tar.gz' saved [389363/389363] localhost:/usr/local/src/hello root# 

Next you will unpack the compressed tar file.

Learning More About Compiling Software

Almost all the Unix software you will download and install is written in the C programming language and uses a couple of common tools to manage the process of configuring the source code and compiling it.

The classic text on C is The C Programming Language , by Brian W. Kernighan and Dennis M. Ritchie (Prentice Hall; http://cm.bell-labs.com/cm/cs/cbook). Also check out C Programming: Visual QuickStart Guide by Larry Ullman and Marc Liyanage (Peachpit Press; www.peachpit.com/title/0321287630).

The make program is widely used for managing software development, especially software written in C. The standard text on make is Managing Projects with make , Second Edition, by Andy Oram and Steve Talbott (O'Reilly; www.oreilly.com/catalog/make2).


6.
tar xfvz hello-2.1.1.tar.gz

This creates a new directory called hello-2.1.1 .

The options to tar are the following: x for "extract," f for "from a file," v for "verbose," and z for "the file is compressed with gzip. " The verbose option causes the display of the name of each file and directory extracted from the archive; in all, you will see more than 200 files listed ( Figure 13.23 ).

Figure 13.23. Using tar to extract files from the compressed archive. (Abridged output; total output will be more than 200 lines.)
 localhost:/usr/local/src/hello root#  tar xfvz hello-2.1.1.tar.gz  hello-2.1.1/ hello-2.1.1/intl/ hello-2.1.1/intl/ChangeLog hello-2.1.1/intl/Makefile.in  ... omitting display of many files from the intl/ subdirectory  hello-2.1.1/intl/VERSION hello-2.1.1/po/ hello-2.1.1/po/Makefile.in.in  ... omitting display of files in the po/ subdirectory  hello-2.1.1/README hello-2.1.1/ABOUT-NLS hello-2.1.1/AUTHORS hello-2.1.1/COPYING hello-2.1.1/ChangeLog hello-2.1.1/INSTALL hello-2.1.1/Makefile.am hello-2.1.1/Makefile.in hello-2.1.1/NEWS hello-2.1.1/THANKS hello-2.1.1/TODO hello-2.1.1/aclocal.m4 hello-2.1.1/config.guess hello-2.1.1/config.h.in hello-2.1.1/config.rpath hello-2.1.1/config.sub hello-2.1.1/configure hello-2.1.1/configure.ac . . . 

7.
cd hello-2.1.1

Now your current directory is the directory containing the actual source code. Check the files, looking especially for README and INSTALL files.

8.
ls

You will see that there are indeed both README and INSTALL files ( Figure 13.24 ); read them both.

Figure 13.24. Using ls to see the files in the unpacked directory.
 localhost:/usr/local/src/hello/hello-2.1.1 root#  ls  ABOUT-NLS        Makefile.am      config.guess      depcomp       mkinstalldirs AUTHORS          Makefile.in      config.h.in       doc           po BUGS             NEWS             config.rpath      install-sh    src COPYING          README           config.sub        intl          tests ChangeLog        THANKS           configure         m4 ChangeLog.O      TODO             configure.ac      man INSTALL          aclocal.m4       contrib           missing localhost:/usr/local/src/hello/hello-2.1.1 root# 

9.
less README

The README file usually tells you what the program is for, who wrote it, where to find more information, and how to report bugs.

10.
q

This quits from the less program.

11.
less INSTALL

The INSTALL file should tell you, in detail, how to install the software. Install files can be quite complex because they try to address many different versions of Unix and the many options that someone might use. In general, as we noted at the beginning of this chapter, the basic instructions tell you to run the following:

 ./configure make make test  or  make check make install 

It is a good idea to read through the INSTALL files carefully the first dozen or so times you install software manually. After that, always read enough to confirm that nothing unusual is required for the installation.

One common option described in INSTALL files controls where you install the software. The convention is to use a prefix of /usr/local , so executables go in /usr/local/bin , man pages in /usr/local/man , software libraries in /usr/local/lib , and so on. Do not use something else unless you have a very good reason. Installing software in the default location keeps your system consistent with the rest of the world and makes for easier maintenance.

12.
q

to quit from less .

In the case of this sample program, you will use the default configuration, so the next steps are very simple.

13.
./configure

This runs a script that probes your system and creates another script using the information found ( Figure 13.25 ). The configure script creates a file called Makefile, which is used by the next command.

Figure 13.25. The configure script probes your system and configures the source code for compilation. (Output here is abridged.)
 locahost:/usr/local/src/hello/hello-2.1.1 root#  ./configure  checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... no checking for mawk... no checking for nawk... no checking for awk... awk checking whether make sets ${MAKE}... yes checking for gcc... gcc checking for C compiler default output... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for style of include used by make... GNU  ... omitting many lines to save space...  configure: creating ./config.status config.status: creating Makefile config.status: creating contrib/Makefile config.status: creating doc/Makefile config.status: creating intl/Makefile config.status: creating man/Makefile config.status: creating po/Makefile.in config.status: creating m4/Makefile config.status: creating src/Makefile config.status: creating tests/Makefile config.status: creating config.h config.status: executing depfiles commands config.status: executing default-1 commands config.status: creating po/POTFILES config.status: creating po/Makefile config.status: executing default commands localhost:/usr/local/src/hello/hello-2.1.1 root# 

14.
make

The make command reads Makefile, created by configure , and runs a series of commands to compile the software. (Both configure and Makefile are plain-text filesyou can look inside them if you are curious .) Figure 13.26 shows abridged output from make . Depending on how large and complex the software is, and how fast your computer is, the compilation process can take many minutes or even longer.

Figure 13.26. The make command runs the compilation process. (Output here is abridged.)
 localhost:/usr/local/src/hello/hello-2.1.1 root#  make  make all-recursive Making all in contrib make[2]: Nothing to be done for `all'. Making all in doc make[2]: Nothing to be done for `all'. Making all in intl gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local  ... several lines omitted ...  rm -f libintl.a ar cru libintl.a intl-compat.o bindtextdom.o dcgettext.o dgettext.o gettext.o f ranlib libintl.a cp ./libgnuintl.h libintl.h /bin/sh ./config.charset 'powerpc-apple-darwin8.1.0' > t-charset.alias mv t-charset.alias charset.alias sed -e '/^#/d' -e 's/@''PACKAGE''@/hello/g' ref-add.sin > t-ref-add.sed mv t-ref-add.sed ref-add.sed sed -e '/^#/d' -e 's/@''PACKAGE''@/hello/g' ref-del.sin > t-ref-del.sed mv t-ref-del.sed ref-del.sed Making all in po make[2]: Nothing to be done for `all'. Making all in src source='hello.c' object='hello.o' libtool=no \ depfile='.deps/hello.Po' tmpdepfile='.deps/hello.TPo' \ depmode=gcc3 /bin/sh ../depcomp \  ... several lines omitted ...  Making all in man perl help2man --name="Friendly Greeting Program" ../src/hello >hello.1 Making all in m4 make[2]: Nothing to be done for `all'. Making all in tests make[2]: Nothing to be done for `all'. make[2]: Nothing to be done for `all-am'. localhost:/usr/local/src/hello/hello-2.1.1 root# 

15.
make check

Some software packages come with a set of preinstallation tests to run after compiling the software but before installing it. In this case, the INSTALL file says that we can run the tests with make check ( Figure 13.27 ). Many packages use make test for the same purpose. (By the way, the argument to the make command is called a target .)

Figure 13.27. Running the preinstallation tests. In this case there were three tests; all passed.
 localhost:/usr/local/src/hello/hello-2.1.1 root#  make check  Making check in contrib make[1]: Nothing to be done for `check'. Making check in doc make[1]: Nothing to be done for `check'. Making check in intl make[1]: Nothing to be done for `check'. Making check in po make[1]: Nothing to be done for `check'. Making check in src make[1]: Nothing to be done for `check'. Making check in man make[1]: Nothing to be done for `check'. Making check in m4 make[1]: Nothing to be done for `check'. Making check in tests make check-TESTS PASS: hello-1 PASS: world-1 PASS: nothing-1 ================== All 3 tests passed ================== make[1]: Nothing to be done for `check-am'. localhost:/usr/local/src/hello/hello-2.1.1 root# 

Up to now you have not changed anything on your disk outside the directory containing the source code. The next step is to install the software in the location where it will be available to all users on the system.

16.
make install

The make program shows you what it does to install the software. In this case it uses the install program ( /usr/bin/install ) ( Figure 13.28 ), which has a man page you can read if you are curious. The software is now installed.

Figure 13.28. The make install program performs the actual installation of the software. (Output here is abridged.)
 localhost:/usr/local/src/hello/hello-2.1.1 root#  make install  Making install in contrib make[2]: Nothing to be done for `install-exec-am'. make[2]: Nothing to be done for `install-data-am'. Making install in doc make[2]: Nothing to be done for `install-exec-am'. /bin/sh ../mkinstalldirs /usr/local/info mkdir --p  /usr/local/info  /usr/bin/install -c -m 644 ./hello.info /usr/local/info/hello.info  install-info --info-dir=/usr/local/info /usr/local/info/hello.info * Hello, world!: (hello). GNU `Hello, world'. install-info(/usr/local/info/hello.info): no file /usr/local/info/dir, retrieving backup file /var/backups/infodir.bak. install-info(/usr/local/info/hello.info): creating new section `Greeting Printing Program'  ...dozens of lines omitted...  Making install in po  ...dozens of lines omitted...  Making install in src /bin/sh ../mkinstalldirs /usr/local/bin mkdir -p -- /usr/local/bin   /usr/bin/install -c hello /usr/local/bin/hello make[2]: Nothing to be done for `install-data-am'. Making install in man make[2]: Nothing to be done for `install-exec-am'. /bin/sh ../mkinstalldirs /usr/local/man/man1 mkdir -p -- /usr/local/man/man1  /usr/bin/install -c -m 644 ./hello.1 /usr/local/man/man1/hello.1 Making install in m4 make[2]: Nothing to be done for `install-exec-am'. make[2]: Nothing to be done for `install-data-am'. Making install in tests make[2]: Nothing to be done for `install-exec-am'. make[2]: Nothing to be done for `install-data-am'. make[2]: Nothing to be done for `install-exec-am'. make[2]: Nothing to be done for `install-data-am'. localhost:/usr/local/src/hello/hello-2.1.1 root# 

17.
exit

This exits from the root shell you started in step 1. Your prompt changes back to your normal prompt. Note that your current directory reverts to whatever it was when you started the root shell ( Figure 13.29 ).

Figure 13.29. Exiting from the root shell brings you back to the directory you were in when you started it.
 localhost:/usr/local/src/hello/hello-2.1.1  root#  exit  localhost:~ vanilla$ 

If you are using the tcsh shell as your shell, type rehash so that tcsh will rebuild its list of available commands.

Now you can try running the newly installed software. The new program has been installed as /usr/local/bin/hello , so you want to make sure that /usr/local/bin is in your PATH . Also, the man page is installed as /usr/local/man/man1/hello.1 , so make sure that /usr/local/man is in your MANPATH see Chapter 7 to learn how to alter your PATH and MANPATH .

18.
hello

The program produces output as shown in Figure 13.30 . If you get an error that says

-bash: hello: command not found

Figure 13.30. Running the newly installed software to see what it does.
 localhost:~ vanilla$ hello Hello, world! localhost:~ vanilla$ 

see step 17 aboveyou probably need to adjust your PATH to include /usr/local/bin . Or use the full path /usr/local/bin/hello .

19.
You're done.

Congratulationsyou've installed software from source code.

Tips

  • Read the man page: man hello

    The hello source-code package (like many GNU packages) also installs documentation in a format called Info. Read man info to learn about the Info format and the info command so that you can run info hello .

  • You can save a record of the compilation process to a file by redirecting the output of make to a file:

     make > compilation.log or make install > install.log 

  • You can remove all the files created in the source directory by the compilation process with

    make clean

    (If you want to remove files that have been installed with make install , you must remove them manually from their installed locations. In some rare cases there might be an "uninstall" target in the makefile, in which case you could do make uninstall .)

  • The configure script saves the configuration it builds in another shell script, called config.status , which you can run to recreate the configuration, including any options you selected.

  • If you are using the tcsh shell as your shell, run rehash so that tcsh will rebuild its list of available commands.




Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net