How to upgrade Alpine Linux 3.8 to 3.9

I am using Alpine Linux v3.7 or v3.8 with my LXD server. How do I upgrade Alpine Linux v3.8 to Alpine Linux v3.9? How can I upgrade Alpine Linux v3.8 to Alpine Linux v3.9?

Before you type any one of the following command make sure that you have a backup of your important data before continuing to update your system. It is important that you keep full backup of your system. Alpine Linux is built around musl libc and busybox. This makes it smaller and more resource efficient than traditional GNU/Linux distributions. A container requires no more than 8 MB and a minimal installation to disk requires around 130 MB of storage. Not only do you get a fully-fledged Linux environment but a large selection of packages from the repository.

Alpine Linux was designed with security in mind. The kernel is patched with an unofficial port of grsecurity/PaX, and all userland binaries are compiled as Position Independent Executables (PIE) with stack smashing protection. These proactive security features prevent exploitation of entire classes of zero-day and other vulnerabilities. When Alpine Linux is installed to hard drive or as LXD VM, upgrading to a newer stable version is straightforward.

Make a backup of your LXD container

Type the following command to create container snapshots:
$ lxc snapshot alpine-www01 "JUNE272018"
Verify it:
$ lxc info alpine-www01
Sample outputs:

Name: alpine-www01
Remote: unix://
Architecture: x86_64
Created: 2017/07/17 11:38 UTC
Status: Running
Type: persistent
Profiles: default
Pid: 2652
  eth0:	inet	veth0H03I3
  eth0:	inet6	fe80::216:3eff:fe1c:8793	veth0H03I3
  lo:	inet
  lo:	inet6	::1
  Processes: 38
  CPU usage:
    CPU usage (in seconds): 88
  Memory usage:
    Memory (current): 65.80MB
    Memory (peak): 80.70MB
  Network usage:
      Bytes received: 5.97MB
      Bytes sent: 3.23MB
      Packets received: 51890
      Packets sent: 30849
      Bytes received: 246.80kB
      Bytes sent: 246.80kB
      Packets received: 1840
      Packets sent: 1840
  Dec052017 (taken at 2017/12/05 07:33 UTC) (stateless)
  JUNE272018 (taken at 2018/06/26 22:54 UTC) (stateless)

Now login to your Alpine Linux box/LXD VM using ssh command or lxc command.

Find out your Alpine Linux version

Type the following command:
$ cat /etc/alpine-release

How to upgrading to latest release

Edit /etc/apk/repositories file, enter:
# vi /etc/apk/repositories
Change the version number by hand. For example, the default entry for 3.4 is as follows:
To update to 3.5.xx, enter:
Change the version number by hand. For example, the default entry for 3.5 is as follows:
To update to 3.5.xx, enter:
Change the version number by hand. For example, the default entry for 3.6 is as follows:
Make sure you change the version number by hand. For example, the default entry for 3.7 is as follows:
To update to 3.8.xx, enter:
Make upgrade to to 3.9.xx, enter:
Save and close the file. Here is my sample config file displayed using cat command:
# cat /etc/apk/repositories
Sample outputs:

Next grab the latest index using apk command:
# apk update
Sample outputs:

v3.9.0-9-gf2000237b1 []
v3.9.0-7-g0c93582c23 []
OK: 9832 distinct packages available

To upgrade all your packages, run apk command:
# apk upgrade --available
# apk upgrade --purge
Sample outputs:

Upgrading critical system libraries and apk-tools:
(1/3) Installing libcrypto1.1 (1.1.1a-r1)
(2/3) Installing libssl1.1 (1.1.1a-r1)
(3/3) Upgrading apk-tools (2.10.1-r0 -> 2.10.3-r1)
Executing busybox-1.28.4-r3.trigger
Executing ca-certificates-20171114-r3.trigger
Continuing the upgrade transaction with new apk-tools:
(1/81) Upgrading musl (1.1.19-r10 -> 1.1.20-r3)
(2/81) Upgrading busybox (1.28.4-r3 -> 1.29.3-r10)
(3/81) Upgrading alpine-baselayout (3.1.0-r0 -> 3.1.0-r3)
Executing alpine-baselayout-3.1.0-r3.pre-upgrade
(4/81) Upgrading openrc (0.35.5-r5 -> 0.39.2-r3)
(5/81) Upgrading alpine-conf (3.8.0-r0 -> 3.8.1-r1)
(6/81) Installing ca-certificates-cacert (20190108-r0)
(7/81) Installing libtls-standalone (2.7.4-r6)
(8/81) Upgrading ssl_client (1.28.4-r3 -> 1.29.3-r10)
(9/81) Replacing zlib (1.2.11-r1 -> 1.2.11-r1)
(10/81) Upgrading busybox-suid (1.28.4-r3 -> 1.29.3-r10)
(11/81) Upgrading busybox-initscripts (3.1-r3 -> 3.1-r6)
(12/81) Replacing scanelf (1.2.3-r0 -> 1.2.3-r0)
(13/81) Upgrading musl-utils (1.1.19-r10 -> 1.1.20-r3)
(14/81) Replacing libc-utils (0.7.1-r0 -> 0.7.1-r0)
(15/81) Replacing alpine-keys (2.1-r1 -> 2.1-r1)
(16/81) Upgrading alpine-base (3.8.2-r0 -> 3.9.0-r0)
(17/81) Upgrading readline (7.0.003-r0 -> 7.0.003-r1)
(18/81) Replacing bash (4.4.19-r1 -> 4.4.19-r1)
(19/81) Replacing bash-completion (2.8-r0 -> 2.8-r0)
(20/81) Replacing bash-doc (4.4.19-r1 -> 4.4.19-r1)
(21/81) Replacing bc (1.07.1-r0 -> 1.07.1-r0)
(22/81) Upgrading ca-certificates (20171114-r3 -> 20190108-r0)
(23/81) Upgrading nghttp2-libs (1.32.0-r0 -> 1.35.1-r0)
(24/81) Upgrading libssh2 (1.8.0-r3 -> 1.8.0-r4)
(25/81) Upgrading libcurl (7.61.1-r1 -> 7.63.0-r0)
(26/81) Upgrading curl (7.61.1-r1 -> 7.63.0-r0)
(27/81) Upgrading expat (2.2.5-r0 -> 2.2.6-r0)
(28/81) Upgrading pcre2 (10.31-r0 -> 10.32-r1)
(29/81) Upgrading git (2.18.1-r0 -> 2.20.1-r0)
(30/81) Upgrading git-bash-completion (2.18.1-r0 -> 2.20.1-r0)
(31/81) Upgrading libressl2.7-libcrypto (2.7.4-r0 -> 2.7.4-r2)
(32/81) Upgrading libressl2.7-libssl (2.7.4-r0 -> 2.7.4-r2)
(33/81) Upgrading libressl2.7-libtls (2.7.4-r0 -> 2.7.4-r2)
(34/81) Upgrading libressl (2.7.4-r0 -> 2.7.4-r2)
(35/81) Replacing popt (1.16-r7 -> 1.16-r7)
(36/81) Upgrading logrotate (3.14.0-r0 -> 3.15.0-r0)
(37/81) Installing logrotate-openrc (3.15.0-r0)
(38/81) Upgrading mariadb-common (10.2.19-r1 -> 10.3.12-r2)
(39/81) Upgrading libgcc (6.4.0-r9 -> 8.2.0-r2)
(40/81) Upgrading libstdc++ (6.4.0-r9 -> 8.2.0-r2)
(41/81) Upgrading mariadb-client (10.2.19-r1 -> 10.3.12-r2)
(42/81) Upgrading mysql-client (10.2.19-r1 -> 10.3.12-r2)
(43/81) Replacing libbsd (0.8.6-r2 -> 0.8.6-r2)
(44/81) Replacing netcat-openbsd (1.130-r1 -> 1.130-r1)
(45/81) Upgrading pcre (8.42-r0 -> 8.42-r1)
(46/81) Replacing nginx (1.14.2-r0 -> 1.14.2-r0)
Executing nginx-1.14.2-r0.pre-upgrade
(47/81) Upgrading php7-common (7.2.13-r0 -> 7.2.14-r0)
(48/81) Upgrading libedit (20170329.3.1-r3 -> 20181209.3.1-r0)
(49/81) Upgrading libxml2 (2.9.8-r1 -> 2.9.9-r0)
(50/81) Upgrading php7 (7.2.13-r0 -> 7.2.14-r0)
(51/81) Upgrading php7-curl (7.2.13-r0 -> 7.2.14-r0)
(52/81) Upgrading php7-fpm (7.2.13-r0 -> 7.2.14-r0)
(53/81) Upgrading libxau (1.0.8-r2 -> 1.0.8-r3)
(54/81) Upgrading libxdmcp (1.1.2-r4 -> 1.1.2-r5)
(55/81) Replacing libxcb (1.13-r2 -> 1.13-r2)
(56/81) Upgrading libx11 (1.6.6-r0 -> 1.6.7-r0)
(57/81) Upgrading libxext (1.3.3-r2 -> 1.3.3-r3)
(58/81) Upgrading libice (1.0.9-r2 -> 1.0.9-r3)
(59/81) Upgrading libuuid (2.32-r0 -> 2.33-r0)
(60/81) Upgrading libsm (1.2.2-r1 -> 1.2.2-r2)
(61/81) Upgrading libxt (1.1.5-r1 -> 1.1.5-r2)
(62/81) Replacing libxpm (3.5.12-r0 -> 3.5.12-r0)
(63/81) Replacing libbz2 (1.0.6-r6 -> 1.0.6-r6)
(64/81) Upgrading libpng (1.6.34-r1 -> 1.6.35-r0)
(65/81) Upgrading freetype (2.9.1-r1 -> 2.9.1-r2)
(66/81) Replacing libjpeg-turbo (1.5.3-r4 -> 1.5.3-r4)
(67/81) Upgrading libwebp (1.0.0-r0 -> 1.0.1-r0)
(68/81) Upgrading php7-gd (7.2.13-r0 -> 7.2.14-r0)
(69/81) Upgrading libintl ( ->
(70/81) Upgrading php7-gettext (7.2.13-r0 -> 7.2.14-r0)
(71/81) Upgrading php7-json (7.2.13-r0 -> 7.2.14-r0)
(72/81) Upgrading php7-openssl (7.2.13-r0 -> 7.2.14-r0)
(73/81) Upgrading php7-mysqlnd (7.2.13-r0 -> 7.2.14-r0)
(74/81) Upgrading php7-mysqli (7.2.13-r0 -> 7.2.14-r0)
(75/81) Upgrading php7-opcache (7.2.13-r0 -> 7.2.14-r0)
(76/81) Upgrading php7-phar (7.2.13-r0 -> 7.2.14-r0)
(77/81) Upgrading php7-session (7.2.13-r0 -> 7.2.14-r0)
(78/81) Upgrading php7-simplexml (7.2.13-r0 -> 7.2.14-r0)
(79/81) Replacing libgd (2.2.5-r1 -> 2.2.5-r1)
(80/81) Replacing vnstat (1.18-r0 -> 1.18-r0)
(81/81) Replacing wget (1.20.1-r0 -> 1.20.1-r0)
Executing busybox-1.29.3-r10.trigger
Executing ca-certificates-20190108-r0.trigger
OK: 94 MiB in 87 packages

Restart the server/VM container:
# sync
# reboot

Verify it:
$ cat /etc/alpine-release

Conclusion – Upgrade Alpine Linux

And there you have it, Alpine Linux upgraded from version 3.8 to 3.9. For more information see