How to cache apt-get installation

Hi !

I've this this .gitlab-ci.yml configuration:

# use the official gcc image, based on debian
# can use verions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: gcc
before_script:
 - apt-get update --yes
 - apt-get install --yes cmake

build:
  stage: build
  script:
    - mkdir cmake-build-debug && cd cmake-build-debug
    - cmake -DCMAKE_BUILD_TYPE=Debug ..
    - cd ..
    - cmake --build cmake-build-debug -- -j 8
    - ./cmake-build-debug/test_runner
    
# TODO: It's bad that the test stage is included in the build stage. They should be separated

Every time a merge request or a push is made, the apt-get install cmake is run again and again. How can I cache the cmake installation to make next jobs faster?

Another question: I'm new to the CI world, my project will need to use Qt library for C++ GUI soon. How can I get my gitlab-ci file to support Qt? Is there an image to use (instead of image: gcc) that has Qt already installed?

Edited by Youssef Victor