diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 18ae4459cd3e7d57d24fc8334b9feb4df8169849..7bc250338be35299f96a84f6c58938e1d9023c66 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -47,7 +47,9 @@ build-native:       # This job runs in the build stage, which runs first.
     - export CCACHE_BASEDIR="$PWD"
     - export CCACHE_DIR="$PWD/ccache"
     - export CCACHE_COMPILERCHECK=content
-    - echo -n Dir::Cache="$PWD/apt" | tee /etc/apt/apt.conf.d/99cache
+    - export APT_CACHE_DIR=`pwd`/apt-cache
+    - mkdir --parents --verbose $APT_CACHE_DIR/partial/
+    - echo dir::cache::archives="$APT_CACHE_DIR" | tee --append /etc/apt/apt.conf.d/99cache
     - apt-get update
     - apt-get install --no-install-recommends --yes ccache
     - ccache --zero-stats || true