{"id":10831,"date":"2024-12-14T06:46:42","date_gmt":"2024-12-14T06:46:42","guid":{"rendered":"https:\/\/blog.trustedhosting.in\/?p=10831"},"modified":"2024-12-14T06:46:42","modified_gmt":"2024-12-14T06:46:42","slug":"package-management-functions-in-linux","status":"publish","type":"post","link":"https:\/\/www.webystrata.com\/blog\/package-management-functions-in-linux\/","title":{"rendered":"Package Management Functions in Linux"},"content":{"rendered":"<figure id=\"attachment_10832\" aria-describedby=\"caption-attachment-10832\" style=\"width: 2560px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.trustedhosting.in\/cpanel-hosting.html\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10832 size-full\" title=\" Package Management Functions in Linux\" src=\"https:\/\/blog.trustedhosting.in\/wp-content\/uploads\/2024\/12\/5595553_55292-scaled.jpg\" alt=\" Package Management Functions in Linux\" width=\"2560\" height=\"2360\" srcset=\"https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5595553_55292-scaled.jpg 2560w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5595553_55292-300x277.jpg 300w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5595553_55292-1024x944.jpg 1024w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5595553_55292-768x708.jpg 768w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5595553_55292-1536x1416.jpg 1536w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5595553_55292-2048x1888.jpg 2048w\" sizes=\"auto, (max-width: 2560px) 100vw, 2560px\" \/><\/a><figcaption id=\"caption-attachment-10832\" class=\"wp-caption-text\">\u00a0<\/figcaption><\/figure>\n<h1>\u00a0Package Management Functions in Linux<\/h1>\n<p>As most UKFast <a href=\"https:\/\/www.trustedhosting.in\/cpanel-hosting.html\" target=\"_blank\" rel=\"noopener\">servers<\/a> are either CentOS\/Red Hat or Ubuntu\/Debian, this article will only cover two of the most popular Linux package managers,\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">yum<\/span><\/code>\u00a0and\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">apt<\/span><\/code>.<\/p>\n<section id=\"yum\">\n<h2>yum<\/h2>\n<section id=\"installing-packages\">\n<h3>Installing Packages<\/h3>\n<p>To install a package in yum, the following syntax can be used:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum install $PACKAGE_NAME<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>This will search the currently installed repositories for a package with that name and install it if it\u2019s found.<\/p>\n<p>If the package you\u2019re looking for isn\u2019t found, then you may have to install an additional repository that does provide it.<\/p>\n<p>A common additional repository is\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">epel<\/span><\/code>\u00a0(Extra Packages for Enterprise Linux).<\/p>\n<p>On CentOS, this can itself be installed using yum:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum install epel-release<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>If you\u2019re using official Red Hat Enterprise Linux, you will need to download the RPM from the EPEL site and install it manually, as well as enabling packages in the \u2018optional\u2019 RHEL repo. More instructions can be found\u00a0here<\/p>\n<p>With this installed, we can then install additional utilities on our server that were previously unavailable:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum install htop<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<\/section>\n<section id=\"updating-packages\">\n<h3>Updating Packages<\/h3>\n<div class=\"admonition note\">\n<p>In all these examples, the update command will be used rather than upgrade. Both commands look to perform the same function, but upgrade will remove packages that it classifies as obsolete as part of the upgrade process. If you\u2019re confident in what you\u2019re removing or drive space is at a premium then this option can be used instead.<\/p>\n<\/div>\n<p>The update syntax for yum is similar to the install syntax:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum update $PACKAGE_NAME<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>If it\u2019s just one package that needs to be updated then the above syntax is fine, for example:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum update httpd<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>If you\u2019re looking to update all the packages on your<a href=\"https:\/\/www.trustedhosting.in\/cpanel-hosting.html\" target=\"_blank\" rel=\"noopener\"> server<\/a>, simply run the command without a package name:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum update<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<div class=\"admonition warning\">\n<p>Take care when updating all the packages on a server, this isn\u2019t something that should be done blindly. Review the packages that are going to update before accepting it. Failure to review package updates could result in you running a higher version of something critical (such as PHP) than your code supports.<\/p>\n<\/div>\n<\/section>\n<section id=\"extra-functions\">\n<h3>Extra functions<\/h3>\n<p>You can always run a number of checks with yum before either installing or updating an application.<\/p>\n<p>If you wish to check whether a package is available on your system, you can always run a search in yum. This will print out all the packages that match your search:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum search $QUERY<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>An example of this, including a snippet of the output, is as follows:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum search php<\/span>\r\n\r\n<span class=\"go\">   ...<\/span>\r\n<span class=\"go\">   =============================== N\/S matched: php ===============================<\/span>\r\n<span class=\"go\">   php.x86_64 : PHP scripting language for creating dynamic web sites<\/span>\r\n<span class=\"go\">   php-Assetic.noarch : Asset Management for PHP<\/span>\r\n<span class=\"go\">   php-EasyRdf.noarch : A PHP library designed to make it easy to consume and<\/span>\r\n<span class=\"go\">                      : produce RDF<\/span>\r\n<span class=\"go\">   ...<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>If the package exists on your system, you can pull additional information on it, including what version of the package is available to you.<\/p>\n<div class=\"admonition note\">\n<p>This will also show you information on an updated version of the package you\u2019ve got. It also highlights the package\u2019s name in a different collour based on its status.<\/p>\n<p>Red: Obsolete yellow: Installed from another source bold white: Currently installed white: Available, but not installed blue: Update<\/p>\n<\/div>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum info $PACKAGE_NAME<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Here is an example, including a snippet of the output, without colour highlights:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   yum info php70w<\/span>\r\n\r\n<span class=\"go\">   ...<\/span>\r\n<span class=\"go\">   Installed Packages<\/span>\r\n<span class=\"go\">   Name        : **php70w**<\/span>\r\n<span class=\"go\">   Arch        : x86_64<\/span>\r\n<span class=\"go\">   Version     : 7.0.11<\/span>\r\n<span class=\"go\">   Release     : 1.w7<\/span>\r\n<span class=\"go\">   Size        : 9.0 M<\/span>\r\n<span class=\"go\">   Repo        : installed<\/span>\r\n<span class=\"go\">   From repo   : webtatic<\/span>\r\n<span class=\"go\">   ...<\/span>\r\n<span class=\"go\">   Available Packages<\/span>\r\n<span class=\"go\">   Name        : **php70w**<\/span>\r\n<span class=\"go\">   Arch        : x86_64<\/span>\r\n<span class=\"go\">   Version     : 7.0.12<\/span>\r\n<span class=\"go\">   Release     : 1.w7<\/span>\r\n<span class=\"go\">   Size        : 2.8 M<\/span>\r\n<span class=\"go\">   Repo        : webtatic\/x86_64<\/span>\r\n<span class=\"go\">   ...<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Yum also has great history features that allow you to examine your previous installations and roll them back if necessary.<\/p>\n<p>To view the history of your yum transactions, run\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">yum<\/span>\u00a0<span class=\"pre\">history<\/span>\u00a0<span class=\"pre\">list<\/span><\/code>, which will output something like:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[root@7dd0ac475f64 \/]# <\/span>yum <span class=\"nb\">history<\/span>\r\n<span class=\"go\">Loaded plugins: fastestmirror, ovl<\/span>\r\n<span class=\"go\">ID     | Command line             | Date and time    | Action(s)      | Altered<\/span>\r\n<span class=\"go\">-------------------------------------------------------------------------------<\/span>\r\n<span class=\"go\">     4 | groupinstall development | 2017-10-24 09:20 | I, U           |  109 EE<\/span>\r\n<span class=\"go\">     3 | install vim-enhanced     | 2017-10-24 09:19 | Install        |   33 EE<\/span>\r\n<span class=\"go\">     2 | -y remove bind-libs bind | 2017-08-01 17:24 | Erase          |   35 E&lt;<\/span>\r\n<span class=\"go\">     1 |                          | 2017-08-01 17:23 | Install        |  178 &gt;<\/span>\r\n<span class=\"go\">history list<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>In the above example, if you had finished with the packaged you installed in transaction 4, you could then remove those by running\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">yum<\/span>\u00a0<span class=\"pre\">history<\/span>\u00a0<span class=\"pre\">undo<\/span>\u00a0<span class=\"pre\">4<\/span><\/code>. If you wished to rollback your server to transaction 2, you could run\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">yum<\/span>\u00a0<span class=\"pre\">history<\/span>\u00a0<span class=\"pre\">rollback<\/span>\u00a0<span class=\"pre\">2<\/span><\/code>\u00a0which would remove packages installed in transactions 3 and 4.<\/p>\n<p>You can get more information about this powerful feature by running\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">yum<\/span>\u00a0<span class=\"pre\">help<\/span>\u00a0<span class=\"pre\">history<\/span><\/code>\u00a0or viewing the yum man page (<code class=\"docutils literal notranslate\"><span class=\"pre\">man<\/span>\u00a0<span class=\"pre\">yum<\/span><\/code>).<\/p>\n<\/section>\n<\/section>\n<section id=\"apt\">\n<h2>apt<\/h2>\n<section id=\"id1\">\n<h3>Installing Packages<\/h3>\n<p>To install a package with\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">apt<\/span><\/code>\u00a0you should first update the apt cache, then install your desired package:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   apt-get update<\/span>\r\n<span class=\"go\">   apt-get install $PACKAGE_NAME<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Updating the cache first is important as this will ensure you get the latest available packages and security updates.<\/p>\n<\/section>\n<section id=\"id2\">\n<h3>Updating Packages<\/h3>\n<p>As with installing, you should ensure your apt cache is up to date so you get the latest software updates and security patches.<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   apt-get update<\/span>\r\n<span class=\"go\">   apt-get upgrade<\/span>\r\n<span class=\"go\">   or<\/span>\r\n<span class=\"go\">   aptitude update<\/span>\r\n<span class=\"go\">   aptitude upgrade<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>This will pull in all available updates for your system. Sometimes you may find that packages have been held back (usually Linux kernel updates). These can be pulled in by running a\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">dist-upgrade<\/span><\/code>.<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   apt-get dist-upgrade<\/span>\r\n<span class=\"go\">   or<\/span>\r\n<span class=\"go\">   aptitude full-upgrade<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>If you wish to view which version you\u2019re upgrading to and from you can always enable verbosity with the \u2018-V\u2019 option<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   apt-get -V upgrade|dist-upgrade<\/span>\r\n<span class=\"go\">   or<\/span>\r\n<span class=\"go\">   aptitude -V upgrade|full-upgrade<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<div class=\"admonition warning\">\n<p>Take care when updating all packages on a server. This is not something which should be done blindly. Review the packages that are going be updated before accepting the upgrade. If you fail to review the packages you may end up installing a new major version of a package which is not going to be compatible with your code, e.g. MySQL or PHP.<\/p>\n<\/div>\n<\/section>\n<section id=\"id3\">\n<h3>Extra Functions<\/h3>\n<p>With apt, there are 2 ways to perform a search for packages, but viewing package info applies the same to both methods.<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   apt-cache search $QUERY<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>This will display all packages that have matches based on name, summary, and full description.<\/p>\n<p>If you only want package and summary searches, you can run the following:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   aptitude search $QUERY<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Here are some examples and their outputs:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   apt-cache search php<\/span>\r\n\r\n<span class=\"go\">   ...<\/span>\r\n<span class=\"go\">   adminer - Web-based database administration tool<\/span>\r\n<span class=\"go\">   air-quality-sensor - user space driver for AppliedSensor's Indoor Air Monitor<\/span>\r\n<span class=\"go\">   ampache - web-based audio file management system<\/span>\r\n<span class=\"go\">   ampache-common - web-based audio file management system common files<\/span>\r\n<span class=\"go\">   ampache-themes - Themes for Ampache<\/span>\r\n<span class=\"go\">   aolserver4-doc - AOL web server version 4 - documentation<\/span>\r\n<span class=\"go\">   ...<\/span>\r\n\r\n<span class=\"go\">   aptitude search php<\/span>\r\n\r\n<span class=\"go\">   ...<\/span>\r\n<span class=\"go\">   p   cakephp               - MVC rapid application development framework for PHP<\/span>\r\n<span class=\"go\">   p   cakephp-instaweb      - Development webserver for CakePHP applications<\/span>\r\n<span class=\"go\">   p   cakephp-scripts       - MVC rapid application development framework for PHP (scripts)<\/span>\r\n<span class=\"go\">   p   dh-make-php           - Creates Debian source packages for PHP PEAR and PECL extensions<\/span>\r\n<span class=\"go\">   p   dh-php5               - debhelper add-on to handle PHP PECL extensions<\/span>\r\n<span class=\"go\">   ...<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>With aptitude searches, they show information about the installation status of a package.<\/p>\n<ul class=\"simple\">\n<li>\u2018p\u2019 shows that the package is available, but not installed.<\/li>\n<li>\u2018v\u2019 shows that this is a virtual package, i.e. it\u2019s provided by another package.<\/li>\n<li>\u2018i\u2019 shows that the package is installed.<\/li>\n<li>\u2018c\u2019 shows that the package was removed, but the configuration still remains<\/li>\n<\/ul>\n<p>If an \u2018A\u2019 is visible, it shows that this was automatically installed as a dependency to another package.<\/p>\n<p>After searching for a package you can get more information with the following command:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   apt-cache show $PACKAGE_NAME<\/span>\r\n<span class=\"go\">   or<\/span>\r\n<span class=\"go\">   aptitude show $PACKAGE_NAME<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Here is an example, and a snippet of the output:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">   apt-cache show linux-image-amd64<\/span>\r\n<span class=\"go\">   or<\/span>\r\n<span class=\"go\">   aptitude show linux-image-amd64<\/span>\r\n\r\n<span class=\"go\">   ...<\/span>\r\n<span class=\"go\">   Package: linux-image-amd64<\/span>\r\n<span class=\"go\">   State: installed<\/span>\r\n<span class=\"go\">   Automatically installed: no<\/span>\r\n<span class=\"go\">   Version: 3.16+63<\/span>\r\n<span class=\"go\">   Priority: optional<\/span>\r\n<span class=\"go\">   Section: kernel<\/span>\r\n<span class=\"go\">   ...<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>This will tell you additional information, such as what packages it depends on, and which packages it will conflict with, along with a description of what the package does.<\/p>\n<\/section>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0Package Management Functions in Linux As most UKFast servers are either CentOS\/Red Hat or Ubuntu\/Debian, this article will only cover&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-10831","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/comments?post=10831"}],"version-history":[{"count":2,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10831\/revisions"}],"predecessor-version":[{"id":10834,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10831\/revisions\/10834"}],"wp:attachment":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/media?parent=10831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/categories?post=10831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/tags?post=10831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}