Installing Qt 5.15 on CentOS 7 requires compiling the framework from source code because the default repositories only provide older versions. This guide walks you through downloading the source, configuring the build environment with necessary dependencies like GCC and OpenSSL, and compiling the toolkit to ensure compatibility with modern C++ standards and development tools on your Red Hat Enterprise Linux-based system.
Prerequisites and System Preparation
Before initiating the installation, you must ensure that your CentOS 7 system has the essential development tools installed. The build process relies heavily on a complete set of compilers and libraries. You need to update your package manager cache and install the base group for development tools. Run the following command to install the core components required for building Qt:
yum groupinstall "Development Tools"
yum install epel-release
yum install openssl-devel libxcb-devel xcb-util-wm-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-renderutil-devel
The
openssl-devel package is critical because Qt 5.15 uses OpenSSL for secure network communications. Without it, the configuration step will fail or produce warnings about missing cryptographic support. Additionally, installing the EPEL repository ensures access to additional packages that might be needed during the dependency resolution phase. It is also advisable to verify your installed GCC version, as Qt 5.15 works best with GCC 4.8.5 or newer, which is standard on CentOS 7.
Downloading the Qt Source Code
Since binary packages for Qt 5.15 are not available in the standard CentOS 7 repositories, you must download the single-file source archive. This archive contains all modules combined into one large file, simplifying the initial setup. Navigate to your preferred directory for storing source files, such as
/usr/local/src, and use
wget to retrieve the installer.
cd /usr/local/src
wget https://download.qt.io/archive/qt/5.15/5.15.0/single/qt-everywhere-src-5.15.0.tar.xz
Once the download completes, extract the archive using the
tar utility. The extraction process may take a few minutes depending on your system's I/O speed. After extraction, change into the newly created directory to begin the configuration process.
tar xf qt-everywhere-src-5.15.0.tar.xz
cd qt-everywhere-src-5.15.0
This directory structure contains the configure script and all module sources. It is important to stay within this directory when running subsequent commands to ensure paths are resolved correctly relative to the source tree.
Configuring the Build Environment
The configuration step determines which features are enabled and where libraries are located. For most developers, enabling both static and shared libraries is beneficial, though static linking increases binary size significantly. You can configure the build by running the
./configure script with appropriate flags. A typical command for a general-purpose development setup looks like this:
./configure -prefix /usr/local/Qt-5.15 -opensource -confirm-license -release -shared -dbus-linked -qt-xcb -qt-pcre -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -make libs -nomake examples -nomake tests
The
-prefix flag specifies the installation directory. Choose a location that does not conflict with system packages, such as
/usr/local/Qt-5.15. The
-opensource and
-confirm-license flags automate the license acceptance for the open-source edition. The
-dbus-linked flag ensures proper integration with the D-Bus messaging system, which is often used for inter-process communication in Linux desktop environments. If you encounter issues related to X11 rendering, ensure that
libX11-devel and
libXi-devel are installed via
yum.
For those who require specific database drivers or multimedia support, you can add flags like
-qt-sqlite or
-gstreamer. However, keeping the build minimal by excluding examples and tests (
-nomake examples -nomake tests) speeds up the compilation process significantly.
Compiling and Installing
After successful configuration, the next step is to compile the source code. Use the
make command with the
-j option to utilize multiple CPU cores, which drastically reduces build time. Replace
N with the number of cores available on your machine.
make -j$(nproc)
This process can take anywhere from 30 minutes to several hours depending on hardware performance. Once compilation finishes, install the binaries and headers by running the make install command with root privileges.
sudo make install
This copies the compiled libraries, executables, and header files to the prefix directory specified earlier. To make the Qt tools accessible from the command line, you should add the bin directory to your
PATH environment variable. Add the following line to your
~/.bashrc or
/etc/profile:
export PATH=/usr/local/Qt-5.15/bin:$PATH
Source your profile to apply changes immediately. Verify the installation by checking the version of qmake.
qmake --version
You should see output indicating Qt version 5.15.x. This confirms that the toolkit is correctly installed and ready for use in your development projects.
Integrating with IDEs
While command-line usage is straightforward, integrating Qt 5.15 with an IDE like Qt Creator enhances productivity. Download and install the latest version of Qt Creator compatible with your system. During the installation or within the application settings, navigate to the Kits section. Add a new Kit and select the compiler (GCC) and debugger (GDB) installed on your system. Crucially, point the QMake path to
/usr/local/Qt-5.15/bin/qmake. This ensures that any new project created uses the correct Qt 5.15 libraries.
For more information on managing complex build environments, you might find resources on troubleshooting virtualization guests useful, similar to guides on
Issues Installing VirtualBox Guest Additions on RHEL 9 Server, as the principles of driver and library compatibility often overlap.
Frequently Asked Questions
Why can't I install Qt 5.15 using yum?
CentOS 7's default repositories contain older versions of Qt, typically around 4.8 or early 5.x releases. Newer versions like 5.15 are not included in the stable base repositories due to stability policies. Therefore, manual compilation from source is the standard method for obtaining recent Qt versions on this OS.
Do I need to uninstall previous Qt versions before installing 5.15?
No, you do not need to uninstall existing versions if they are installed in different directories. By setting a unique prefix like
/usr/local/Qt-5.15, you keep the new installation isolated. Just ensure your
PATH variable points to the correct version's bin directory to avoid conflicts.
What should I do if the configure script fails to find OpenGL?
Ensure that you have installed the Mesa OpenGL development libraries. On CentOS 7, these are provided by the
mesa-libGL-devel and
mesa-libGLU-devel packages. Install them using
yum and re-run the configure script. Also, verify that your graphics drivers are properly configured for the desktop environment.
Can I use this Qt installation with Python PyQt?
Yes, but you must build PyQt5 against the same Qt 5.15 installation. You need to specify the path to the qmake executable of your custom Qt installation during the PyQt5 build process. This ensures that the Python bindings link against the correct libraries rather than system defaults.
How do I remove Qt 5.15 if I made a mistake?
If you installed to a specific prefix like
/usr/local/Qt-5.15, you can simply delete that directory. Remove the corresponding entry from your
PATH in
.bashrc or
/etc/profile and reload the shell configuration. This leaves no residual files on the system.