How to switch Qt version in Ubuntu

It’s surprising how often people seem to ponder how to switch between different Qt/Qtopia versions when they have multiple versions of Qt/Qtopia installed. All what really matters is to have the right qmake in PATH at time. Even if it might not be that hard to write a shell script to do the switch, I decided to praise Debian’s update-alternatives tool a bit. Just look below how easy it is to manage multiple Qt/Qtopia installations with update-alternatives.

I have installed Qt 4.3.2 from Ubuntu repositories to /usr/lib. In addition to that, I have the following hand-compiled installations:

$ ls /usr/local/Trolltech
Qt-4.3.4  Qt-4.4.0-beta1  QtopiaCore-4.3.4  QtopiaCore-4.4.0-beta1

Update-alternatives is already aware of the Qt version installed from Ubuntu repositories. To make it also aware of those hand-made compilations we invoke such commands as:

sudo update-alternatives --install /usr/bin/qmake qmake /usr/local/Trolltech/Qt-4.3.4/bin/qmake 30
sudo update-alternatives --install /usr/bin/qmake qmake /usr/local/Trolltech/Qt-4.4.0-beta1/bin/qmake 10
sudo update-alternatives --install /usr/bin/qmake qmake /usr/local/Trolltech/QtopiaCore-4.3.4/bin/qmake 20
sudo update-alternatives --install /usr/bin/qmake qmake /usr/local/Trolltech/QtopiaCore-4.4.0-beta1/bin/qmake 10

Whenever I want to change the Qt/Qtopia version I do:

$ sudo update-alternatives --config qmake

There are 5 alternatives which provide `qmake'.

  Selection    Alternative
-----------------------------------------------
 +        1    /usr/bin/qmake-qt4
*         2    /usr/local/Trolltech/Qt-4.3.4/bin/qmake
          3    /usr/local/Trolltech/QtopiaCore-4.3.4/bin/qmake
          4    /usr/local/Trolltech/Qt-4.4.0-beta1/bin/qmake
          5    /usr/local/Trolltech/QtopiaCore-4.4.0-beta1/bin/qmake

Press enter to keep the default[*], or type selection number:

Not very complicated, is it?

13 Responses to “How to switch Qt version in Ubuntu”

  1. J-P Nurmi

    Oh, and you can use “slaves” to make it a complete switch, including the whole set of Qt tools. For example:

    sudo update-alternatives –install /usr/bin/qmake qmake /usr/local/Trolltech/Qt-snapshot/bin/qmake 25 –slave /usr/bin/moc moc /usr/local/Trolltech/Qt-snapshot/bin/moc –slave /usr/bin/uic uic /usr/local/Trolltech/Qt-snapshot/bin/uic –slave /usr/bin/rcc rcc /usr/local/Trolltech/Qt-snapshot/bin/rcc –slave /usr/bin/lrelease lrelease /usr/local/Trolltech/Qt-snapshot/bin/lrelease –slave /usr/bin/lupdate lupdate /usr/local/Trolltech/Qt-snapshot/bin/lupdate –slave /usr/bin/linguist linguist /usr/local/Trolltech/Qt-snapshot/bin/linguist –slave /usr/bin/assistant assistant /usr/local/Trolltech/Qt-snapshot/bin/assistant –slave /usr/bin/designer designer /usr/local/Trolltech/Qt-snapshot/bin/designer

  2. Anonymous

    hi ,

    Could you tell me how to install Qt-4.3.4 successfully in Ubuntu 8.10

  3. J-P Nurmi

    Why 4.3.4? There’s 4.4.3 in Ubuntu Intrepid repos:

    sudo apt-get install libqt4-dev qt4-dev-tools qt4-doc

  4. Janez

    Hi,

    another demande how to install qt 4.3.x under ubuntu 8.10. The reason is quiet simple. If i want ot use OpenFoam -> paraFoam (binary package) there must be installed Qt 4.3.x. Doesn’t work with 4.4.x.

    Janez

  5. J-P Nurmi

    Hi,

    I still don’t know why because Qt 4.4 is backwards binary compatible with Qt 4.3. But anyway, then download the Qt 4.3 source package from ftp://ftp.trolltech.com/qt/source and follow the installation instructions http://doc.trolltech.com/4.3/install-x11.html.

    PS. Pay attention to the configure script output, after qmake has been compiled. There’s a detailed summary you might want to check out. Enabling some specific feature is only a matter of installing the corresponding development (ie. libxxx-dev) package.

  6. kenez

    Hi,

    Thank you for your post, which solve my problem about qmake version update!

    kenez

  7. qt4.3.4 with ubuntu 9.04 "jaunty jackalope"? -- CFD Online Discussion Forums

    [...] worked on my ubuntu just fine. follow the qt4.3.4 then i followed this webpage http://jpnurmi.kapsi.fi/blog/2008/03…ion-in-ubuntu/ do this: sudo update-alternatives –install /usr/bin/qmake qmake [...]

  8. Daniel Martins

    Very useful post! Thanks!

  9. paraFoam reader for OpenFOAM 1.6 -- CFD Online Discussion Forums

    [...] about how to switch Qt version in Ubuntu but you have to install other version of Qt before that: http://jpnurmi.kapsi.fi/blog/2008/03…ion-in-ubuntu/ Follow the point 2.1 Qt to install other versions of Qt and do the switch… Let me know the [...]

  10. switch Qt version on Ubuntu | TurboLinux Blog

    [...] Here is a good tutorial show you how to switch Qt version on Ubuntu: It’s surprising how often people seem to ponder how to switch between different Qt/Qtopia versions when they have multiple versions of Qt/Qtopia installed. All what really matters is to have the right qmake in PATH at time. Even if it might not be that hard to write a shell script to do the switch, I decided to praise Debian’s update-alternatives tool a bit. Just look below how easy it is to manage multiple Qt/Qtopia installations with update-alternatives. [...]

  11. Rob Frohne

    You may need to do the same with /usr/bin/uic, at least that is what I found with Ubuntu 13.10 and Qt5.2 and Qt4.8.

  12. Rob Frohne

    And moc as well….

  13. J-P Nurmi

    Notice that this blog post was written quite a few years ago. These days the preferred way is to use qtchooser to switch between various Qt versions.

Leave a Reply