<?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=Ivladak</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=Ivladak"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Ivladak"/>
	<updated>2026-04-25T18:31:41Z</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=14113</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=14113"/>
		<updated>2017-11-03T18:29:10Z</updated>

		<summary type="html">&lt;p&gt;Ivladak: typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Alpine Linux needs to be able to pull packages from local media on boot. (You can&#039;t download packages from the net before you have a network connection.)  Using remote repositories presents a problem.  If the config files have been modified for a newer version of a package, and the older package is on local media, all sorts of fun can result.&lt;br /&gt;
&lt;br /&gt;
The solution is a local cache of updated packages.   This cache can be stored on any r/w media, typically the same location as the apkovl.&lt;br /&gt;
&lt;br /&gt;
The cache is enabled by creating a symlink named &#039;&#039;/etc/apk/cache&#039;&#039; that points to the cache directory. Note that &#039;&#039;apk&#039;&#039; will ignore any cache residing on a &#039;&#039;tmpfs&#039;&#039; volume. If you want this for some reason, see section below on tmpfs caches.&lt;br /&gt;
&lt;br /&gt;
To enable local cache run: {{Cmd|setup-apkcache}}&lt;br /&gt;
&lt;br /&gt;
= To enable Local Cache on releases prior v2.3 =&lt;br /&gt;
Alpine Linux version prior to v2.3 does not have the &#039;&#039;setup-apkcache&#039;&#039; tool so the symlink needs to be set up manually.&lt;br /&gt;
&lt;br /&gt;
== To manually enable Local Cache on HDD install ==&lt;br /&gt;
If you&#039;ve installed Alpine to your hard drive (as &#039;sys&#039;), then create a cache dir and then an &#039;&#039;/etc/apk/cache&#039;&#039; symlink pointing to that dir:&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;
You normally don&#039;t need apk cache on HDD &#039;sys&#039; installs but it might be handy if you re-install from net to have the packages cached.&lt;br /&gt;
&lt;br /&gt;
== To manually enable Local Cache on run-from-RAM installs ==&lt;br /&gt;
&lt;br /&gt;
# Create a &#039;&#039;&#039;cache&#039;&#039;&#039; directory on the device you store your 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;
# Done.  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;
= Cache maintenance =&lt;br /&gt;
Over time, newer packages will replace older ones; the cache directory will contain all older versions of packages.  &lt;br /&gt;
&lt;br /&gt;
== Delete old packages ==&lt;br /&gt;
To clean out older versions of packages, run the &#039;&#039;&#039;clean&#039;&#039;&#039; command.  {{cmd|apk cache clean}} or to see what is deleted {{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;
= Using the Local Cache with tmpfs volumes =&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 /cache.img /etc/apk/cache&lt;br /&gt;
* apk update&lt;br /&gt;
&lt;br /&gt;
As per 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;
[[Category:Package Manager]]&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;/div&gt;</summary>
		<author><name>Ivladak</name></author>
	</entry>
</feed>