Install the RPM package or the source package

Source: Internet
Author: User

Install the RPM package or the source package

Chapter 2 InstallRPMPackage or install the source package

It is easy to install a software in windows. You only need to double-click the .exe file, and the installation prompt is "Next". However, installing a software in linux does not seem so easy, because we are not in the graphic interface. Therefore, you must learn how to install a software in linux.

Yum, which has been mentioned many times in the previous content, is a unique tool for installing the RPM package for Redhat. It is quite convenient to use. If you use RPM to install a package, the package may not be installed because it depends on another package. The yum tool can be installed together with the dependent package. Of course, CentOS can also use the yum tool, and you can use yum for free in CentOS. However, in Redhat, yum is unavailable only after you pay for it. Before introducing yum, let's talk about RPM-related things.


RPM is the abbreviation of "Redhat Package Manager", which is developed by Redhat according to the name. RPM is a set of management programs that install the required kits to your Linux host in a database record manner. In other words, there is a database about RPM in your linux system, which records the installed packages and dependencies between packages. The RPM package is a pre-compiled and packaged file on a linux machine. It is fast to install. However, there are also some disadvantages, such as the installation environment must be consistent with or equal to the compiling environment; there is dependency between packages; when uninstalling a package, you must first uninstall the dependent package. If the dependent package is required by the system, You Cannot uninstall the package. Otherwise, the system will crash.

If you still have system installation disks in your optical drive, you can mount the optical drive to the/mnt directory by running the "mount/dev/cdrom/mnt" command, you will see a lot in the/mnt/CentOS directory. rpm file. This is the RPM package.

The name of each rpm package is divided into several parts by "-" and. Take the a2ps-4.13b-57.2.el5.i386.rpm package to explain, a2ps for the package name; 4.13b for version information; 57.2.el5 for the release version number; i386 for the operating platform. Among them, i386, i586, i686, and x86_64 are common running platforms. Note that the cpu is currently divided into 32-bit and 64-bit, and i386, i586, and i686 are both 32-bit platforms, x86_64 indicates a 64-bit platform. In addition, some rpm packages do not have a specific platform but noarch, which means that this rpm package has no hardware platform restrictions. For example, alacarte-0.10.0-1.fc6.noarch.rpm. The following describes common rpm commands.

1) install an rpm package

-I: Installation meaning

-V: Visualization

-H: displays the installation progress.

In addition, the following parameters are often used to install an rpm package:

-- Force installation, even if it overwrites files of other packages

-- Nodeps when the rpm package to be installed depends on other packages, you must install this package even if other packages are not installed.

2) upgrade an rpm package

Rpm-Uvh filename-U: indicates the upgrade.

3) uninstall an rpm package

Rpm-e filename the filename here is queried through the rpm query function. It will be introduced later.

There is a difference between the filename and the installed filename at the time of uninstallation. The "|" mentioned in the preceding command is also very useful in linux systems. It is a pipeline operator used to pass the preceding running results to subsequent commands. In the future, we will give a detailed introduction. The grep command that appears later is a tool used to filter a keyword, which will be detailed in subsequent chapters.

4) check whether a package is installed.

Rpm-q rpm package name (the package name here does not contain platform information or suffix)

If the platform information and suffix are added, it cannot be found. You can also query all the rpm packages installed in the current system.

Because there are too many, I will list the top 10.

5) obtain the rpm package information.

Rpm-qi package name (no platform information or suffix is required)

6) list the files installed in an rpm package.

Rpm-ql package name

The above command shows that vim is obtained by installing the rpm package of the vim-enhanced-7.0.109-6.el5. In turn, how can we find out which rpm package was installed through a file?

7) list which rpm package a file belongs

Absolute path of the rpm-qf File

We have discussed how to find the absolute path of a file (executable command ).

So you can connect the two commands to write them.

As you can see, the which vim command is caused by two backquotes, which indicates the result of referencing the commands in the backquotes. There is still a lot of content about the use of rpm tools. I will not list them one by one. As long as you master the above content, it is enough for your daily work.


After introducing the rpm tool, you also need to master the most commonly used yum tool, which is much easier to use than the rpm tool, provided that the linux system you use supports yum. The biggest advantage of yum is that it can download the required rpm package online and then install it automatically. If the rpm package to be installed in this project has dependencies, yum will help you solve these dependencies and install all rpm packages in turn. The following describes common yum commands.

1) list all available rpm packages "yum list"

I will only list the first seven packages. As shown in the preceding example, the message "" appears, indicating that it is the rpm package resource downloaded from If you are using CentOS, you can see the relevant configuration information under the/etc/yum. repos. d/CentOS-Base.repo file. In the preceding example, you can see that the rpm package name is on the left, the version information is in the middle, and the installation information is on the right. If the rpm package is installed, installed is displayed, if the rpm package is not installed, the base or extras is displayed. If the rpm package is installed but the upgrade is required, the updates is displayed.

2) search for an rpm package "yum search [related keywords]"

In addition to this search, I often use grep to filter

I believe you will also like to use the latter, which looks much more concise.

3) install an rpm package "yum install [-y] [rpm package name]"

If the-y option is not added, the installation will be performed in an interactive manner with the user. The first step is to list the rpm package information to be installed, and then you will be asked if you need to install the package. Enter y to install the package, if n is entered, no installation is performed. I think this is too troublesome, So I directly add the-y option to omit the step to ask the user whether to install it.

4) uninstall an rpm package "yum remove [-y] [rpm package name]"

Just like the installation, you can simply add the-y option to omit the steps for interacting with users. Here, I would like to remind you that it is clear to uninstall an rpm package. Do not detach other important rpm packages together to avoid affecting normal business.

4) upgrade an rpm package "yum update [-y] [rpm package]"

This section describes how to use yum to search, install, uninstall, and upgrade an rpm package. If you have mastered this, you can solve the rpm package-related problems in your daily work. Of course, the yum tool has many other useful commands. I will not list them. If you are interested, go to man. In addition, I will teach you some small applications about yum.

1Use a Local CD to createYumSource

Sometimes your linux system cannot be connected to the Internet, and of course you cannot easily use the online yum source. At this time, you need to use the linux system CD to create a yum source. The procedure is as follows:

A. Attach a cd

[Root @ fortest Server] # mount-t iso9660-o loop/dev/cdrom/mnt

B. Delete All repo files in the/etc/yum. repos. d directory.

[Root @ fortest Server] # rm-rf/etc/yum. repos. d /*

C. Create a new file, dvd. repo

[Root @ fortest Server] # vim/etc/yum. repos. d/dvd. repo

Add the following content:


Name = install dvd

Baseurl = file: // mnt

Enabled = 1

Gpgcheck = 0

D. Refresh the repos and generate the cache.

[Root @ fortest Server] # yum makecache

Then you can use the yum command to install the required software package.

2ExploitationYumDownload a toolRpmPackage

Sometimes, we need to download an rpm package, just download it and copy it to other machines for use. We also mentioned earlier that when installing the rpm package in yum, we must first download this rpm package and then install it, therefore, you can use yum to download only without installing it.

A. Install yum-downloadonly first.

# Yum install-y yum-downloadonly.noarch

B. Download an rpm package without installing it.

# Yum install test. rpm-y -- downloadonly // even though this is downloaded, It is not saved to the desired directory. How do I specify a directory?

C. Download to the specified directory

# Yum install test. rpm-y -- downloadonly -- downloaddir =/usr/local/src

Install the source package]

In fact, installing a source code package in linux is the most common. In my daily management work, most of the software is installed through the source code. To install a source code package, we need to compile the source code into a binary executable file. If you understand the source code, you can modify the source code customization function and compile it into what you want. The benefits of using the source code package can be customized in addition to modifying the source code, as the source code package can be added with additional options during compilation.

The compilation of the source code package uses the compiler in linux. common source code packages are generally developed in C language. This is also because the C language is the most standard programming language in linux. The C language compiler on Linux is called gcc, which can be used to convert the C language into executable binary files. So if gcc is not installed on your machine, there is no way to compile the source code. You can use yum install-y gcc to complete the installation.

Installing a source code package usually requires three steps:

1../config can be customized in this step, and corresponding options can be added. You can view the options by running the "./config -- help" command. In this step, the system will automatically check whether your linux system has any libraries required to compile the source code package, because the compilation cannot be completed once a library is missing. A Makefile is generated only after the check is successful.

2. make uses this command to compile Based on the preset parameters in the Makefile file. This step is actually done by gcc.

3. make install Installation Steps to generate related software storage directories and configuration files.

The three steps described above are not the same for all source code packages. I have encountered them before. The installation steps are not the same, that is to say, the installation of the source code package does not have certain standard installation steps. In this case, you need to obtain the source code package and decompress it, and then go to the directory to find the relevant help documentation. Usually, the file name is INSTALL or README. So, you must take a look. The author will compile and install a source package to help you better understand how to install the source package.

1. Download a source code package

We recommend that you put all the downloaded source code packages under the/usr/local/src/directory. This is not necessary, but a convention. It is convenient for you and your colleagues to better operate and maintain this server in the future. Wget is the download command, followed by the source code package. This address is an apache address from the Internet.

2. decompress the source code package

The general source code package is a compressed package, as described in the previous chapter on how to decompress a .tar.gz package.

3. Configure related options and generate Makefile

You can use./config -- help to view available options. The "-- prefix = PREFIX" option is commonly used to define where the software package is installed. Here, I propose another small convention. Generally, the source code package is installed in the/usr/local/directory. For example, if we install apache under/usr/local/apache2, we should write "-- prefix =/usr/local/apache2" here ". There are many other options. If you have the patience, you can go one by one to see what it will do.

Here I only define the installation directory of apache, and the others are default. Press enter to start the check operation.

Makefile is generated after check.

Besides checking whether the Makefile file has been generated to determine whether the./config operation has been completed, you can also run the "echo $?" command ?" If it is 0, the previous operation is successfully completed. Otherwise, the operation fails.

4. Compile

This step is to compile the source code into a binary executable file, which is also the longest step. The length of compilation time depends on the source code quantity and machine configuration.

5. Install

Before installation, check whether the previous operation is successful.

Make install creates directories and files. After the installation is complete, an apache2 directory will be added to the/usr/local directory, which is the directory where apache is installed.

In fact, in the daily source code installation work, not all of them are successfully installed like the author. There are many situations where installation cannot be completed due to errors. This is usually because a library file is missing. This requires you to carefully check the error message or view the config. log in the current directory to obtain the relevant information. In addition, if you cannot solve the problem, google it online. You will usually get the answer you want.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.