<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Dnpr</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Dnpr"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Dnpr"/>
	<updated>2026-04-25T22:40:43Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Local_APK_cache&amp;diff=23338</id>
		<title>Local APK cache</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Local_APK_cache&amp;diff=23338"/>
		<updated>2023-04-30T16:07:12Z</updated>

		<summary type="html">&lt;p&gt;Dnpr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&amp;lt;!-- NOTE This page ([[Local_APK_cache]]) also gets included at [[Alpine_Linux_package_management#Local_Cache]] to avoid duplication. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
To have the packages available during boot, apk can keep a cache of installed packages on a local disk.  &lt;br /&gt;
&lt;br /&gt;
Added packages can then be automatically (re-)installed from local media into RAM when booting, without requiring, and even before there is a network connection.&lt;br /&gt;
&lt;br /&gt;
The cache can be stored on any writable media, or at the same location as the .apkovl file from the [[Alpine_local_backup| local backup utility &amp;lt;code&amp;gt;lbu&amp;lt;/code&amp;gt;]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Enabling Local Cache with current releases ===&lt;br /&gt;
&lt;br /&gt;
Execute the script {{Cmd|setup-apkcache}} and it will assist in enabling a local cache.&lt;br /&gt;
&lt;br /&gt;
The script creates a symlink named &#039;&#039;/etc/apk/cache&#039;&#039; that points to the cache directory.&lt;br /&gt;
&lt;br /&gt;
{{Tip|On a diskless installation, to make the disk where the cache directory is present be automatically mounted at boot you can create an empty file &#039;&#039;.boot_repository&#039;&#039; inside the cache directory.}}&lt;br /&gt;
&lt;br /&gt;
=== Cache maintenance ===&lt;br /&gt;
&lt;br /&gt;
==== Removing older packages ====&lt;br /&gt;
&lt;br /&gt;
When newer packages are added to the cache over time, the older versions of the packages default to remain in the cache directory.  &lt;br /&gt;
&lt;br /&gt;
The older versions of packages can be removed with the &#039;&#039;&#039;clean&#039;&#039;&#039; command.  {{cmd|apk cache clean}} Or to see what is deleted include the verbose switch: {{cmd|apk -v cache clean}}&lt;br /&gt;
&lt;br /&gt;
==== Download missing packages ====&lt;br /&gt;
If you accidentally delete packages from the cache directory, you can make sure they are there with the &#039;&#039;&#039;download&#039;&#039;&#039; command, {{cmd|apk cache download}}&lt;br /&gt;
&lt;br /&gt;
==== Delete and download in one step ====&lt;br /&gt;
You can combine the two steps into one with the &#039;&#039;&#039;sync&#039;&#039;&#039; command - this cleans out old packages and downloads missing packages. {{cmd|apk cache -v sync}}&lt;br /&gt;
&lt;br /&gt;
==== Automatically Cleaning Cache on Reboot ====&lt;br /&gt;
To automatically attempt to validate your cache on reboot, you can add the above command to a {{Path|/etc/local.d/*.stop}} file:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/local.d/cache.stop|#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# verify the local cache on shutdown&lt;br /&gt;
apk cache -v sync&lt;br /&gt;
&lt;br /&gt;
# We should always return 0&lt;br /&gt;
return 0&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Tip|Usually the only time you need to reboot is when things have gone horribly wrong; so this is a &amp;quot;best effort&amp;quot; to cover forgetting to sync the cache; It is much better to run &#039;&#039;&#039;sync&#039;&#039;&#039; immediately after adding or upgrading packages.}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Custom shutdown commands were formerly added to a {{Path|/etc/conf.d/local}}; but that method is now deprecated.}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Special Caching Configurations ===&lt;br /&gt;
&lt;br /&gt;
==== Enabling Local Cache on HDD installs ====&lt;br /&gt;
&lt;br /&gt;
Note that HDD &#039;sys&#039; installs don&#039;t need an apk cache to maintain their state, it allows to serve packages over the network, though, e.g. to get installed by other local machines.&lt;br /&gt;
&lt;br /&gt;
Manually create a cache dir and then symlink it to &#039;&#039;/etc/apk/cache&#039;&#039;:&lt;br /&gt;
{{Cmd|mkdir -p /var/cache/apk&lt;br /&gt;
ln -s /var/cache/apk /etc/apk/cache}}&lt;br /&gt;
&lt;br /&gt;
==== Local Cache on tmpfs volumes ====&lt;br /&gt;
&lt;br /&gt;
In some circumstances it might be useful to have the cache reside on tmpfs, for example if you only wish for it to last as long as the system is up.&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;apk&#039;&#039; is coded to ignore tmpfs caches, and this is correct behaviour in most instances. Using tmpfs as a package cache can consume large amounts of system memory if you install a lot of packages, possibly resulting in a crashed system. You can limit this by restricting the size of your cache to a small number (128M in the example below).&lt;br /&gt;
&lt;br /&gt;
To do it, you need to create an image inside which your cache can live. We do this by creating an image file, formatting it with ext2, and mounting it at &#039;&#039;/etc/apk/cache&#039;&#039;.&lt;br /&gt;
* apk add e2fsprogs&lt;br /&gt;
* dd if=/dev/zero of=/apkcache.img bs=1M count=128&lt;br /&gt;
* mkfs.ext2 -F /apkcache.img&lt;br /&gt;
* mkdir -p /etc/apk/cache&lt;br /&gt;
* mount -t ext2 /apkcache.img /etc/apk/cache&lt;br /&gt;
* apk update&lt;br /&gt;
&lt;br /&gt;
As usual, if you want to download currently installed packages into the cache, use &#039;&#039;apk cache sync&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Manually Enabling Local Cache (required for releases prior to v2.3) ====&lt;br /&gt;
&lt;br /&gt;
# Create a &#039;&#039;&#039;cache&#039;&#039;&#039; directory on the storage device where you keep the lbu backups (typically, &amp;lt;code&amp;gt;/dev/sda1&amp;lt;/code&amp;gt;.)  {{Cmd| mkdir /media/sda1/cache }}&lt;br /&gt;
{{Tip|If you get an error that says &amp;quot;mkdir: can&#039;t create directory &#039;/media/usbdisk/cache&#039;: Read-only file system&amp;quot;, then you probably need to remount your disk read-write temporarily.  Try {{Cmd|mount -o remount,rw /media/sda1}} and then don&#039;t forget to run {{Cmd|mount -o remount,ro /media/sda1}} when you are done with the following commands}}&lt;br /&gt;
# Create a symlink to this directory from &amp;lt;code&amp;gt;/etc/apk/cache&amp;lt;/code&amp;gt;.  {{Cmd|ln -s /media/sda1/cache /etc/apk/cache}}&lt;br /&gt;
# Run an lbu commit to save the change (&amp;lt;code&amp;gt;/etc/apk/cache&amp;lt;/code&amp;gt; is in &amp;lt;code&amp;gt;/etc&amp;lt;/code&amp;gt; and is automatically backed up.) {{Cmd|lbu commit}}&lt;br /&gt;
{{Tip|If you needed to remount your disk read-write before, run {{Cmd|mount -o remount,ro /media/sda1}} now that you are done with saving the changes}}&lt;br /&gt;
&lt;br /&gt;
Now whenever you run an apk command that pulls a new package from a remote repository, the package is stored on your local media.  On startup, Alpine Linux will check the local cache for new packages, and will install them if available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&lt;br /&gt;
== Enabling Package Caching (Older) ==&lt;br /&gt;
&lt;br /&gt;
{{Note|This document applies to Alpine 1.9 and later versions only}}&lt;br /&gt;
&lt;br /&gt;
Package caching is useful when the need arises to upgrade packages on read-only media. Package caching allows you to store newer packages in a location on writable media, which Alpine checks for when loading packages on start-up.&lt;br /&gt;
&lt;br /&gt;
This can be enabled either from the console or through the ACF.&lt;br /&gt;
&lt;br /&gt;
{{Tip|For package upgrades, it is useful to point Alpine Package Manager to repositories on the internet, to easily obtain package upgrades when they become available.}}&lt;br /&gt;
&lt;br /&gt;
{{:Include:Using_Internet_Repositories_for_apk-tools}}&lt;br /&gt;
&lt;br /&gt;
== Enable caching from either console or ACF ==&lt;br /&gt;
&lt;br /&gt;
Choose one of the two methods below to enable, either from the console or from the ACF web interface.&lt;br /&gt;
&lt;br /&gt;
=== Option 1: Enable caching from the console ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Substitute &#039;sda1&#039; in the example below for the actual device you will use to store the caching directory.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First upgrade apk-tools:&lt;br /&gt;
{{Cmd|apk add –u apk-tools}}&lt;br /&gt;
&lt;br /&gt;
Now enable package caching:&lt;br /&gt;
{{Cmd|mkdir –p /media/sda1/cache&lt;br /&gt;
ln –s /media/sda1/cache /etc/apk/cache}}&lt;br /&gt;
&lt;br /&gt;
=== Option 2: From the ACF ===&lt;br /&gt;
&lt;br /&gt;
Browse to &#039;&#039;&#039;System &amp;gt; Packages &amp;gt; Cache&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Edit Cache Settings:&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tick &#039;&#039;&#039;Enable Cache&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Specify the &#039;&#039;&#039;Cache Directory&#039;&#039;&#039;, for example:&lt;br /&gt;
 /media/sda1/cache&lt;br /&gt;
&lt;br /&gt;
Click &#039;&#039;&#039;Save&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Package Manager]]&lt;/div&gt;</summary>
		<author><name>Dnpr</name></author>
	</entry>
</feed>