Skip to content

Instantly share code, notes, and snippets.

@raulqf
Last active January 8, 2023 11:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save raulqf/928813979db4dc01f29217134b9fb113 to your computer and use it in GitHub Desktop.
Save raulqf/928813979db4dc01f29217134b9fb113 to your computer and use it in GitHub Desktop.
How to install Qt libraries on Linux from source code

How to install Qt on Linux from source code

One of the best option is to use the run package offered by Qt to install the libraries and its IDE (Qt Creator). Nevertheless However, when you want to compile it for a sever, where no GUI is required, you must be then interested in how to compile from source and discover some of the configuration options you have to disable some GUI modules among others and get lightest weight libraries.

First of all download the tar.xz file from Qt. You can also go to the archive and select the best that fulfill your requirement. Right now I am going on with the newest version up to the moment v5.9.3.

Create a directory and uncompress the downloaded file:

  $ mkdir temp
  $ cd temp
  $ mv ~/Download/qt-everywhere-opensource-src-5.9.3.tar.xz .
  $ tar xf qt-everywhere-opensource-src-5.9.3.tar.xz
  $ cd qt-everywhere-opensource-src-5.9.3

Now, it's time to set the configure option to select the kind of Qt libraries compilation that you want:

  - For a server without GUI modules:
  
  ./configure -release -no-xcb -nomake examples -nomake tools -prefix /usr/local/qt-5.9.3
  
  - For a server without GUI modules and other non-essentials modules to get a lightweight version:
  
  ./configure -release -opensource -prefix /usr/local/qt-5.10.1 -shared -confirm-license -system-zlib -system-libpng -system-libjpeg -no-accessibility -no-freetype -no-harfbuzz -no-glib -no-gui -no-widgets -no-cups -no-iconv -no-evdev -no-icu -no-fontconfig -no-pch -no-dbus -no-xcb -no-directfb -no-linuxfb -no-kms -no-opengl -nomake examples -nomake tests -skip qtgamepad -skip qtdoc -skip qtgraphicaleffects -skip qtlocation -skip qtquickcontrols -skip qtscript -skip qttranslations -skip qtx11extras -skip qtxmlpatterns -qt-xcb
  
  - Static build with Qt GUI. To make it dynamic remove the static flag
 
  ./configure -static -prefix /usr/local/qt-5.9.3

Then we can proceed to make it and install:

 $ make
 $ make install (sudo make install)

Add the binaries (qmake and others) to the path. In bash shell you can add to your .profile or .bashrc the following at the bottom of the file:

  export PATH=/usr/local/qt-5.9.3/bin:$PATH

Check that the libraries have been also included otherwise you can also configure your .profile or .bashrc in the same way but for the libs:

  export LD_LIBRARY_PATH=/usr/local/qt-5.9.3/lib:$LD_LIBRARY_PATH

Compile Qt using command line

qmake file.pro -r -spec linux-g++ CONIFG+=release make

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment