Special topics: Windows to Linux: Part 1 install software

Source: Internet
Author: User
Use pre-compiled rpm and compile applications from source code

Level: elementary

Chris Walden (cmwalden-at-us.ibm.com)
E-commerce architect, IBM developer relations
January 2004

IBM e-commerce architect Chris Walden willDeveloperWorksThe nine articles published in this article will guide you how to use your Windows Operating Skills in Linux. In the last part, we will download and compile a software package, discuss the advantages and disadvantages of automated package management, and understand the RPM System.

One of the first things you notice when installing Linux is that there are so many available packages in the Linux release version. Most releases come with Linux operating systems, Installation Tools, and management tools. They also include Internet tools, development tools, office tools, games, and programs you have never heard of before. Linux releasesThousandsAvailable packages are not uncommon. If you do not select "complete installation", only a subset of these packages will be installed.

Now you may want to know "how to delete unwanted packages? How to install the missing package? Can I use software not included in this release ?"

Rpm
When installing Linux, you may notice a lot of information about the RPM being installed.RPMRepresents the RedHat Package Manager, which is a contribution of RedHat and has become a standard for managing RedHat, unitedlinux, and many other releases of software.

Rpm is essentially a package that contains Linux software that can be installed and run on a specific machine architecture immediately. For example, in section 3rd. Webmin introduction, we installed the Webmin package through an RPM. All software originally loaded to the release version is installed with one rpm.

Rpm profiling
Rpm is a file package. The. spec file contains information about the package, its functions, and dependencies (that is, which packages must be installed before the package can run .. SPEC also contains a list of files in the package, specifying where these files must be loaded to the system and their initial permissions. RPM also contains the pre-installation script, which is compiled by the package developer. RPM also contains compiled binary files. Finally, the RPM contains the script after installation.

Rpm Structure

. Spec Pre-installation script Binary files Binary files ... Binary files Script after installation

When installing rpm, the system first checks whether the dependency of the package is satisfied. If the installation fails, the installation process ends unless you specify the option to force the installation to continue regardless of the situation.

If everything goes well, the script runs before installation. This script can do anything. It usually creates users and directories. However, it can do many types of dynamic configuration, and even compile and run the source code of the system in a custom way.

Learn where RPM comes from
When installing rpm, copy the file to your system and execute the script. Since RPM runs as root, all these functions are executed as root. Therefore, it is important to know the origin of an RPM before installing it to the system. Like many Windows software, malicious code can be easily included in RPM just as it is included in other packages. Rpm from the vendor is generally secure, but be cautious about random download and installation from unknown sources.

If the script is successfully installed, the binary file will be copied to the system according to the list. After all the files are copied and their permissions are set, the script runs after installation. Similarly, this script can do almost anything.

Once all these steps are completed, the package information is added to the RPM database, and the installation process is complete. With this simple mechanism, You can execute all the functions that can be performed through a more comprehensive commercial installation program.

Rpm Database
The elegance of RPM is the RPM database. This database is usually located in the/var/lib/RPM Directory, which contains information about each RPM installed on the system. This database knows the dependency between packages. When deleting a package, it will issue a warning when other packages cannot work. This database knows each file that was initially installed with a package and the initial state of these files on the system. It also knows the document and configuration file location of each package. This sounds like a lot of information, as it does. But it is not too large. On a system consisting of 1,066 packages and 203,272 files, the database file is only 45 MB! When the package is loaded and detached, RPM uses this database to check the dependency. You can also query the package information in this database.

Use rpm
The program used with the RPM package is namedrpm.rpmRun in different modes, but the most common tasks are installation, upgrade, query, verification, and deletion.

Rpm-I (installation)
When you install a package for the first time -iOr installation mode. You only need to direct the RPM to a Binary Package and execute it. Then, the RPM will install the package on your system. Generally, the installation process takes only a few seconds. I often use-v(Detailed) switch to provide more information about the process and use-hThe (hash line) Switch provides the installation progress update by outputting the hash (#) symbol on the console. The following is an example of installing a package:

Listing 1. Installing MyPackage

$ rpm -ivh MyPackage-1.0.0.i386.rpmPreparing...                ########################################### [100%]   1:MyPackage              ########################################### [100%]

That's it! MyPackage is now installed and available.

Rpm must run as root
Must be executed as rootrpmInstallation and deletion, because you need to access the file system and RPM database.

Rpm-e (delete)
To delete an installed package, you can use-eSwitch.rpmAll files in the package will be deleted using the database. If other packages that have been installed depend on the packages being deleted,rpmWill exit unexpectedly. You must usenodepsSwitch to force Delete (nodepsIt can also be used for force installation ). When using this switch to force installation or deletion, be sureVeryBe careful. Deleting the packages that other packages depend on may lead to disastrous results. The following command deletes the package we installed on it:

$ rpm -e MyPackage

Note that deleting a package does not necessarily require its complete name (including the version number ). The complete name is required during installation, because we are referencing a file name. Installed packages are referenced only by their names. The package name is all the content before the version number.

Rpm-V (verification)
The verification switch is very useful. It compares the current status of package files with their original status during installation. The difference between the two States is displayed with one code:

File verification results

S Inconsistent File Size
M Inconsistent modes (including permissions and file types)
5 Inconsistent MD5 checksum
D The device primary/secondary numbers do not match
L ReadLink (2) path Mismatch
U Inconsistent user ownership relationships
G Inconsistent group ownership relationships
T Inconsistent mTime

If you runrpm -VAnd the size of an executable file has changed, which may be a sign of a security vulnerability.

Rpm-U (upgrade)
Once a package has been installed, an attempt to install a package with the same name will generate a message indicating that the package has been installed. To upgrade a package to an updated version, use -USwitch to upgrade. The upgrade has another impact. When the upgrade is performed for multiple package names, it will try to place the packages in the order of dependency. In other words, the required package will be installed first. Whether or not a package is installed, you can use the upgrade switch for it. Many people use it instead-iSwitch to install and upgrade. The following is an example of using the upgrade switch to load multiple rpm packages:

List 2. Interactive upgrade

$ rpm -Uvh My*.rpmPreparing...                ########################################### [100%]   1:bMyPackageDep          ########################################### [ 50%]   1:aMyPackageNew          ########################################### [100%]

In the preceding example, bMyPackageDep is a prerequisite for aMyPackageNew, so although the file names are listed in reverse order,rpmThey are also sorted correctly.

Rpm-q (query)
You can query a variety of useful information from the rpm database. Any user with read access to the rpm database can run the query. By default, all users have the read permission. To run a query, you can use-qThe name of the package to be queried. This will return the version of the package.

$ rpm -q MyPackage
MyPackage-1.0.0

The package name must be exactly matched. Wildcards are not allowed. However, you can usegrepTool to help find it. Available-qaTo query all installed packages.grepTo output the information you can remember. For example:

Grep
grepIs a widely used text search tool. By default,grepSearch for a file to display the specified row. In this example, it searches for the word "IBM ".grepIt is a powerful tool for scripting and console work.

$ rpm -qa | grep IBM
IBMWSAppDev-Product-5.0-0
IBMWSSiteDevExp-Core-5.0-0
IBMWSSiteDev-Core-5.0-0
IBMWSTools-WAS-BASE-V5-5.0-0
IBMJava118-SDK-1.1.8-5.0
IBMWSWB-samples-5.0-0
IBMWSWB-5.0-0
IBMWSAppDev-Core-5.0-0
IBMWSAppDev-5.0-0
IBMWSTools-5.0-0

Except the version number,rpm -qYou can also provide other useful information about the package. The following are some examples:

Use rpm to query and obtain information

rpm -q changelog Show the development and change history of the package
rpm -qc Display the package configuration file
rpm -qd Show the document file of the package
rpm -qi Show Package Description
rpm -ql Display the file list of the package
rpm -qR Show package Dependencies

There is another interesting query command, which runs on files instead of packages.

rpm -q whatprovides <filename>

The above command recognizes the packages associated with the given filename (file name. Filename must include the absolute path of the file, because the information is stored in the rpm database in this way.

RPM front-end
Operate from the consolerpmIt is easy, but sometimes it is more convenient to use a graphical user interface. In a typical Linux style, some front-end programs provide interfaces for rpm programs. Each release version has a front-end, but they are different. For more information about the provided package management tools, see your release document.

Webmin Software Package
Webmin also provides a simple Web-based front-end for processing RPM packages.

Figure 1. Webmin RPM page

The software can be easily installed, deleted, and queried from this interface. You can also install software directly from the URL site. IfaptOr RPM enhancement tools such as RedHat network, Webmin will recognize them and provide them with an interface.

Source code
Since Linux is an open-source operating system, it comes with all the development tools required to compile the software. Although most of the packages you use will be provided in the form of binary rpm, you are not limited to those packages. If you want to, you can download the original source code for your system and compile it in a custom manner.

Exercise caution when compiling source code on the production system, as this may cause problems or no longer support commercial software (such as IBM DB2) that is being used on the system ). However, familiarity with the process of compiling software from source code will enable you to patch software applications and use packages ported from other environments. Once the code is compiled successfully, you can also create your own RPM!

Corewars source code demonstration
To demonstrate how easy it is to compile software from source code, we will compile a simulation game named corewars (see references ). The following is a description of corewars from their Web site: "corewars is a simulation game, many of which attempt to attack each other while running on virtual computers. One of the two languages similar to assembler can be used to write a samurai program, which is called corewars and redcode respectively. Corewars is the default language, making it easier to learn and understand. Redcode provides more advanced and powerful commands, but it takes more time to learn ."

The first step to compile the source code is to download the source code package from the Web site:

  • Http://download.sourceforge.net/corewars/corewars-0.9.13.tar.gz

After the code is downloaded, expand the package.

tar -xvzf corewars-0.9.13.tar.gz

The file is expanded to the current directory. The standard practice is to include the source code in a directory that matches the product name. In this example, the source code is located in a directory named corewars-0.9.13.

First, go to the directory and find the source code and some documents, configuration scripts, and README files. Most source code packages contain a file named INSTALL and README. You should read these materials before compiling the software. They identify the problem before the problem occurs, and suggest correct compilation and Installation Steps for you, so that you can avoid a lot of detours. Most of the problems I encountered when compiling the source code are because I did not follow those guidelines.

The next step is to runconfigureScript.configureIs part of the Autoconf package, including in the development tool of the Linux release version. Here we reference the Autoconf Package Description: "GNU Autoconf is a tool used to configure source code and Makefile. By using Autoconf, programmers can create portable and configurable packages, because the package owner can specify various configuration options ."

configureThe script runs a series of tests on the system to determine the best way to compile packages for your release version and system architecture. Then it creates a customized Makefile for your system. If problems occur during compilation on your system,configureYou will be notified.configureYou are usually allowed to customize the features to be included in the compilation, or to provide location parameters about the library or other required files, so that the package can be compiled successfully. The following code does not contain parametersconfigure:

./configure

After multiple tests are executed on the system, the compilation is successful. Run the following command to generate a program:

make

If there are compilation errors, you need to confirm the problems and fix them. This may be a tedious task and may require a lot of general knowledge about the environment and programming. If everything goes well, we usually use the following command to install the software:

make install

The file will be copied to the correct location in the system, the file permission will be updated, the configuration file will be copied, and the document will be added to the book page.

Now we can test our labor results by executing this program. It is a graphical program, so you need to run the X system before starting it. Themake installThe command should have placed the program in the executable file path.

corewars

As a reward for us, a graphic screen should appear.

Figure 2. Success!

The subject of corewars rules is beyond the scope of this article, but you will (man corewars.

Corewars compilation is a typical scenario. There may be many other forms of change, includingconfigureUse the switch on the script to adjust the features to be compiled into the program, and use different commands from Makefile to adjust the compilation method.

This program is not installed using rpm, so there are no corresponding entries in the rpm database. If a program does not run as expected after installation, most makefiles include an uninstall parameter to delete the software:

make uninstall

Be sure to keep in mind that using the original source code will not add anything to the RPM database. The software installed in this way is unmanaged, so proceed with caution.

Source code RPM
When RPM is created, there is also a product called source code RPM. This is a SPEC file combined with source code, designed to generate programs on one or more architectures. This is the best for both source code and binary! For source code RPM, you can customize the compilation software on the system, but the finished product will be an installable RPM instead of the original binary. Most packages available in the form of pre-compiled RPM are also available in the form of SRPM. This may be a simple way for cross-platform software transfer in Linux. When you successfully recompile on a different platform, you can consider sharing the completed RPM with the entire development community.

Maybe the source code is more suitable for you
If you are a beginner in Linux, the method for installing software is different from the method you used in the past. However, the RPM installation method is elegant and provides new capabilities that you will soon appreciate.

You should be familiar with the options for using rpm from the console, but for daily use, there are some front-end interface options to make the rpm easier to manage. Your release version provides such an interface, and other similar interfaces are available, such as the interface in Webmin.

You can not only use pre-compiled rpm, but also use the open-source nature of Linux to directly compile applications from the source code. Compilation is usually easy for mature projects. Remember, the Code installed from the source code does not have corresponding entries in the rpm database. When using source code, you can consider using source code rpm, which combines the powerful capabilities of compiled source code and the manageability of rpm.

References

  • Read Other sections of the Windows to Linux journey series (DeveloperWorks, January 1, November 2003 ).

  • IBMDeveloperWorksTutorial LPI certification 102 exam prep, Part 1: Compiling sources and managing packages Describes Red Hat and Debian package managers, as well as source code compilation and management of shared libraries.
  • IBMDeveloperWorksTutorial Compiling and installing software from sources in-depth discussions about packages, checks, configurations, and installing software packages from source code.
  • IBMDeveloperWorksTutorial LPI certificate 102 exam preparation, Part 1: configuration and compilation kernel describes important kernel configurations and PCI and USB support in the kernel.
  • Through IBMDeveloperWorksSpecial series Compiling and installing software from sources, learn more about Linux source code compilation and installation.
  • Through IBMDeveloperWorksCreate Debian Linux package and use RPM package to learn how to create your own package.
  • At IBMDeveloperWorksThis topic uses the Stow management package to learn about the RPM and Debian package management solutions.
  • Frequent software upgrades are an important part of ensuring security. Through IBMDeveloperWorksTIPS: update the application from the source code and learn how to keep the system up to date.
  • In this IBMDeveloperWorksLearn more about United Linux in the special edition.
  • SourceForge is an excellent reference for open source projects. You can also add your own projects.
  • The Corewars project is only one of the many projects published on SourceForge.
  • DeveloperWorksThe open source code area hosts an open source project from IBM.
  • IBM's alphaWorks allows easy access to emerging IBM technologies, including content such as Web Services and grid toolboxes.
  • IBM provides Toolbox subscriptions that highlight the single-user, low-cost license features of accessing core IBM tools, middleware and technology.
  • IBM provides a free Linux software evaluation package (SEK) for your Linux Application Development Acceleration Program ), including DB2 Universal Database, WebSphere Application Server, WebSphere Studio Site Developer, WebSphere MQ, Lotus Domino, Tivoli Access Manager ......, Wait!
About the author
Chris Walden is an IBM developer relations Technical Consulting (also knownDragonslayersE-commerce architect, which provides education, implementation, and consulting for IBM business partners. He is dedicated to Linux-related work and will publicize the benefits of Linux to people around him as soon as he has the opportunity. In addition to fulfilling the responsibilities of his architect, he is also proficient in various fields of Linux infrastructure servers, including files, printing and other application services in the hybrid platform user environment. Chris has 10 years of experience in the computer industry. From field support to Web application development and consulting, he has been involved in various fields. You can contact Chris via cmwalden-at-us.ibm.com.

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: info-contact@alibabacloud.com 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.