Transcript UNIX

Application Installation
Guntis Barzdins
Girts Folkmanis
“Hello World” palaišana
unix% cat > hello.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
Ctrl/D
unix%gcc hello.c
unix%./a.out
Hello World!
unix%
gcc
the Gnu Compiler Collection
 Frontend for:



C: gcc
C++: g++
More (ada, java, objective-c, fortran, …)
 Backend for:

x86, ia-64, ppc, m68k, alpha, hppa, mips, sparc,
mmix, pdp-11, vax, …
gcc: Usage
 gcc foo.cpp

Outputs ./a.out binary
 gcc -g -Wall –pedantic foo.cpp bar.cpp baz.o –o foo



-g: produce debugging information
-Wall –pedantic: many types of warnings
-o foo: output to file “foo”
 Linking libraries:

eg math library: –lm

The library foo is named libfoo.a under unix
Linking
o
o
o
Combines the program object code with other object code
to produce the executable file.
The other object code can come from the Run-Time
Library, other libraries, or object files that you have
created.
Saves the executable code to a disk file. On the Linux
system, that file is called a.out.
o
If any linker errors are received, no executable file will be
generated.
Normal Linking and Loading
Printf.c
Main.c
gcc
gcc
Printf.o
ar
Static
Library
Main.o
Linker
a.out
Loader
Memory
X Window code:
- 500K minimum
- 450K libraries
Load Time Dynamic Linking
Printf.c
Main.c
gcc
gcc
Printf.o
ar
Dynamic
Library
Main.o
Linker
a.out
Loader
Memory
• Save disk space.
• Libraries move?
• Moving code?
• Library versions?
• Load time still
the same.
Run-Time Dynamic Linking
Printf.c
Main.c
gcc
gcc
Printf.o
ar
Dynamic
Library
Main.o
Linker
a.out
Loader
Run-time
Loader
Memory
Save disk space.
Startup fast.
Might not need all.
Creating a static library
 static library for linking: libsomething.a




create .o files: gcc –c helper.c
ar rlv libsomething.a *.o
ranlib libsomething.a
use library as gcc –L/your/dir –lsomething
Creating a dynamic library
 Details differ for each platform

gcc –shared –fPIC –o libhelper.so *.o
 use same as for static (-llibrary)
 also LD_LIBRARY_PATH
Program Development Using gcc
Editor
Source File pgm.c
Preprocessor
Modified Source Code in RAM
Compiler
Program Object Code File pgm.o
Other Object Code Files (if any)
Linker
Executable File a.out
Unix sw development
environments
 Emacs
 Kdevelop
 Xcode
Other Programming Tools
 There are tools to ease single programmer
development of multiple file projects (make)
 There are version control tools for multi
programmer projects: CVS (Concurrent Version
Control)
 There are “packaging” tools to ease installing
programs: Tarball, RPM, DEB,...
The make program
If in a directory full of C files there is a text file with the
default name of makefile then running $make will cause it to
be used by the make program
The power of make is that it examines timestamps. If a
change is made to part2.c and make run again, only part2.c
is compiled. The linker links the old part1.o, old main.o
and the new part2.o to make the final program.
Makefiles
• When programming large applications
– Better to modularise.
– Keep individual source files small.
– Instead of one large file.
• Difficult to edit.
• Slow to compile.
– Not easy to do manually.
– Use a “makefile.”
Makefile example
• Consider, program contained in two
separate source files.
– “main.c”
– “sum.c”
– Both contain header “sum.h”
• Require executable file to be named “sum”
• Next slide shows a simple makefile that
could be used.
Makefile example
Comment line preceded with “#”
# Make file for sum executable
“Dependency line”
sum: main.o sum.o
gcc –o sum main.o sum.o
“Action line”
main.o: main.c sum.h
gcc –c main.c
sum.o: sum.c sum.h
Dependency line + Action
gcc –c sum.c
line = “Rule”
Action line must begin with a tab character
Dependency line must start in column 1
make
 make maintains dependency graphs
 based on modification times
 Makefile as default name
 make [–f makefile] [target]
 if node newer than child, remake child
tab!
target ...: dependency
command
command
make environment
 Environment variables (PATH, HOME,
USER, etc.) are available as $(PATH), etc.
 Also passed to commands invoked
 Can create new variables (gmake):
export FOOBAR = foobar
make variables
$@ name of current target
$? list of dependencies newer than target
$< name of dependency file
$* base name of current target
$% for libraries, the name of member
 implicit rules, e.g., a .c file into .o
.c.o:
$(CC) $(CFLAGS) $<
make
all: hello clean
clean:
rm –f *.o
helper.o: helper.c
OBJ = helper.o \
hello.o
hello: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) –o $@ $(OBJ)
make depend
depend: $(CFILES) $(HFILES)
$(CC) $(CFLAGS) –M $(CFILES) > .state
# works for GNU make and BSD make
#if 0
include .state
#endif
#include “.state”
Revision Management
 diffutils:


Find differences among files (diff and diff3)
Update a set of files from generated differences
(patch)
 cvs

Maintains a history of changes for groups of files



Including: who, when, what, and optionally why
Analogue of Visual SourceSafe
New alternatives: subversion and bitkeeper
Revision Management
What CVS lets you do
 Modify source code locally until it’s ready to be merged
with what everyone sees

Multiple people can modify the same file and be ok
 Develop multiple versions of software simultaneously

And merge these branches later on
 Recall past versions of code base

Based on time ago or version
 See committer's comments on their changes
Packages
 In more widespread linux distributions, programs are distributed
in binary RPM, DEB or modified TGZ formats
 RPM (RedHat Package Management) packages are used on
RedHat, Mandrake, Suse, Conectiva
 DEB are used on the open source distribution Debian and its
forks
 Modified TGZ are used on SlackWare
Packaging Approaches:
Source vs. Binary
 There are two fundamentally different
approaches for packaging-based
software distributions:


providing source packages containing
the vendor sources plus instructions for
automated build and installation.
providing binary packages containing
the final installation files only.
 Most packaging facilities support both
approaches, although often not equally
well.
 Both approaches have each their pros
and cons, nevertheless all software
distributions focus on one of them.
source
package
binary
package
distribution size


package size


package
dependencies


installation
reproducability


installation
run-time stability


installation system
alignment


installation time


Dependencies



Dependencies management is a very useful feature of
package management software
They keep systems in a consistent state and
guarantee the applications to run in the expected way
rpm or dpkg commands have limited dependencies
management features

They can report which library a package relies on,
but the library can itself rely on other packages…
Main Package Distribution
Formats in Linux
 There is no standard package manager in Linux
 Packages Distributed in Binaries or Source Code form
 Main Package Management Standards

Tarball files (.tar.gz/.tar.bz2)




RPM (RedHat Package Manager) (.rpm)



The old-fashioned way of distributing software in Linux/Unix
Compatible with all distros
Main package manager in Slackware, Gentoo
Introduced by RedHat and has been adopted by many other distributions
(Fedora, Mandrake, SuSe) .
The most popular Linux package format
DEB (Debian Package Manager) (.deb)

Introduced by Debian distribution
Installing from Tarball files
 Software Packages coming in source code archives have to be compiled
before installed
 Usually come in .tar.gz or .tar.bz2 archives
 Typical compilation/installation steps

Unpack the archive:



Change to the extracted directory


make
Install the package as follows:


./configure
Build the source code using the GNU Make utility as follows:


cd <extracted_dir_name>
Run source configuration script as follows:


tar xzvf <package_name>.tar.gz
tar xvjf <package_name>.tar.bz2
make install
“INSTALL” or “README” files also exist in this directory giving application-specific
usage information
Backup Tools
 tar











tar jxvf mytarball.tar.bz2 - Extract files from mytarball.tar.bz2
tar zxvf mytarball.tar.gz - Extract files from mytarball.tar.gz
-z : Use gzip compression
-j : Use bzip2 compression
-x : Extract
-c: Create
-v : Verbose
-f : Use file
Gzip compression is used for tarballs with the extensions .tar.gz, .tgz, and .tar.Z.
Bzip2 compression which is slightly better but requires more CPU is used in tarballs with the
extensions .tar.bz2 and .tbz2.
tar jcvf mytarball.tar.bz2 my_files - Creates a tarball mytarball.tar.bz2 with the specified files.
 gzip file - Will compress file using gzip compression and will rename "file" to "file.gz“
 gunzip file.gz - Will uncompress file compressed using gzip compression and will rename
"file.gz" to "file“
 bzip2 file - Will compress file using bzip2 compression and will rename "file" to "file.bz2“
 bunzip2 file.bz2 - Will uncompress file compressed using bzip2 compression and will
rename "file.bz2" to "file“
Apache Example
1.
2.
3.
4.
5.
6.
7.
8.
9.
gunzip apache_xxx.tar.gz
tar -xvf apache_xxx.tar
gunzip php-xxx.tar.gz
tar -xvf php-xxx.tar
cd apache_xxx
./configure --prefix=/www --enable-module=so
make
make install
cd ../php-xxx
10. Now, configure your PHP. This is where you customize your PHP
with various options, like which extensions will be enabled. Do a
./configure --help for a list of available options. In our example
we'll do a simple configure with Apache 1 and MySQL support. Your
path to apxs may differ from our example.
./configure --with-mysql --with-apxs=/www/bin/apxs
11. make
12. make install
If you decide to change your configure options after installation,
you only need to repeat the last three steps. You only need to
restart apache for the new module to take effect. A recompile of
Apache is not needed.
Note that unless told otherwise, 'make install' will also install PEAR,
various PHP tools such as phpize, install the PHP CLI, and more.
Managing Software in RedHatbased distributions
 Using the command line, packages are installed using
rpm utility program



Install a package
 rpm -i <package_name>.rpm
Update an existing package
 rpm –U <package_name>.rpm
Remove a package
 rpm –e <package_name>
Three ways to manage software
packages in Debian
 dpkg: Used on .deb files like rpm

Install: dpkg -i <package_name>.deb


If an older version of the package is installed it updates it automatically by
replacing it with the new
Remove: dpkg -r <package_name>
 dselect: dpkg console front-end
 apt-get: The most frequently used way of managing
software packages in Debian.

Install: apt-get install <package_name>


e.g. apt-get install kde to install KDE Window Manager
Remove: apt-get remove <package_name>
Package Management
 Using RPM




To install or upgrade a package: rpm -Uvh package-1.0.i386.rpm
To remove a package: rpm -e package-1.0
To determine what version of a package you have installed: rpm -qa | grep
package_name
To determine what package a file "belongs" to: rpm -qf filePackage
Management Cont.
 Using Apt






To update your package lists: apt-get update
To install all updated packages: apt-get dist-upgrade
To install a package: apt-get install package
To upgrade a package: apt-get upgrade package
To then remove that package (and all packages that depend on it): apt-get
remove package
To search for a package: apt-cache search search_string
Other Packaging Methods
 The Debian case (APT - Advanced Packaging Tool)


The first distribution used organised on-line package repositories
APT utilities set (apt-get, apt-cache etc.) is provided for managing
packages on these repositories
 Can manage packages in binaries and source format
 Provides packages inter-dependency auto-resolve
 Contacts repositories listed in /etc/apt/sources.list file
 E.g. apt-get remove gnome # Remove GNOME
apt-cache search mozilla #Search for package names
# containing mozilla”
 The Gentoo Linux case (emerge)

Deals mostly with source files


Fetches packages and compiles them according to compilation parameters given
in /etc/make.conf
E.g. emerge kde #Fetches, compiles and installs
packages for KDE
Gentoo Portage features
 Provides ebuild scripts which download, patch, compile, and
install packages.
 Modeled on the ports-based BSD distributions.
 Dependency checking, extreme customization.
 Original source tarballs are downloaded.

No need to wait for someone to make a binary package for your
distribution.
 The user specifies what they want, and the system is built to
their specifications.

Compiles are optimized for your specific hardware.

E.g. Altivec on G4 PPC chips, Pentium versus Athlon.
Portage tree
 The Portage tree is a collection of ebuilds, files that
contain all information Portage needs to maintain
software (install, search, query, ...). These ebuilds reside
in /usr/portage by default.
 The Portage tree is usually updated with rsync:


# emerge --sync
# emerge-webrsync
 To search for all packages who have "pdf" in their name:

$ emerge search pdf
Package Lifecycle
BEGIN
developer
administrator
Evaluation of
application
Checkout RPM
Specification
from CVS
Fetch Source
RPM from
Repository
Fetch Binary
RPM from
Repository
Edit RPM
Specification
(.spec)
Track Vendor
Sources
Unpack
Source RPM
Install
Application
into Instance
Fetch Vendor
Sources
Unpack Vendor
Sources
Remove
Application
from Instance
upgrade
Configure & Build
Application
Install
Application
Commit RPM
Specification
to CVS
Roll Source RPM
Package
Roll Binary RPM
Package
Store Source
RPM into
Repository
Store Binary
RPM into
Repository
END
My hack: This universe.
Just one little problem:
core keeps dumping.
On-line Package Repositories
 Large package bases on the Web



Accessible via FTP or HTTP
http://rpm.pbone.net/
http://www.apt-get.org/text/?site=4
Using rpm
 rpm –i
 rpm –e
 rpm –U
 rpm –q
install package, check for dependencies
erase package
upgrade package
query packages (e.g., -a = all)
rpm -q
rpm -q -i telnet
Name
: telnet
Relocations: (not relocateable)
Version
: 0.17
Vendor: Red Hat, Inc.
Release
: 18.1
Build Date: Wed Aug 15 15:08:03 2001
Install date: Fri Feb 8 16:50:03 2002
Build Host: stripples.devel.redhat.com
Group
: Applications/Internet
Source RPM: telnet-0.17-18.1.src.rpm
Size
: 88104
License: BSD
Packager
: Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Summary
: The client program for the telnet remote login protocol.
Description :
Telnet is a popular protocol for logging into remote systems over the
Internet. The telnet package provides a command line telnet client.
Install the telnet package if you want to telnet to remote machines.
This version has support for IPv6.
Building your own rpm: spec
#
# spec file for hello world app
#
Summary: hello world
Name: hello
Version: 1.0
Release: 1
Copyright: GPL
Group: Applications/Test
Source: http://www.cs.columbia.edu/IRT/software/
URL: http://www.cs.columbia.edu/IRT/software/
Distribution: Columbia University
Vendor: IRT
Packager: Henning Schulzrinne <[email protected]>
BuildRoot: /home/hgs/src/rpm
%description
The world's most famous C program.
Building your own rpm: spec
%prep
rm -rf $RPM_BUILD_DIR/hello-1.0
zcat $RPM_SOURCE_DIR/hello-1.0.tgz | tar -xvf %build
make
%install
make ROOT="$RPM_BUILD_ROOT" install
%files
%doc README
/usr/local/bin/hello
/usr/local/man/man1/hello.1
%clean
Building your own rpm
 create ~/.rpmmacros
%_topdir /home/hgs/src/test/rpm
 cd /home/hgs/src/test/rpm/SPECS
 rpm -ba --buildroot /home/hgs/tmp hello-1.0.spec
 creates binary and source RPM
APT




APT is a system created in the Debian community to
automatically manage the packages dependencies
APT can install, remove and upgrade packages,
managing dependencies and downloading the
packages
It’s a frontend to other tools, and it uses the
underlying package management system, like the
rpm or dpkg commands
It’s able to fetch packages from several media
(cdrom, ftp, http, nfs), and it can be used to create
ad-hoc software repositories
APT – Using
(1/3)
[root]@[/] # apt-get install nautilus
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
bonobo libmedusa0 libnautilus0
The following NEW packages will be installed:
bonobo libmedusa0 libnautilus0 nautilus
0 packages upgraded, 4 newly installed, 0 to remove and 1 not
upgraded.
Need to get 8329kB of archives. After unpacking 17.2MB will be
used.
Do you want to continue? [Y/n]
APT – Using
(2/3)
[root]@[/] # apt-get remove gnome-panel
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED:
gnome-applets gnome-panel gnome-panel-data gnome-session
0 packages upgraded, 0 newly installed, 4 to remove and 1 not
upgraded.
Need to get 0B of archives. After unpacking 14.6MB will be freed.
Do you want to continue? [Y/n]
APT – Using
(3/3)
[root]@[/] # apt-cache search pdf
kghostview - PostScript viewer for KDE
tetex - The TeX text formatting system.
xpdf - A PDF file viewer for the X Window System
…
[root]@[/] # apt-cache show xpdf
…
Filename: xpdf-1.00-3.i386.rpm
Description: A PDF file viewer for the X Window System.
Xpdf is an X Window System based viewer for Portable Document
Format (PDF) files. Xpdf is a small and efficient program which
uses standard X fonts.
APT for RPM



Brazilian distribution Conectiva ported the apt system
on its linux distribution, which uses rpm packages
Apt is now available for all distributions using rpm,
also thanks to the SourceForge project apt4rpm
(http://apt4rpm.sourceforge.net)
Some features of Debian apt are not yet available,
like package priority or requests to change
configuration files, because of some differences in
deb and rpm format
APT – repository creation

Create the directory tree
 <arch>/RPMS.os, <arch>/RPMS.updates,
<arch>/base (for apt specific files)
Ex: /linux/apt/redhat/7.3/i386/RPMS.os
In RPMS.os: copy the distribution rpms
 In RPMS.updates: copy the updates rpms
Give the command




genbasedir --topdir=/linux/apt --bloat --bz2only redhat/7.3/i386 os
(for “os” section)
genbasedir --topdir=/linux/apt --bloat --bz2only redhat/7.3/i386
updates (for “updates” section)
APT – repository source.list

Create an apache virtual host
<VirtualHost *>
ServerName apt.na.infn.it
DocumentRoot /linux/apt
<Directory /linux/apt>
Options +Indexes
</Directory>
</VirtualHost>

The source.list file to access this repository is
rpm http://apt.na.infn.it redhat/7.3/i386 os updates
APT – Naples repository

We have an apt repository in our campus in Naples,
accessible at
http://apt.na.infn.it


apt packages for RedHat 7.2, 7.3, 8 e 9 and
corresponding sources.list files for os and updates are
available on this site
Updates rpms and apt lists are updated every night
APT - Benefits


Apt simplifies package management on rpm based
distributions, even on RedHat
Systems update is possible with only two commands:
# apt-get update; apt-get -y upgrade


Using a local repository is possible to upgrade
machines using no external links
It is possible to include non standard packages in
local repositories...
Advanced Package Tool for
RPM
 High level package management tool from Debian ported to RPM





based systems (Conectiva Linux, RedHat, Fedora, SUSE,
Scientific Linux ...)
Installs the whole software with one command:
 “apt-get install lcg-ui” and APT will do the rest for you
Automatically resolves dependencies for specified packages and
downloads required rpms
Central configuration file with repositories' URLs
(/etc/apt/sources.list or /etc/apt/sources.list.d)
Automated or half-automated software upgrades
Note! APT requires that there are no broken dependencies in the
OS