Installing Software in Linux

In this chapter we will learn how to install software in Linux system.

Red Hat Package Manager (RPM)

Basically, an RPM file is a collection of all the files necessary for a particular program to run. It also includes descriptions of the program, version information, and the necessary scripts to perform the installation itself.

Although the name of the package manager says "Red Hat," the software can be used with other distributions as well. In fact, RPM has even been ported to other operating systems, such as Solaris and IRIX! The source code to RPM is open-source software, so anyone can take the initiative to make the system work for them.
A proper RPM file should follow a specific naming convention:
For example, pciutils-2.2.1-1.2.i386.rpm is the RPM filename for the 1.2 release of version 2.2.1 of the PCI utilities software package built for the i386 architecture. System Architectures Used by RPM.

Installing a New Package

The easiest way to install a new package is to use the -i option with rpm. For example, if you downloaded a package called bc-1.06-10.i386.rpm and wanted to install it, you would type

[root@localhost /mohit]# rpm -i <rpmname>

[root@localhost /mohit]# rpm -i bc-1.06-10.i386.rpm

If the installation went fine, you would not see any errors or messages. This is the most common method of installing RPMs. On the other hand, if the package already existed, you would see this message: error: package bc-1.06-10 is already installed. If You want to see the progress of installation use -ivh meaning of this command.
i      installation
v      to see the progress (Tells rpm to be verbose about its actions.)
h      progress appear in hash form
My RPMs are placed in directory /Packages. Bind- is the RPM.
Linux RPM installation
RPM installation

If you need to upgrade a package that already exists, use the -U option, like so:
Linux RPM installation
RPM installation

Some packages rely on other packages. A KDE applet, for example, may depend on KDE libraries having already been installed. In those instances, you will get a message indicating Which packages need to be installed first. Simply install those packages and then come back to the original package. Some RPMs depend upon other RPMs.
So we add another option --aid for automatically install dependants, I assume.
Some time we one programs is divided into multiple RPM files
Linux RPM package installation

DNS service RPMs, if install it one by one it will become very time consuming. So instead of writing complete name of RPM I shall write bind-* as shown in figure.
Linux RPM package installation
DNS RPM installation

if you install rpm which have already been installed in your system.
[root@localhost /mohit]# rpm -ivh --aid --force rpm_name

[root@localhost /mohit]# rpm -ivh --aid --force caching-name-server-7.33.rpm

If rpm is complaining about missing dependency files, but you want the installation to happen anyway, passing this option at the command line will cause rpm to not perform any dependency checks.
[root@localhost /root]# rpm -ivh --force --nodeps packagename.rpm

Uninstalling a Package

for uninstallation of rpm use command.
[root@localhost /root]# rpm -e rpm name
but here no need to give the .rpm extension.
TIPs :
changing text mode to graphical mode.
install the rpm of kde and genome for graphics.
use commands
rpm -ivh --aid kde-*
rpm -ivh --aid gnome-*
rpm -ivh --aid system-config-display-*
when these rpms are installed in your computer use commands
system-config-display for adjust the frequency of monitor

Querying a Package

Sometimes it is handy to know which packages are currently installed and what they do. You can do that with the RPM query options.
To list all installed packages, simply type

[root@localhost /root]# rpm -qa

Be ready for a long list of packages! If you are searching a particular package name, you can take advantages of grep command to specify the name (or part of the name) of the package, like so:

[root@lcalhost /root]# rpm -qa | grep -i 'bind'

Querying a Package
Querying a Package

The -i parameter in grep tells it to make its search case-insensitive.

If you just want to view all of the packages one screen at a time, you can use the more command, like so:
[root@localhost /root]# rpm -qa | more

To find out which package a particular file belongs to, type

[root@localhost /root]# rpm -qf /usr/bin/amidi

Querying a Package
Querying a Package

To find out the purpose of a package that is already installed, you must first know the name of the package (taken from the listing in rpm -qa) and then specify it, like so:

[root@tedford /root]# rpm -qi name

Where you can substitute any packagename in place of name.
Querying a Package
rpm -qi

To find out what files are contained in a package, type
[root@localhost /root]# rpm -ql pkname

where you can replace pkname with any packagename you want information about.
Querying a Package
rpm -ql

These above queries are about installed packages.
If you want to know the information appertain to uninstalled packages.
Use -p option
[root@localhost Packages]# rpm -qilp rpm name | more
In below example I have used -i.
Querying a Package
rpm -qip

Tape Archive: tar

The tar program combines multiple files into a single large file. It is separate from the compression tool, so it allows you to select which compression tool to use or whether you even want compression.
Although the name of the tar program includes the word "tape," it isn't necessary to read or write to a tape drive when creating archives. Initially developed to be written directly to sequential I/O devices for tape backup purposes,
Here's the structure of the tar command, its most common options, and several examples of its use:

[root@localhost /root]# tar [commands and options] filename

Option for tar Description
-c      Create a new archive.
-t      View the contents of an archive.
-x      Extract the contents of an archive.
-f      Specify the name of the file (or device) in which the archive is located.
-v      Be verbose during operations.
-z      Use gzip to compress or decompress the file.
-u      To upgrade the tar file

To create a tar file, enter:
[root@localhost mohit]# tar -cvf filename.tar directory [path of files]

In this example, filename.tar represents the file you are creating and directory/file represents the directory and file you want to put in the archived file.
Querying a Package
rpm -qip

You can tar multiple files and directories at the same time by listing them with a space between each one:
[root@localhost mohit]# tar -cvf filename.tar /firstdir /2nd dir
Linux Tar
Linux Tar creation

First it archive the /raj directory files then /mohitraj directory files. Now where have my.tar gone ? You can find your tar in present working directory.

To list the contents of a tar file
[root@localhost mohit]#tar -tvf filename.tar
Virtual Tar Extraction
Virtual Tar Extraction

To extract use command
[root@localhost raj]#tar -xvf filename.tar
Linux Tar Extraction
Tar Extraction
Remember, the tar command does not compress the files by default.

To update the tar file, use command
[root@localhost raj]#tar -uvf filename.tar /dir
Linux Tar updation
Tar updation
To verify, see the contents.

The gzip utility

The gzip package is a creation of the GNU Project.
This package includes the files:
  • gzip for compressing files
  • gunzip for uncompressing files
[root@localhost]# gzip [options] file_name
Linux gzip compression
gzip compression

Consider you multiple files say c programs you want to compress it simultaneously .
[root@localhost]# gzip *.*c
Linux gzip compression
gzip compression

For best compression use -9, and use -v for verbose form.
[root@localhost]# gzip -9v filename
Linux gzip compression -9
gzip best compression

For Fastest compression use -1 (one not L)
Like this
[root@localhost]# gzip -1v filename
To know the compression ratio use -l ( use file after compressed means .gz)
[root@localhost]# gzip -lv filename
Linux gzip compression ratio
gzip compression ratio

If want to change the all file recursively use -r it travel the directory structure recursively. If any of the filenames specified on the commandline are directories, gzip will descend into the directory and compress all the files it finds there (or decompress them in the case of gunzip).
[root@localhost]# gzip -rv *.*extension /dir
Linux gzip recursively
gzip compression recursively

If you want to change the name of the zipped file use -c.
[root@localhost]# gzip -c filename > name.gz
Linux gzip
gzip compression

Use gzip -L to know the license of gzip. Compressed files can be restored to their original form using gzip -d or gunzip.
Linux gzip
gzip compression

You learned two things
  • how to make archive file using tar
  • how to compress the files using Gzip
Ok when you will get a file like my.tar.gz First apply gzip operation to unzip the file then untar the file. Instead of using this you can use -xvzf with tar like this:
Linux gzip + untar
gzip + untar

Install downloaded software

  1. Unzip all the files within that new directory. (-xvfz)
  2. Execute the 3 (now famous) commands : configure, make & make install.

# ./configure

First give the permission to the configure file using chmod , then run configure file. The main job of the configure script is to create a ' Makefile ' . This is a very important file for the installation process.


Basically the make utility compiles all your program code and creates the executables.

#make install

When you run make install, these executables are copied to the final directories.

When unzip and untar the file, there will be a file called "Readme". Read that file for installation.

Adding the Executable Directory to the Path

As in Windows, the Linux path is a list of directories in which the system looks for executable files. If you have a directory that you want to add to the path, If you wanted to add the /cp directory to the path using the Bash shell, you could use this command:
[root@localhost~]# export PATH = $PATH:/cp
Before setting the path
Linux path setting
before exporting the path

After using command
Linux path exporting
After exporting the path

You can cp at the end. If don't use $ with PATH. Then it would not add the path but set only /cp as path abandon all other path
However, using above method, you can only modify the path for the current session. Once you log out, anything you've added to the path would be removed, so next time you log in it would have to be added again.
The way to modify the path variable permanently is to edit the .bash_profile file in Redhat & Centos and .bashrc in ubuntu & debian (assuming you are using the default bash shell). Login as that user for you want to add the path.
Consider mohit as user.
Open .bash_profile see the fig for help
exporting the path in .bash_profile

Default file like this
exporting the path in .bash_profile

To add /fine directory as path see the figure what you have to change. See the red arrow mark line add /fine directory like this.
exporting the path in .bash_profile
Adding path in .bash_profile

Once you have modified this file, save it and then execute it as follows :
exporting the path in .bash_profile
Path in path command

I hope you have enjoyed the chapter.