How to enable APK caching: Difference between revisions

From Alpine Linux
(created page)
 
(added Note and Tip template)
Line 1: Line 1:
== Enabling Package Caching ==
== Enabling Package Caching ==


'''''This document applies to Alpine 1.9 and later versions only'''''
{{Note|This document applies to Alpine 1.9 and later versions only}}


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.
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.
Line 7: Line 7:
This can be enabled either from the console or through the ACF.
This can be enabled either from the console or through the ACF.


'''Note:''' 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.
{{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.}}


{{Using_Internet_Repositories_for_apk-tools}}
{{Using_Internet_Repositories_for_apk-tools}}

Revision as of 05:18, 14 April 2010

Enabling Package Caching

Note: This document applies to Alpine 1.9 and later versions only

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.

This can be enabled either from the console or through the ACF.

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.


Update Repositories File

The Repositories file /etc/apk/repositories can be updated using one of the following methods.

Using setup-apkrepos script

Launch the setup-apkrepos script:

# setup-apkrepos

Pressing e will open the file to edit using vi editor. Edit the repository lines to reflect the new version number.

Using sed command

Use a one-line command to edit all version numbers in the file "in place". Here's how you'd change 3.21 to 3.22:

# sed -i -e 's/v3.21/v3.22/g' /etc/apk/repositories

Manual editing of /etc/apk/repositories

Edit the /etc/apk/repositories file using any editor of your choice (nano for instance).

Contents of /etc/apk/repositories

http://dl-3.alpinelinux.org/alpine/v3.21/main http://dl-3.alpinelinux.org/alpine/v3.21/community

In the above file, to upgrade Alpine Linux from version 3.21 to 3.22, simply replace the number 3.21 by 3.22 in all the places:

Contents of /etc/apk/repositories

http://dl-3.alpinelinux.org/alpine/v3.22/main http://dl-3.alpinelinux.org/alpine/v3.22/community

Using latest-stable instead of version number

Manual changes of the version numbers may be avoided for future release upgrades by having the repository lines refer to "latest-stable" instead of an absolute value in the repositories file.

Warning: Changing the repositories to latest-stable may initiate unexpected release upgrades. Beware of the consequences.


The /etc/apk/repositories file should appear as follows:

Contents of /etc/apk/repositories

http://dl-3.alpinelinux.org/alpine/latest-stable/main http://dl-3.alpinelinux.org/alpine/latest-stable/community

Updating package lists

With the correct repositories file in place, the latest index list of available packages can be obtained with:

# apk update

Tip: Adding the --update-cache or -U to another apk command, as in apk add -U ... or apk upgrade -U, has the same effect as always running apk update immediately before the other apk command. Instead of auto-update it only if the index has not been updated recently.

Upgrading packages

At times it is required to first upgrade just the Alpine Linux Package Manager itself to the latest available version, before upgrading any other package. This was the case, for example, when upgrading from a version of Alpine before 2.3.0_rc1. But simply always doing so shouldn't hurt, either:

# apk add --upgrade apk-tools

Next, to upgrade all installed packages:

# apk upgrade --available

The --available switch is used to force all packages to be upgraded, even if they have the same version numbers. Sometimes changes in musl require doing this.

Note: All services that have been upgraded need to be restarted, to begin using the upgraded version. If the kernel is upgraded, it's required to reboot to begin using the upgraded version:

sync reboot

Enable caching from the console

Substitute 'sda1' in the example below for the actual device you will use to store the caching directory.

First upgrade apk-tools:

apk add –u apk-tools

Now enable package caching:

mkdir –p /media/sda1/cache
ln –s /media/sda1/cache /etc/apk/cache

From the ACF

Browse to System > Packages > Cache

Edit Cache Settings:

Tick Enable Cache

Specify the Cache Directory, for example:

/media/sda1/cache

Click Save