Topic: Windows to Linux Tour: Part 9. Installing Software

xiaoxiao2021-03-06  74

Compile applications using precompiled RPM and from source code

Level: primary

Chris Walden (cmwalden-at-us.ibm.com) e-commerce architect, IBM Developer Relations, January 2004

IBM e-commerce architect Chris Walden will pass him

The nine series of articles published on DeveloperWorks guides you how to use your Windows operation skills in your Linux environment. In this last part, we will download and build a package, discuss the advantages and disadvantages of automated package management, and learn about the RPM system.

One of the things that is noted when installing Linux is that there is so many available packages in the Linux release. Most release versions come with Linux operating system, installation tools, and management tools. They also include Internet Tools, Development Tools, Office Tools, Games, and some programs you have never heard of. The Linux distribution version comes with thousands of available packages. If you don't have "full installation", you will only have a subset of these packages.

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

RPM When you install Linux, you may notice many of the information about the RPM being installed. RPM represents Redhat Package Manager (Red Hat Package Manager), which is the contribution of Redhat, which has now become the standard for managing Redhat and UnitedneTEDLinux and many other distributions.

RPM is essentially a package that contains Linux software that can be installed and running on a specific machine architecture. For example, in "Part 3. Webmin Introduction", we installed a webmin package through an RPM. All software initially loaded into the release is installed by an RPM.

RPM analysis rpm is a file package. It includes information about the package and its functions and dependencies (ie, which packages must be installed before this package can be run. .spec also contains file list in the package, specify where these files must be loaded into the system, and how their initial permissions are. The RPM also contains the pre-installation script, which is written by the package developers. RPM secondly contains compiled binaries. Finally, RPM contains a post-installation script.

RPM structure

.SPEC installation front script binary binary file ... binary file post-installation script

When installing RPM, the system first checks whether the dependency of the package is met. If it is not satisfied, the installation process will terminate unless you specify an option to continue to continue.

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

Learn about where rpm from RPM is installed on your system and performs scripts. Since rpm is run as root, all of these features are executed as root. Therefore, it is important to know that it is important before the RPM is installed to the system. Just like many Windows software, malicious code can be easily included in RPM as contained in other packets. RPM from vendors is generally safe, but it is necessary to be vigilant for content that is randomly downloaded and installed from unknown sources.

If the installation script is successfully completed, the binary will be copied to the system in accordance with the list. After copying all files and settings their permissions, the script will run. Similarly, this script can almost do anything.

Once all these steps are completed, the information about the package is added to the RPM database, and the installation process is completed. With this simple mechanism, you can perform all features that can be performed through a more complete business installer. The elegance of the RPM database RPM is the RPM database. This database is usually located on the / var / lib / rpm directory that contains information about each RPM installed on the system. This database knows the dependencies between the package. When a package will cause other packets that cannot be worked, it will issue a warning. This database knows that each file installed in a package and the initial state of these files on the system. It also knows the location of each package and the location of the configuration file. This sounds like a lot of information, in fact it is true. But it is not too much and huge. On a system consisting of 1,066 packages, consisting of 203,272 files, the database file is only 45 MB! When loading and uninstalling the package, RPM uses this database to check the dependencies. Users can also query information about the package in this database.

The program used with the RPM with the RPM package is named RPM accordingly. RPM runs in a variety of different modes, but the most common task is to install, upgrade, query, verification, and deletion.

RPM -I (installed) When you install a package, you want to use -i or installation mode. Just point the rpm to a binary package and execute it, RPM will install the package to your system. The installation process is generally only a few seconds. I often use the -v (detailed) switch while installing the package to provide more information about the process, and using the -H (Hash Line) switch to provide installation by outputting the hash (#) symbol on the console Schedule update. Here is an example of installing a package:

Listing 1. Install Mypackage

$ rpm -ivh mypackage-1.0.0.i386.rpm

Preparing ... #################################################### ]

1: mypackage ############################### [100%]

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

RPM must run with root must perform RPM installation and deletion as root, as you need to access file systems and RPM databases.

RPM -E To delete the installed package, you can use the -e switch. RPM will use the database to delete all the files of the package. If there is a package that has been installed dependes on the packet being deleted, the RPM will exit an abnormally. You must use the NODEPS switch to perform forced deletion (Nodeps can also be used for mandatory installation). Be sure to be very careful when using this switch to force installation or delete. Deleting the package depends on other packages may result in catastrophic results. Below this command deletes our package installed above:

$ rpm -e mypackage

Note that the deletion of the package does not necessarily require its full name (including the version number). The full name is required during installation, because we are referenced to a file name. The installed packets are only referenced by their name. The name of the package is all the content before the version number.

RPM -V (Verify) Verification Switter is very useful. It compares the current state of the package file with their original state at the time of installation. The difference between the two states will be displayed with a code:

File verification result

S File size is inconsistent M mode inconsistent (including permission and file type) 5MD5 check and inconsistency D device main / secondary number Do not match LreadLink (2) Path Mismatch U User Has relationship The inconsistency G group has inconsistent TMTIME inconsistent

If you run rpm -v for a package, and find a change in the size of a executable file, it may be a sign of security vulnerabilities. RPM -U (upgrade) Once a package is already installed, attempt to install a package that has the same name will generate a message, indicating that the package is already installed. If you want to upgrade a package to an updated version, you can use the -U switch to upgrade. The upgrade also has another impact. When the multiple package name is upgraded, it will try to place the package in the order of dependencies. In other words, the required package will be installed first. Regardless of whether a package is already installed, it can be used to use an upgrade switch, and many people use it instead of using the -i switch to perform installation and upgrade. Here is an example of using an upgrade switch to load multiple RPM packages:

Listing 2. Interactive upgrade

$ rpm -uvh my * .rpm

Preparing ... #################################################### ]

1: bmypackagedep ############################ [50%]

1: amypackagenew ############################ [100%]

In the above example, BmyPackageDep is a prerequisite for AmyPackageNew, so that although the file name is arranged in the opposite order, RPM will be properly sorted.

RPM -Q (query) can query a variety of useful information from the RPM database. Any user with the RPM database has read access rights can run a query. By default, all users have read access. To run a query, you can use the name of the package you want to query on the -Q switch. This will return the version of the package.

$ rpm -q mypackagemypackage-1.0.0

The name of the package must be precisely matched and unsuccessful is not allowed. However, if you can't remember the full name, you can use the GREP tool to help find it. You can use the -QA switch to query all installed packets and use grep to pipe the information you can remember. E.g:

GREP Tracing Grep is a text search tool with a wide range of purposes. By default, GREP will search the file to display the row you specify. In the example here, it searches for words "IBM". GREP is a powerful tool for scripting and console work.

$ Rpm -qa | grep IBMIBMWSAppDev-Product-5.0-0IBMWSSiteDevExp-Core-5.0-0IBMWSSiteDev-Core-5.0-0IBMWSTools-WAS-BASE-V5-5.0-0IBMJava118-SDK-1.1.8-5.0IBMWSWB-samples-5.0-0IBMWSWB -5.0-0IBMWSAPPDEV-CORE-5.0-0IBMWSAPPDEV-5.0-0IBMWSTOOLS-5.0-0

In addition to the version number, RPM -Q can also provide other useful information about the package. Here is some examples:

Use rpm query to get information

RPM -Q Changelog Display Package Development Change History RPM -QC Display Package Profile RPM -QD Display Pack Document File RPM -QI Display Package List RPM-QL Display Package List RPM -QR Display Package Dependency

There is another interesting query command that is run for the file instead of the package.

RPM -Q WhatProvides

The above command will identify the package associated with a given FileName (file name). FileName must include the absolute path of the file, because the information is stored in this manner in the RPM database.

The RPM front end is easy to operate from the console, but sometimes it is more convenient to use the graphical user interface. In a typical Linux style, there are some front-end programs to provide an interface for the RPM program. Each release version has a front end, but they are different. Please refer to your distribution version of the text to learn about the information provided by the package management tool. Webmin package Webmin also provides a web-based simple front-end for processing RPM packages.

Figure 1. Webmin RPM interface

Software can easily install, delete, and queries from this interface. You can also install software directly from the URL site. If the RPM enhancement tool such as APT or Redhat Network is installed, Webmin will identify them and provide them with an interface.

Source code Because Linux is an open source operating system, it comes with all developments required for compiling software. Although most packages you use will be provided in the form of binary rpm, you are not only limited to those packages. If you prefer, you can download the original source code for your system and compile in a custom manner. It should be cautious on the production system, as this may result in problems, or no longer support commercial software (such as IBM DB2) on the system (such as IBM DB2). However, the process of familiarizing from the source code compilation software will enable you to apply patches for software, and packages that are transplanted from other environments. Once you have successfully compiled code, create your own RPM can be done!

CoreWars Source Code Demo is more simple for demo from source code compilation software, we will compile a simulated game called CoreWars (see Resources). Here is a description of the Corewars from their Web site: "Corewars is an analog game, where many samurans are trying to attack each other when running in the virtual computer. You can use the language of the two kinds of assembler to write a language. Samurai procedures, these two languages ​​are called CoreWars and RedCode.corewars are the default language, easier to learn and understand. Redcode provides higher and more powerful instructions, but requires more time to learn. "

The first step in compiling 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 download is complete, you need to expand this package.

Tar-xvzf corewars-0.9.13.tar.gz

The file will be expanded to the current directory. The standard practice is to include the source code in a directory that matches the product name. In this case, the source code is located in a directory called CoreWars-0.9.13.

First enter the directory, find the source code and some documents, configure scripts, and readme files. Most source code packs have a file called install and a member called Readme. You should first read these materials before compiling the software. They identify problems before the problem and suggest the correct compilation and installation steps, which usually allows you to take a lot of detours. Most questions I have encountered when compiling source code are because I don't follow those guidance.

The next step in the usual execution is to run the Configure script. Configure is part of the AutoConf package, including in the development tool in Linux release. Here, a section of AutoConf is here: "The GNU's AutoConf is a tool for configuring source code and makefile. By using AutoConf, programmers can create portable and configurable packages, because people built package can specify various configurations Options. "

The Configure script runs a series of tests on the system to determine the best way to compile your distribution and system architecture. Then it creates a custom Makefile for your system. If you encounter problems in your system, Configure will tell you. Configure typically allows you to customize features that will be included in the compilation or allow you to provide location parameters for libraries or other required files to successfully compile packets. Below we will do configure: ./ Configure

Execute several tests on the system, and eventually compile success. The following command is used to generate a program:

Make

If you have errors, you need to determine the problem and fix them. This may be a cumbersome task that may require a lot of general knowledge about the environment and programming. If everything goes well, we generally use the following command to install the software:

Make Install

The file will be copied to the correct position in the system, and the file permissions will be updated, and the configuration file will be copied, and the document will also be added to the man page.

Now use the program to test our labor results. It is a graphical program, so you have to run the X system before starting it. The made install command executed above should have placed the program in the executable file path.

Corewars

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

Figure 2. Master!

The theme of the Corewars rule exceeds the scope of this article, but you will find documents about this interesting analog game in the man page (Man Corewars).

Compilation of CoreWars is a typical scene. There may be many other variations, including using the switch on the Configure script to adjust the feature to be compiled into the program, and adjust the compilation mode from Makefile to adjust compilation, and so on.

Since this program is not installed using RPM, there is no corresponding entry in the RPM database. If a program is not running on the expected operation, most makefile includes an uninstall parameter to delete the software:

Make Uninstall

Be sure to keep in mind, using the original source code will not add anything in the RPM database. Software installed in this way is unmanaged, so it should be careful.

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

Perhaps source code is more suitable for you if you are a Linux newbie, the installation software method is different from your past habits. However, the RPM installation method is elegant and provides you with new ability to appreciate quickly.

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

You are not limited to the use of precompiled RPM, and you can also use Linux's open source code to compile applications directly from the source code. For mature projects, compile is often easy. Remember, the code installed from the source code has no corresponding entry in the RPM database. When using the source code, you can consider using the source code RPM, which combines the powerful capabilities of the compiled source code and the manageability of RPM. Reference

Read the other parts of Windows to Linux Tour Series (DeveloperWorks, November 2003). IBM DeveloperWorks Tutorial LPI Certification 102 Exam PREP, Part 1: Compiling Sources and Managing Packages introduces the Red Hat and Debian package manager, and from the source code compiler and management shared library. IBM DeveloperWorks Tutorial CompiLing and Installing Software from Sources In-depth discussion, check, configure, and slave the source code installation package. IBM DeveloperWorks Tutorial LPI Certificate 102 Exam Preparation, Part 2: Configuring and compiled kernels show important kernel configuration and PCI and USB support in the kernel. Learn more knowledge about the source code compilation and installation on Linux via IBM DeveloperWorks Special Encycloped. Create a debian Linux package through the IBM DeveloperWorks special, how to create your own package with RPM package software. In the IBM DeveloperWorks Special, use the Stow management package to learn about the replacement of RPM and DEBIAN's package management solutions. Regular upgrade software is an important part of ensuring security. Through IBM DeveloperWorks about tips: start upgrading the application from the source code to learn how to easily quickly keep the system in the latest. Learn more about United Linux in this IBM DeveloperWorks Special. SourceForge is an excellent reference for open source code projects; you can also add your own project. Corewars Project is just one of many projects published on SourceForge. The developerWorks open source zone hosts an open source project of IBM. IBM AlphaWorks allows easy access to emerging IBM technology, including content such as Web services and grid toolboxes. IBM provides Toolbox subscriptions, highlighting a single user, middleware, and technical single users, low-cost licenses. IBM provides free Linux software evaluation packages (SEK) for your Linux application development, including DB2 Universal Database, WebSphere Application Server, WebSphere Studio Site Developer, WebSphere MQ, Lotus Domino, Tivoli Access Manager ..., etc. !

转载请注明原文地址:https://www.9cbs.com/read-121421.html

New Post(0)