Showing posts with label rpms. Show all posts
Showing posts with label rpms. Show all posts

Tuesday, 8 November 2016

Working With RPMs

The RPM Package Manager (RPM) is an open packaging system that runs on Red Hat Enterprise Linux as well as other Linux and UNIX systems. The RPM Package Manager only works with packages built in the RPM format RPMmaintains a database of installed packages and their files, so you can invoke powerful queries and verifications on your system.
For the developer, RPM enables software source code to be packaged into source and binary packages for end users. This process is quite simple and is driven from a single file and optional patches that you create.

RPM Design Goals:

Upgradability
                      With RPM, you can upgrade individual components of your system without a complete reinstallation. When you get a new release of an operating system based on RPM, such as Red Hat Enterprise Linux, you do not need to reinstall a fresh copy of the operating system on your machine (as you might need to with operating systems based on other packaging systems). RPM allows for intelligent, fully-automated, in-place upgrades of your system. In addition, configuration files in packages are preserved across upgrades, so you do not lose your customizations. There are no special upgrade files needed to upgrade a package because the same RPM file is used to both install and upgrade the package on the system.

Powerful Querying
                               RPM
is designed to provide powerful querying options. You can perform searches on your copy of the database for packages or even just certain files. You can also easily find out what package a file belongs to and where the package came from. The files an RPM package contains are in a compressed archive, with a custom binary header containing useful information about the package and its contents, allowing you to query individual packages quickly and easily.

System Verification
                                Another powerful RPM feature is the ability to verify packages. It allows you to verify that the files installed on the system are the same as the ones supplied by a given package. If an inconsistency is detected, RPM notifies you, and you can reinstall the package if necessary. Any configuration files that you modified are preserved during reinstallation.

Pristine Sources
                            A crucial design goal was to allow the use of pristine software sources, as distributed by the original authors of the software. With RPM, you have the pristine sources along with any patches that were used, plus complete build instructions. This is an important advantage for several reasons. For example, if a new version of a program is released, you do not necessarily have to start from scratch to get it to compile. You can look at the patch to see what you might need to do. All the compiled-in defaults, and all of the changes that were made to get the software to build properly, are easily visible using this technique.

Operations in RPM 


  1. Installation
        It  is used to install a given package to the system
  2. Upgrading:       Upgrade is used to upgrade the existing package to the newer version, or, if the package is not installed it will install the package. Upgrade is therefore able to either upgrade or install.
    1. Installation of Package: rpm -Uvh tree-1.6.0-10.el7.x86_64.rpm
    2. If the package is already installed it will give error,
      “Package is already installed
    3. If you want to initiate the re-install, to get the default conf files or to get back some deleted files,
      rpm -Uvh --replacepkgs tree-1.6.0-10.el7.x86_64.rpm
    4. To downgrade the package, rpm -Uvh --oldpackage older_package.rpm
    5. If you attempt to install a package that contains a file that has already been installed by another package, a conflict message is displayed. To ignore it, 
      rpm -Uvh --replacefiles package.rpm
    6. Force rpm to install a package that has an unresolved dependency. rpm -Uvh —-nodeps package.rpm               
  3. Uninstallation: 
    rpm -e package
     Note:- You can encounter dependency errors when uninstalling a package if another installed package depends on the one you are trying to remove
  4. Verification :
    1. To verify your entire system and see what files are missing, issue the following command as rootrpm -Va [Note:If some files are missing or appear corrupted, consider reinstalling relevant packages.]
    2. Packages can be verified with, rpm -V <package_name> .  It compares the files to be installed with the one that is already installed and shows the difference.
  5. Querying: rpm -qa : lists all the rpm packages.
    1. rpm -qi <package_name>  : Information about the installed package
    2. rpm -qip <package_name>  : Information about the non-installed package
    3. To determine which package owns given file:
      rpm -qf <file>
    4. To query the documentation of the package to while the file belongs, rpm -qdf <file>
    5. To list the files in the package: rpm -qlp package.rpm

  Other Misc Operations:-
       
  1. To determine which package contains the required file, use the --whatprovides option: rpm -q --whatprovides required_file
  2. To determine which package requires this package: use ——whatrequires: rpm -q --whatrequires <package_name>



Notes:


  • For most package-management tasks, the Yum package manager offers equal and often greater capabilities and utility than RPMYum also performs and tracks complicated system-dependency resolutions. Yum maintains the system integrity and forces a system integrity check if packages are installed or removed using another application, such as RPM, instead of Yum. For these reasons, it is highly recommended that you use Yum instead of RPM whenever possible to perform package-management tasks.
  • It is always recommended to use rpm -Uvh to install as new packages, EXCEPT for kernel packages.

Sunday, 6 November 2016

Actionable YUM Commands

Yum is the repository management tool which fetches the appropriate package for your particular version of linux.

Actionable Yum commands:- 
  1. Yum list                      : list all the installed and available packages
  2. yum list installed        :  list all the installed packages
  3. yum list available       : list all the available packages in enabled repos, ready to be installed.
  4. yum repolist/repoinfo : list all the enabled repos
  5. yum info <package_name>  : list information about mentioned package
  6. yumd info <package_name>  : Querying yum database for more detailed information.
  7. yum install mysql*         : install all the mysql related packages
  8. yum provides <package_name> : will list the path where it is installed and other imp details.
  9. yum localinstall <package_name> : to install the package that was already downloaded
  10. yum remove <package_name>  : to remove the package
         
  11. Package groupA package group is a collection of packages that serve a common purpose, for instance System Tools.
    1. yum group list <filter>               : View all the available and Installed group.
    2. yum group info <filter>  : to list all the mandatory and optional package from the group.
    3. yum group install <group_name> : installs the group
    4. yum group remove <group_name> : removes group
  12. Yum Transaction History:  The yum history command enables users to review information about a timeline of yum transactions, the dates and times they occurred, the number of packages affected, whether these transactions succeeded or were aborted, and if the RPM database was changed between transactions. Additionally, this command can be used to undo or redo certain transactions. All history data is stored in the history DB in the /var/lib/yum/history/ directory.
    1. yum history list  : list  last 20 transactions
    2. yum history list all  : list all transactions
    3. yum history list <filter>
    4. yum history info <id>    : Examine any transaction in more detail
    5. Repeating or Undoing transaction using history: Apart from reviewing the transaction history, the yum history command provides means to revert or repeat a selected transaction. 
      1. yum history undo <id>     : it will revert the transaction mentioned by ID
      2. yum history redo <id>     : it will repeat the transaction mentioned by ID
  13. Yum Configuration : 
    1. The configuration information for yum and related utilities is located at /etc/yum.conf
    2. Yum cache and database file are kept by default at : /var/cache/yum/$basearch/$releasever/
    3. Default yum log file : /var/log/yum.log     
  14. Repo Configuration :   All .repo files contain repository information (similar to the [repository] sections of /etc/yum.conf). Yum collects all repository information from .repo files and the [repository] section of the /etc/yum.conf file to create a master list of repositories to use for transactions. If reposdir is not set, yum uses the default directory /etc/yum.repos.d/.  Basic repo configuration in repo.d are as follows, 
    1. name=repository_name
      Here, repository_name is a human-readable string describing the repository.
    2. baseurl=repository_url  : 
      Replace repository_url with a URL to the directory where the repodata directory of a repository is located:
    3. enabled=value : This is a simple way to tell yum to use or ignore a particular repository
      Note: Turning repositories on and off can also be performed by passing either the --enablerepo=repo_name or --disablerepo=repo_name option to yum
  15. Yum variables: You can use and reference the following built-in variables in yum commands and in all yum configuration files (that is, /etc/yum.conf and all .repo files in the /etc/yum.repos.d/ directory):
    1. Default/Build-in Variables: 
      1. $releasever
      2. $arch
      3. $basearch
    2. Custom Variables: To define a custom variable or to override the value of an existing one, create a file with the same name as the variable (without the $ sign) in the /etc/yum/vars/ directory, and add the desired value on its first line.
  16. Adding a yum repository: To define a new repository, you can either add a [repository] section to the /etc/yum.conf file, or to a .repo file in the /etc/yum.repos.d/ directory. All files with the .repo file extension in this directory are read by yum, and it is recommended to define your repositories here instead of in /etc/yum.conf.
  17. To view/modidy global configuration: $yum-config-manager
    1. yum-config-manager —add-repo repository_url : Yum repositories commonly provide their own .repo file. To add such a repository to your system and enable it.
    2. yum-config-manager —enable repository : To enable any repository.
    3. yum-config-manager --enable \* : Enable all the repos
  18. Creating New/Local yum repos:
    1. Install createrepo package yum install createrepo
    2. Copy all packages that you want to have in your repository into one directory, such as /mnt/local_repo/
    3. Change to this directory and run the following command:
      createrepo -database /mnt/local_repo This creates the necessary metadata for your yum repository, as well as the sqlite database for speeding up yum operations.


NOTES-
  • use backslash sign before any regex expression [  /* OR /?]
  • Most, if not all, commands will need root privileges to execute.
  • This blog contains the list of the yum commands that you will gonna use on day to day basis as a Linux developer, however, you will need more depth if you are Linux Admin.