WINE tips: Giving each Windows application its own environment

I’m going to tell you about the useful WINEPREFIX environment variable, and, as a bonus, you’ll also find out how to install Office 2007 and IrfanView in WINE, plus how to configure file associations so that double-clicking on a .doc and/or .docx file will launch Word 2007 and open the file.

BACKGROUND

I’ll wager most WINE users have not heard of the WINEPREFIX environment variable and are installing all Windows applications in the ~/.wine/ directory tree. Until a couple of months ago that’s what I was doing too, but these days I install all Windows applications in WINE using this clever WINE feature.

Some WINE users will know that it is possible to use the ‘Add application…’ button on the Applications Settings page (the Applications tab) in the winecfg window to specify per-application libraries (DLLs) and graphics settings. For example, a user could use this feature in order to set an override of riched20 (native) for Office 2007 but not for, say, IrfanView. This WINE feature allows you to ‘ring fence’ applications from each other, avoiding the possibility of incompatible DLLs and graphics settings interfering with the working of another application. However, WINE still keeps directories and files for all the Windows applications in the ~/.wine/ directory tree.

The WINEPREFIX environment variable enables you to go a stage further. By using a WINEPREFIX you can install each Windows application (or a group of applications) in its own, completely separate environment. For example you could install IE7 in ~/.wine-ie7/, IrfanView in ~/.wine-irfanview/, World of Warcraft in ~/.wine-wow/, Word 2007 in ~/.wine-word2007/ and so on. You could even have different versions of the same Windows application installed simultaneously if you wanted. Not only does a WINEPREFIX allow you to keep an application’s DLLs and all settings completely separate from those of other applications, thus avoiding or preventing conflicts, it means that uninstalling a Windows application becomes as simple as:

$ rm -rf ~/.wine-visio5

You no longer need to hope that wine uninstaller supports the application, or that the application’s uninstaller will work if launched directly via WINE.

If winecfg’s Applications Settings allows you to partially isolate an individual application, the use of a WINEPREFIX allows you to put an application into solitary confinement!

HOW TO USE A WINEPREFIX

Let’s look at a couple of examples.

Installing Office 2007 (including SP2) with its own WINEPREFIX:

$ cd
$ export WINEPREFIX=$HOME/.wine-office2007
$ export WINEARCH="win32" # If WINE was built for 64-bit and 32-bit Windows and you have 32-bit Office 2007.
$ winecfg
$ cd .wine-office2007/drive_c/
$ wget http://www.kegel.com/wine/winetricks
$ chmod +x winetricks
$ cp ~/Downloads/X12-30107.exe . # Office 2007 installer from Microsoft.
$ cp ~/Downloads/office2007sp2-kb953195-fullfile-en-us.exe . # Office 2007 SP2.
$ cp ~/Downloads/officelp2007sp2-kb953195-fullfile-en-us.exe . # Office 2007 SP2 language pack.
$ wine X12-30107.exe # Install Office 2007. If you have an Office 2007 installation DVD then use "wine /path/to/setup.exe" instead.
$ winecfg # Set up riched20.dll as per instructions in Wine AppDB for Office 2007 (it must be "Native (Windows)").
$ ./winetricks msxml3 # Install msxml3 as per instructions in Wine AppDB for Office 2007, to stop SP2 crashing.
$ wine office2007sp2-kb953195-fullfile-en-us.exe # Install Office 2007 SP2.
$ wine officelp2007sp2-kb953195-fullfile-en-us.exe # Install Office 2007 SP2 language pack.
$ ./winetricks wsh56js # Install Windows Scripting Host for the thesaurus.
$ ./winetricks allfonts # Install all the TTF fonts.
$ winecfg # Set usp10 to 'native,builtin' for the equation toolbar in Word.
$ ./winetricks fontsmooth-rgb # Install font smoothing.

I have a KDE Kickoff menu entry Applications > Wine > Programs > Microsoft Office > Word containing the following command:

env WINEPREFIX="/home/fitzcarraldo/.wine-office2007" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix /home/fitzcarraldo/.wine-office2007/dosdevices/c:/users/fitzcarraldo/Start\ Menu/Programs/Microsoft\ Office/Microsoft\ Office\ Word\ 2007.lnk

The above command might look complicated, but WINE creates it automatically during the installation of Office 2007. WINE also creates similar Kickoff Menu entries for the other Office 2007 applications.

Having installed Office 2007 using a WINEPREFIX, if I wanted to launch e.g. Word from the command line I’d need to enter the following commands:

$ export WINEPREFIX=$HOME/.wine-office2007
$ export WINEARCH="win32"
$ wine $WINEPREFIX/drive_c/Program\ Files/Microsoft\ Office/Office12/WINWORD.EXE

instead of the following if I had not installed Office 2007 using a WINEPREFIX:

$ env WINEARCH="win32" wine $HOME/.wine/drive_c/Program\ Files/Microsoft\ Office/Office12/WINWORD.EXE

Installing IrfanView 4.27 with its own WINEPREFIX:

$ cd
$ export WINEPREFIX=$HOME/.wine-irfanview/
$ export WINEARCH="win32"
$ winecfg
$ cd .wine-irfanview/drive_c/
$ wget http://www.kegel.com/wine/winetricks
$ chmod +x winetricks
$ ./winetricks mfc42
$ cp ~/Downloads/iview427_setup.exe .
$ cp ~/Downloads/irfanview_plugins_427_setup.exe .
$ wine iview427_setup.exe
$ wine irfanview_plugins_427_setup.exe

I have a KDE Kickoff menu entry for IrfanView containing the following command:

env WINEPREFIX="/home/fitzcarraldo/.wine-irfanview" WINEARCH="win32" wine C:\\\\Program\\ Files\\\\IrfanView\\\\i_view32.exe

The above command might look complicated, but WINE creates it automatically during the installation of IrfanView.

By installing Office 2007 and IrfanView this way, I keep the DLLs installed by the IrfanView installer completely separate from the DLLs used by Office 2007.

File associations

If you find that Word opens a blank document (Document1) when you double-click on a .doc (or .docx) file then this is a file association issue. In KDE I simply selected Kickoff > System Settings > File Associations and changed all the associations for .doc and .docx from the following:

env WINEPREFIX="/home/fitzcarraldo/.wine-office2007" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix /home/fitzcarraldo/.wine-office2007/dosdevices/c:/users/fitzcarraldo/Start\ Menu/Programs/Microsoft\ Office/Microsoft\ Office\ Word\ 2007.lnk

to the following:

env WINEPREFIX="/home/fitzcarraldo/.wine-office2007" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

A different approach is needed if you want IrfanView to open image files when you double-click on them, and I’ll cover that in my next post.

About Fitzcarraldo
A Linux user with an interest in all things technical.

5 Responses to WINE tips: Giving each Windows application its own environment

  1. DHalens says:

    Are you sure all wine configs are in the prefix, even for a specific wineprefix?
    Some time ago I got a little script to remove all wine configs:
    rm -rf $HOME/.wine
    rm -f $HOME/.config/menus/applications-merged/wine*
    rm -rf $HOME/.local/share/applications/wine
    rm -f $HOME/.local/share/desktop-directories/wine*
    rm -f $HOME/.local/share/icons/????_*.xpm

    It’s just for a standard wine config, but it makes me wonder if some configs get into those other directories when using wineprefix.

    • Fitzcarraldo says:

      Thank you for your comment, DHalens.

      You’re right, not absolutely everything is in the WINEPREFIX directory tree. If we take IrfanView as an example, I have just checked and the following files exist outside $WINEPREFIX:

      $HOME/.local/share/icons/7BE4_i_view32.7.png
      $HOME/.local/share/icons/7BE4_i_view32.0.png
      $HOME/.local/share/applications/IrfanView.desktop
      $HOME/.local/share/applications/IrfanView Thumbnails.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/
      $HOME/.local/share/applications/wine/Programs/IrfanView/Uninstall IrfanView.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/IrfanView - Thumbnails.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/About IrfanView.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/Command line Options.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/Available Languages.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/Available PlugIns.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/What's New.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/IrfanView Help.desktop
      $HOME/.local/share/applications/wine/Programs/IrfanView/IrfanView 4.27.desktop
      $HOME/.local/share/desktop-directories/wine-Programs-IrfanView.directory
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-Command line Options.menu
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-About IrfanView.menu
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-IrfanView - Thumbnails.menu
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-Available PlugIns.menu
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-Uninstall IrfanView.menu
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-What's New.menu
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-Available Languages.menu
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-IrfanView 4.27.menu
      $HOME/.config/menus/applications-merged/wine-Programs-IrfanView-IrfanView Help.menu

      Mind you, the files that are not in the WINEPREFIX directory tree do not interact with, or affect in any way, the other Windows applications; they’re files such as Desktop Config files (analogous to shortcuts in Windows), freedesktop.org XML menu specification files, and icons. But you’re correct, if a user wanted to remove every last trace of an application, then (s)he would have to delete those files too.

  2. Fitzcarraldo says:

    Note that WINE 1.3.21 has a bug that stops Office 2007 SP2 from installing correctly. See WINEHQ Bugzilla bug report no. 27369. The bug is reported to be fixed in WINE 1.3.22.

  3. Pingback: A guided tour of my KDE 4.8.4 desktop (Part 1) « Fitzcarraldo's Blog

  4. Pingback: A guided tour of my KDE 4.8.4 desktop (Part 2) « Fitzcarraldo's Blog

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.