{"id":97823,"date":"2024-01-15T08:08:45","date_gmt":"2024-01-15T08:08:45","guid":{"rendered":"https:\/\/linuxiac.com\/?p=97823"},"modified":"2024-01-15T08:08:52","modified_gmt":"2024-01-15T08:08:52","slug":"alpine-apk-command-guide","status":"publish","type":"post","link":"https:\/\/linuxiac.com\/alpine-apk-command-guide\/","title":{"rendered":"Alpine User&#8217;s Guide to APK: How to Manage Packages"},"content":{"rendered":"\n<p>If you&#8217;re navigating <a href=\"https:\/\/linuxiac.com\/how-to-install-alpine-linux\/\">the world of Alpine Linux<\/a> and looking to master its package management, you&#8217;ve landed in the right place. We&#8217;ve covered you, from installing new packages and updating existing ones to removing or searching for them.<\/p>\n\n\n\n<p>In this comprehensive guide, we&#8217;re diving deep into the APK command, Alpine&#8217;s powerful package management tool. So, are you ready to become an Alpine APK command wizard? I&#8217;m sure you are! But before we start, let&#8217;s share some theories.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-s-alpine-s-apk-command\">What&#8217;s Alpine&#8217;s APK Command?<\/h2>\n\n\n\n<p><strong>APK<\/strong>&nbsp;stands for &#8220;<strong>Alpine Package Keeper<\/strong>.&#8221; It&#8217;s the tool for installing, updating, removing, and managing software packages in Alpine Linux. Like&nbsp;<a target=\"_blank\" href=\"https:\/\/linuxiac.com\/apt-command-in-linux\/\" rel=\"noreferrer noopener\">APT<\/a>&nbsp;in Debian-based distributions or&nbsp;<a target=\"_blank\" href=\"https:\/\/linuxiac.com\/dnf-command-linux\/\" rel=\"noreferrer noopener\">DNF<\/a>&nbsp;in Red Hat-based systems, APK is the primary way to manage software on Alpine Linux systems.<\/p>\n\n\n\n<p>With the APK command, you can:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Install Packages:<\/strong> Easily add new packages to your system.<\/li>\n\n\n\n<li><strong>Update Packages:<\/strong> Keep your installed packages up-to-date with the latest versions.<\/li>\n\n\n\n<li><strong>Remove Packages:<\/strong> Cleanly remove packages you no longer need.<\/li>\n\n\n\n<li><strong>Search for Packages:<\/strong> Find available packages in the Alpine repositories.<\/li>\n\n\n\n<li><strong>Upgrade the System:<\/strong> Update all installed packages to their latest versions.<\/li>\n\n\n\n<li><strong>Querying Packages:<\/strong> Inspect packages or files to see various details.<\/li>\n\n\n\n<li><strong>Add Repositories:<\/strong> Customize your package sources for additional software.<\/li>\n<\/ul>\n\n\n\n<p>It&#8217;s designed to be simple and efficient, aligning with Alpine&#8217;s philosophy of keeping things small and resource-friendly. This makes it an ideal tool for servers, containers, and minimal environments.<\/p>\n\n\n\n<p>Lastly, before we delve into the practical examples, it&#8217;s important to note that all the examples provided are executed under the root user.<\/p>\n\n\n\n<p>Should you run these with a standard user account, remember to prefix each command with &#8216;<code>sudo<\/code>&#8216; and ensure that your account has been granted <code>sudo<\/code> privileges in advance. So, let&#8217;s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-update-package-lists\">Update Package Lists<\/h2>\n\n\n\n<p>Before installing new packages, it&#8217;s a good practice to update the list of available packages, ensuring that the index of our local copy of the package database is up-to-date.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk update<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-update.jpg\"><img decoding=\"async\" width=\"942\" height=\"270\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-update.jpg\" alt=\"Update the index of available packages.\" class=\"wp-image-97889\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-update.jpg 942w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-update-380x109.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-update-768x220.jpg 768w\" sizes=\"(max-width: 942px) 100vw, 942px\" \/><\/a><figcaption class=\"wp-element-caption\">Update the index of available packages.<\/figcaption><\/figure>\n\n\n\n<p>The command forces updating the indexes from all configured package repositories.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-system-upgrade\">System Upgrade<\/h2>\n\n\n\n<p>The &#8220;<code>apk upgrade<\/code>&#8221; command in Alpine is used to upgrade packages to their latest versions. It checks for updates (if any) and bump all the currently installed packages on your system to the most recent versions available in the repositories.<\/p>\n\n\n\n<p>This ensures your system remains patched with the latest versions, bug fixes, and essential security enhancements.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk upgrade<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If no updates are available, the command will provide output similar to the one below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-upgrade.jpg\"><img decoding=\"async\" width=\"942\" height=\"177\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-upgrade.jpg\" alt=\"Upgrade all the currently installed packages.\" class=\"wp-image-97898\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-upgrade.jpg 942w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-upgrade-380x71.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-upgrade-768x144.jpg 768w\" sizes=\"(max-width: 942px) 100vw, 942px\" \/><\/a><figcaption class=\"wp-element-caption\">Upgrade all the currently installed packages.<\/figcaption><\/figure>\n\n\n\n<p>In short, you can use this command to keep your Alpine Linux system up to date.<\/p>\n\n\n\n<p>However, if you want to upgrade only a specific package on your Alpine system, you can use the <code>apk add<\/code> command (details below) with the &#8220;<em>-u<\/em>&#8221; option added. For example, to upgrade only the &#8220;<em>nano<\/em>&#8221; package, run:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk add -u nano<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-search-for-the-package\">Search for the Package<\/h2>\n\n\n\n<p>The\u00a0<code>apk search<\/code>\u00a0command allows you to search the repository&#8217;s index for a given package or descriptions in the list of available packages. For example, to search for\u00a0&#8220;<em>nano<\/em>,&#8221; enter:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk search nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search.jpg\"><img decoding=\"async\" width=\"942\" height=\"375\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search.jpg\" alt=\"Search for packages.\" class=\"wp-image-97910\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search.jpg 942w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search-380x151.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search-768x306.jpg 768w\" sizes=\"(max-width: 942px) 100vw, 942px\" \/><\/a><figcaption class=\"wp-element-caption\">Search for packages.<\/figcaption><\/figure>\n\n\n\n<p>Include the &#8220;<em>-v<\/em>\u00a0(<em>\u2013verbose<\/em>)&#8221; option to get a more comprehensive overview of the matches found. This will give you a concise description of each packet in the results.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk search -v nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search2.jpg\"><img decoding=\"async\" width=\"1024\" height=\"336\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search2-1024x336.jpg\" alt=\"Search for packages with a description added to the results.\" class=\"wp-image-97913\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search2-1024x336.jpg 1024w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search2-380x125.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search2-768x252.jpg 768w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search2.jpg 1129w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Search for packages with a description added to the results.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-searching-through-installed-packages\">Searching Through Installed Packages<\/h2>\n\n\n\n<p>The <code>apk info<\/code> command is a versatile tool for gathering package information. Without additional arguments, it lists all packages currently installed on your system, which helps get a quick overview of all the software and libraries on your Alpine installation.<\/p>\n\n\n\n<p>But what if we want to check if a particular package is installed, for example, &#8220;<em>nano<\/em>&#8220;? The simplest approach is to use <code>apk info<\/code> with an added &#8220;<em>-e<\/em>&#8221; option to perform this check.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk info -e nano<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>We recommend appending the &#8220;<em>v<\/em>&#8221; option to &#8220;<em>-e<\/em>,&#8221; as it will display the package&#8217;s name and installed version.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info7.jpg\"><img decoding=\"async\" width=\"943\" height=\"160\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info7.jpg\" alt=\"Searching through installed packages.\" class=\"wp-image-98045\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info7.jpg 943w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info7-380x64.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info7-768x130.jpg 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/a><figcaption class=\"wp-element-caption\">Searching through installed packages.<\/figcaption><\/figure>\n\n\n\n<p>You can achieve the same result if you pass the <code>apk info<\/code> command&#8217;s output (which without additional parameters lists all installed packages on your system) with an added &#8220;<em>-v<\/em>&#8221; option through grep by searching for specific package&#8217;s name.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk info -v | grep nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search4.jpg\"><img decoding=\"async\" width=\"937\" height=\"160\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search4.jpg\" alt=\"Searching through installed packages.\" class=\"wp-image-97925\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search4.jpg 937w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search4-380x65.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-search4-768x131.jpg 768w\" sizes=\"(max-width: 937px) 100vw, 937px\" \/><\/a><figcaption class=\"wp-element-caption\">Searching through installed packages.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-installing-packages\">Installing Packages<\/h2>\n\n\n\n<p>Installing packages in Alpine is a straightforward process and one of the most common uses of the\u00a0<code>apk<\/code>\u00a0command. You can install any package with <code>apk add<\/code> followed by the package&#8217;s name. For example, let\u2019s\u00a0install the Nano terminal text editor:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk add nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install.jpg\"><img decoding=\"async\" width=\"942\" height=\"270\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install.jpg\" alt=\"Installing new package with the APK command.\" class=\"wp-image-97865\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install.jpg 942w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install-380x109.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install-768x220.jpg 768w\" sizes=\"(max-width: 942px) 100vw, 942px\" \/><\/a><figcaption class=\"wp-element-caption\">Installing new package with the APK command.<\/figcaption><\/figure>\n\n\n\n<p>That&#8217;s it. How much easier can it be? What&#8217;s more, APK even takes care of dependencies automatically. This means when you install a package, APK will also install any necessary dependencies, should there be any.<\/p>\n\n\n\n<p>Looking to install multiple packages simultaneously? It&#8217;s easy! Enumerate the names of the packages you want to install one after the other. For instance, to install &#8220;<em>nano<\/em>&#8221; and &#8220;<em>vim<\/em>&#8221; together in one go:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk add nano vim<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install2.jpg\"><img decoding=\"async\" width=\"942\" height=\"298\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install2.jpg\" alt=\"Install multiple packages simultaneously on Alpine Linux.\" class=\"wp-image-97880\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install2.jpg 942w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install2-380x120.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install2-768x243.jpg 768w\" sizes=\"(max-width: 942px) 100vw, 942px\" \/><\/a><figcaption class=\"wp-element-caption\">Install multiple packages simultaneously on Alpine Linux.<\/figcaption><\/figure>\n\n\n\n<p>As you notice, the APK also automatically installs the &#8220;<em>xxd<\/em>&#8221; package, which depends on the Vim installation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-batch-installing-using-the-world-file\">Batch-Installing Using the &#8216;world&#8217; File<\/h2>\n\n\n\n<p>In Alpine Linux, there is a special file located at &#8220;<em>\/etc\/apk\/world<\/em>,&#8221; which records all the packages the user has explicitly installed. It&#8217;s important to note that this list does not include dependencies that were automatically installed alongside other packages.<\/p>\n\n\n\n<p>When you install a new package, its name is added to the &#8220;<em>world<\/em>&#8221; file. Conversely, when you remove a package, it&#8217;s removed from this list. This approach ensures that the system retains only the packages that are necessary and desired by the user.<\/p>\n\n\n\n<p>So, if you want to install multiple packages simultaneously, open the file with a text editor and append their names to the end of the file. For example, let&#8217;s add &#8220;<em>vim<\/em>,&#8221; &#8220;<em>htop<\/em>,&#8221; and &#8220;<em>curl<\/em>&#8221; to the list.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">nano \/etc\/apk\/world<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install3.jpg\"><img decoding=\"async\" width=\"942\" height=\"696\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install3.jpg\" alt=\"Batch-installing packages on Alpine Linux using the 'world' file.\" class=\"wp-image-97985\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install3.jpg 942w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install3-380x281.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install3-768x567.jpg 768w\" sizes=\"(max-width: 942px) 100vw, 942px\" \/><\/a><figcaption class=\"wp-element-caption\">Batch-installing packages on Alpine Linux using the &#8216;world&#8217; file.<\/figcaption><\/figure>\n\n\n\n<p>Then, run <code>apk add<\/code> without any additional arguments, and the desired packages will be installed along with their dependencies.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install4.jpg\"><img decoding=\"async\" width=\"938\" height=\"532\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install4.jpg\" alt=\"Batch-installing packages on Alpine Linux using the 'world' file.\" class=\"wp-image-97988\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install4.jpg 938w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install4-380x216.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-install4-768x436.jpg 768w\" sizes=\"(max-width: 938px) 100vw, 938px\" \/><\/a><figcaption class=\"wp-element-caption\">Batch-installing packages on Alpine Linux using the &#8216;world&#8217; file.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-installing-a-local-package\">Installing a Local Package<\/h2>\n\n\n\n<p>Installing a local package, usually a file with a &#8220;<em>.apk<\/em>&#8221; extension, in Alpine is relatively straightforward. To do so, use the <code>apk add<\/code> command with the &#8220;<em>&#8211;allow-untrusted<\/em>&#8221; option, followed by the full path to the package.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk add --allow-untrusted \/tmp\/package_name.apk<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The &#8220;<em>&#8211;allow-untrusted<\/em>&#8221; flag is necessary only if your package is not from a trusted source, as defined in your APK repositories. Of course, the package must also be compatible with your Alpine version.<\/p>\n\n\n\n<p>Remember, it&#8217;s crucial to install APK packages only from sources you trust, as installing from untrusted sources can compromise the security of your system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-removing-packages\">Removing Packages<\/h2>\n\n\n\n<p>To remove (uninstall) an installed package in Alpine, use the <code>apk del<\/code> command followed by the package&#8217;s name. For example, to remove a \u201c<em>nano<\/em>,\u201d execute:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk del nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete.jpg\"><img decoding=\"async\" width=\"937\" height=\"216\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete.jpg\" alt=\"Delete packages from the running system.\" class=\"wp-image-97934\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete.jpg 937w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete-380x88.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete-768x177.jpg 768w\" sizes=\"(max-width: 937px) 100vw, 937px\" \/><\/a><figcaption class=\"wp-element-caption\">Delete packages from the running system.<\/figcaption><\/figure>\n\n\n\n<p>You can also remove multiple packages simultaneously by specifying packages&#8217; names separated by spaces:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk del nano vim<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete2.jpg\"><img decoding=\"async\" width=\"937\" height=\"291\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete2.jpg\" alt=\"Removing multiple packages simultaneously on Alpine Linux.\" class=\"wp-image-97937\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete2.jpg 937w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete2-380x118.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-delete2-768x239.jpg 768w\" sizes=\"(max-width: 937px) 100vw, 937px\" \/><\/a><figcaption class=\"wp-element-caption\">Removing multiple packages simultaneously on Alpine Linux.<\/figcaption><\/figure>\n\n\n\n<p>Additionally, if you\u2019re unsure about the full name of the package, APK supports wildcards. For example, the command below would remove all packages starting with &#8220;<em>vim<\/em>.&#8221;<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk del vim*<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>However, using a wildcard always brings risks with it. Thus, we highly advise you to assess the potential outcomes using the &#8220;<em>\u2013simulate<\/em>&#8221; option provided by APK so you can first check what exactly will happen without actual execution.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk del --simulate vim*<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Lastly, when you install a package in Alpine and modify its configuration files, those altered files stay on your system even if you uninstall the package. Include the &#8220;<em>\u2013purge<\/em>&#8221; option to the <code>apk del<\/code> command to ensure these files are also removed when deleting the package.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk del --purge vim<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-getting-package-details\">Getting Package Details<\/h2>\n\n\n\n<p>The <code>apk info<\/code> command is used to display information about packages. It can query various details about the packages available or installed on an Alpine Linux system. Here are some of its common uses.<\/p>\n\n\n\n<p>You can use <code>apk info<\/code> followed by the package&#8217;s name to get detailed information about a specific package. This will show the package version, description, and size.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk info nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info.jpg\"><img decoding=\"async\" width=\"937\" height=\"369\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info.jpg\" alt=\"Prints information about installed or available packages.\" class=\"wp-image-97973\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info.jpg 937w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info-380x150.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info-768x302.jpg 768w\" sizes=\"(max-width: 937px) 100vw, 937px\" \/><\/a><figcaption class=\"wp-element-caption\">Prints information about installed or available packages.<\/figcaption><\/figure>\n\n\n\n<p>To get more detailed information, including dependencies and which files belong to a package, add the &#8220;<em>-a<\/em>&#8221; option.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk info -a nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info2.jpg\"><img decoding=\"async\" width=\"937\" height=\"724\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info2.jpg\" alt=\"View detailed information about installed or available packages.\" class=\"wp-image-97976\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info2.jpg 937w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info2-380x294.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info2-768x593.jpg 768w\" sizes=\"(max-width: 937px) 100vw, 937px\" \/><\/a><figcaption class=\"wp-element-caption\">View detailed information about installed or available packages.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-view-package-s-file-list\">View Package&#8217;s File List<\/h2>\n\n\n\n<p>In Alpine, you can use <code>apk info<\/code> with the added &#8220;<em>-L<\/em>&#8221; option to list the files a package provides. When you run this command, followed by a specific package name, it displays all the files in that package.<\/p>\n\n\n\n<p>This is particularly useful for understanding what files a package installs on your system and where these files are located. For example, let&#8217;s check this for the &#8220;<em>nano<\/em>&#8221; package:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk info -L nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info3.jpg\"><img decoding=\"async\" width=\"943\" height=\"266\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info3.jpg\" alt=\"List the files provided by a package.\" class=\"wp-image-98003\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info3.jpg 943w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info3-380x107.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info3-768x217.jpg 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/a><figcaption class=\"wp-element-caption\">List the files provided by a package.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-view-package-s-dependencies\">View Package\u2019s Dependencies<\/h2>\n\n\n\n<p>Another great feature of <code>apk info<\/code> is to display the reverse dependencies of a package. When you run this command with a &#8220;<em>-R<\/em>&#8221; option, followed by a package name, it shows you a list of all dependencies that require the specified package to function.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk info -R nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info4.jpg\"><img decoding=\"async\" width=\"943\" height=\"238\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info4.jpg\" alt=\"View the package\u2019s dependencies.\" class=\"wp-image-98015\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info4.jpg 943w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info4-380x96.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info4-768x194.jpg 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/a><figcaption class=\"wp-element-caption\">View the package\u2019s dependencies.<\/figcaption><\/figure>\n\n\n\n<p>This is useful for understanding if you uninstall a specific package and what other packages might also be affected by this action.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-trace-file-s-package-origin\">Trace File&#8217;s Package Origin<\/h2>\n\n\n\n<p>Have you ever stumbled upon a binary or plain text configuration file and wondered about its origins or which package added it to your Alpine system?<\/p>\n\n\n\n<p>The solution is simple: use the <code>apk info<\/code> command, but this time include the &#8220;<em>-W<\/em> (<em>&#8211;who-owns<\/em>)&#8221; option, followed by the full path to the file.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk info -W \/etc\/rc.conf<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info5.jpg\"><img decoding=\"async\" width=\"943\" height=\"163\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info5.jpg\" alt=\"Trace the file's package origin in Alpine Linux.\" class=\"wp-image-98024\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info5.jpg 943w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info5-380x66.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info5-768x133.jpg 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/a><figcaption class=\"wp-element-caption\">Trace the file&#8217;s package origin in Alpine Linux.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-check-package-s-installed-size\">Check Package&#8217;s Installed Size<\/h2>\n\n\n\n<p>When you run <code>apk info<\/code> with the &#8220;<em>-s<\/em>&#8221; option followed by the package&#8217;s name, it will provide details about the specified package, including its installable size, which helps understand how much space the package will take up when installed.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk info -s nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info6.jpg\"><img decoding=\"async\" width=\"943\" height=\"212\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info6.jpg\" alt=\"Check package's installed size.\" class=\"wp-image-98036\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info6.jpg 943w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info6-380x85.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-info6-768x173.jpg 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/a><figcaption class=\"wp-element-caption\">Check package&#8217;s installed size.<\/figcaption><\/figure>\n\n\n\n<p>This is particularly useful in environments where storage space is a concern, such as in minimalistic setups or Docker containers often used in Alpine Linux environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cleaning-the-cache\">Cleaning the Cache<\/h2>\n\n\n\n<p>The <code>apk cache<\/code> command manages the local cache of package archives that the APK has downloaded. But if you&#8217;ve installed numerous packages, they can <a href=\"https:\/\/linuxiac.com\/check-disk-space-linux\/\">consume significant disk space<\/a>.<\/p>\n\n\n\n<p>In this case, to clean up the cache by removing downloaded packages that are no longer needed, use the command provided below, which helps in freeing up disk space.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk cache clean<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-broken-packages-repair\">Broken Packages&#8217; Repair<\/h2>\n\n\n\n<p>As unpleasant as it may be, sometimes the installation of specific packages may proceed differently than planned, resulting in a broken package. Here&#8217;s where the <code>apk fix<\/code> command comes to the rescue.<\/p>\n\n\n\n<p>It checks for broken dependencies and attempts to fix them by updating or reinstalling packages. If a package is partially installed or removed, <code>apk fix<\/code> can help resolve these issues, ensuring that all packages are consistent and functional.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk fix<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>It&#8217;s beneficial when you have a corrupted package database, or after a failed package installation or upgrade. By running <code>apk fix<\/code>, you can ensure that all the dependencies are correctly met and the packages are installed on your Alpine system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-view-package-s-policy\">View Package&#8217;s Policy<\/h2>\n\n\n\n<p>The <code>apk policy<\/code> command is used to show information about the policies of a package. Specifically, it details which repository a package is coming from and its available versions.<\/p>\n\n\n\n<p>This is useful in scenarios where multiple repositories are configured, and you want to understand from which repository a specific package is being pulled or could be pulled and what versions are available in these repositories.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk policy nano<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-policy.jpg\"><img decoding=\"async\" width=\"943\" height=\"209\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-policy.jpg\" alt=\"View information about the policies of a package.\" class=\"wp-image-98072\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-policy.jpg 943w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-policy-380x84.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-policy-768x170.jpg 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/a><figcaption class=\"wp-element-caption\">View information about the policies of a package.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-lists-stats-for-the-installed-packages\">Lists Stats for the Installed Packages<\/h2>\n\n\n\n<p>The <code>apk stats<\/code> command displays statistics about the installed packages in the Alpine package management system. It provides information such as the number of installed packages, disk space used by the installed packages, etc.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">apk stats<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-stats.jpg\"><img decoding=\"async\" width=\"943\" height=\"429\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-stats.jpg\" alt=\"Lists summarized statistics for the installed packages.\" class=\"wp-image-98081\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-stats.jpg 943w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-stats-380x173.jpg 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2024\/01\/alpine-apk-stats-768x349.jpg 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/a><figcaption class=\"wp-element-caption\">Lists summarized statistics for the installed packages.<\/figcaption><\/figure>\n\n\n\n<p>It helps get a quick overview of the package management system&#8217;s status on your Alpine Linux system, especially regarding storage and the number of packages managed by APK.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-apk-command-cheat-sheet\">APK Command Cheat Sheet<\/h2>\n\n\n\n<p>Finally, let&#8217;s recap all the primary uses of the APK command in Alpine for package management.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>Command<\/th><th>Usage<\/th><\/tr><\/thead><tbody><tr><td><strong>apk update<\/strong><\/td><td>Update the index of available packages.<\/td><\/tr><tr><td><strong>apk upgrade<\/strong><\/td><td>Upgrade the currently installed packages.<\/td><\/tr><tr><td><strong>apk search<\/strong><\/td><td>Search for packages or descriptions.<\/td><\/tr><tr><td><strong>apk add<\/strong><\/td><td>Install new packages or upgrade existing ones.<\/td><\/tr><tr><td><strong>apk del<\/strong><\/td><td>Delete packages.<\/td><\/tr><tr><td><strong>apk info<\/strong><\/td><td>Prints information about installed or available packages.<\/td><\/tr><tr><td><strong>apk cache<\/strong><\/td><td>Maintenance operations for locally cached packages.<\/td><\/tr><tr><td><strong>apk fix<\/strong><\/td><td>Repair broken installed packages.<\/td><\/tr><tr><td><strong>apk policy<\/strong><\/td><td>Show information about the policies of a package.<\/td><\/tr><tr><td><strong>apk stats<\/strong><\/td><td> Displays summarized statistics about the installed packages.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>As we wrap up this Alpine User&#8217;s Guide to APK, I hope you feel more equipped and confident in managing packages on Alpine Linux. Remember, whether installing, updating, removing, or searching for packages, the APK command is your trusty companion in this journey.<\/p>\n\n\n\n<p>Moreover, don&#8217;t hesitate to revisit this guide whenever you need a refresher. Thanks for joining me on this adventure through Alpine Linux package management.<\/p>\n\n\n\n<p>I also strongly recommend checking out the <a href=\"https:\/\/wiki.alpinelinux.org\/wiki\/Alpine_Package_Keeper\" target=\"_blank\" rel=\"noreferrer noopener\">official manual<\/a>. It&#8217;s an excellent resource for quick reference on the key features of Alpine Package Keeper.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Your ultimate guide to Alpine Linux APK command! Learn how to manage packages &#8211; install, update, remove, and search &#8211; easily and confidently.<\/p>\n","protected":false},"author":10,"featured_media":97826,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4417],"tags":[4758,5579,1484,2016],"class_list":["post-97823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips","category-linux-knowledge","tag-alpine-linux","tag-apk","tag-commands","tag-package-manager"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/97823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/comments?post=97823"}],"version-history":[{"count":0,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/97823\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media\/97826"}],"wp:attachment":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media?parent=97823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/categories?post=97823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/tags?post=97823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}