The process for building Qt6 from source is surprising obscure. This is due to the Qt Foundation's unusual licensing, lack of clarity in documentations, and the cincher: that the qt6 source code exists in the qt5 repository. So I'm writing this article to hopefully prevent me from having to relearn this process every time.
Good news, despite what the docs might imply, you don't need to sign up to their gerrit instance, you don't need a qt.io account. You just need to know where to look.
These instructions were tested on Fedora, but should work on most Linuxes. More information (and where I finally found the build instructions in the miasma of Qt docs) can be found here: https://wiki.qt.io/Building_Qt_6_from_Git
Qt6 (as of this writing) requires at least the following to build (depending on the version of qt and modules you're building): git
, cmake
, perl
, python2
, libclang
, ninja
, clang
or gcc
, libgl
or libegl
, libinput
, and libfontconfig
.
- dnf install -y clang clang-libs ninja-build cmake libglvnd-devel libinput-devel fontconfig-devel python2.7
This should install the necessary dependencies on Fedora
The qt source code (for 5 and 6) is available from gerrit at https://code.qt.io/cgit/qt/qt5.git/
- git clone git://code.qt.io/qt/qt5.git qt6
- cd qt6
- git checkout v6.5.0
First we clone the qt5 repo, I renamed it qt6 for clarity, then we checkout the relevant git tag for the qt6 release you desire.
- perl init-repository
Next download all of the submodules. This may be several Gigabytes of downloads.
If you know which modules you'll need, you can save space and bandwidth by specifying them individually a la:
- perl init-repository --module-subset=qtbase,qtshadertools,qtdeclarative
- mkdir ../qt6-build
- cd ../qt6-build
Next we create a build directory outside of source directory
- ../qt6/configure -prefix /usr/local
- cmake --build . --parallel $(nproc)
- cmake --install .
Finally, we configure and build from inside the build directory. On my laptop with a 10th gen i7, and only compiling with a small subset of submodules (qtbase
, qtshadertools
, and qtdeclarative
), this took about 3 hours to build, and about 10GB of disk space once built.
Happy building!