Windows Apps on Linux with Wine

Tutorials – Wine

Article from Issue 194/2017
Author(s):

Convert your home/office/friends to be completely Microsoft-free with our tips and tricks.

While we all love to shout from the rooftops about the awesomeness of GNU, Linux, Free Software, and open standards, we also have to deal with the awkward reality that Windows is still pretty dominant on the desktop and has an enormous software base. Sure, FOSS equivalents for proprietary Windows apps exist (and new ones are popping up every week), but certain tools simply don't exist elsewhere, and people or companies that want to migrate away from Windows toward Linux might still need to run the occasional Windows program.

Of course, dual-booting is one way to solve this problem, but it still means you need a Windows license and a chunk of your hard drive devoted to it. If you want to be as Microsoft-free as possible but still need to run the occasional Windows app or game, you have another option: Wine. This open source project provides a software compatibility layer that lets you run many Windows programs on Linux – albeit with varying degrees of reliability and compatibility. Wine is a mature piece of software, having been in development since 1993, but given the vast complexity (and closed nature) of Microsoft's operating systems, it has trouble running some apps.

Wine famously means "Wine Is Not an Emulator" – which seems silly for something that ostensibly emulates Windows. But really, Wine intercepts system calls from programs and reworks them for their Linux equivalents. This means that you can often get surprisingly good performance from Wine, because it's not doing the job of emulating a whole CPU; indeed, I've heard from readers who say that some Windows apps run faster on Linux+Wine rather than native Windows itself!

Over the next few pages, I'll show you how to install and configure Wine, exploring some of its workings and a few tricks to save time. If you've got some old Windows games you'd like to dig out, now's the time! Or indeed, even if you're fully Microsoft-free, it's worth knowing the essentials of using Wine in case you need to help a friend or school/club/charity/company transition to Linux while still having some Windows compatibility.

First Steps

The first thing you'll need to do is install Wine from your distro's package repositories. Almost every mainstream distro has Wine available, so it should only take a

sudo apt-get install wine

or equivalent to get it installed. If you're fairly new to Linux and not yet fully au fait with the command line, you should also be able to find Wine by searching in your graphical package manager, but bear in mind that you'll be using the command line for a few things in this tutorial.

Note that some distros may include older versions of Wine; if you have problems running a particular Windows program, it may be worth updating to the very latest version of Wine because compatibility improves with every release. On the download page [1], you'll find binary packages for various distros. The WineHQ wiki also shows you how to build it from source [2]. Just make sure you remove any Wine binary packages before compiling the source code, to avoid conflicts on your system.

Once you have Wine installed, it's a good idea to test it with a small and fairly simple program to make sure it's working correctly before moving on to more complicated apps. Here, I'll use a Minesweeper clone called MineZ. To begin, download the latest version (minez0.1.2.zip at the time of writing) [3], extract the archive, and run the game:

unzip minez0.1.2.zip
cd minez
wine minez.exe

If this is the first time you're using Wine, a new configuration will be created – more on that in a moment – but all being well, the MineZ game will appear on your screen and should be playable (Figure 1). There you have it, a native Windows app running flawlessly on Linux!

Figure 1: Once we have this small and simple Minesweeper clone running, we know Wine is installed properly.

Working with Installers

Very few Windows programs are available as simple standalone .exe files, however; most of them require some kind of installation. For this example, you'll be using the Windows version of AbiWord [4]. Grab the abiword-setup-2.8.6.exe file (or a newer version if available) and run it in Wine:

wine abiword-setup-2.8.6.exe

This time, a familiar installation wizard will pop up, asking a few questions. To skip through them, just keep tapping Enter. Once the files have been copied over, choose not to run AbiWord immediately, and then the installer window closes. OK, what now? How do you run the freshly installed AbiWord from here?

Well, the first time you ran Wine, it created a minimal installation of a Windows-like operating system (including libraries and tools) inside .wine/drive_c/ in your home directory. Have a look inside there, and notice the famous Program Files and Windows directories. After doing a bit of searching, you will find that the AbiWord executable has been installed inside Program Files (x86)/AbiWord/bin, so you can run it like so:

wine "Program Files (x86)"/AbiWord/bin/AbiWord.exe

Note the use of quotation marks here to deal with the spaces and brackets, which are usually annoying to handle at the command line. Et voilà, AbiWord appears as expected, and you could create a desktop or menu shortcut to run the above command (including the full path of /home/user/.wine/drive_c) to save you always having to type it.

Bear in mind that because Wine is not an emulator, programs running inside it are not sandboxed away from the rest of the system. They can access files in your home directory like any other native Linux app. So you still have to be aware of security issues, even if a lot of viruses and malware wouldn't have the same effect as on a native Windows system.

You can see this yourself: in AbiWord, go to File | Open and navigate to My Computer. You'll see that the C: drive is mapped to .wine/drive_c/ in your home directory, whereas Z: is mapped to the root (/) directory (Figure 2). In many cases this is useful, because you can access other files on your filesystem without having to copy them into a dedicated place, but if you want to run something potentially risky, it's better to do it in a virtual machine.

Figure 2: By default, Wine maps the virtual Z: drive to your root filesystem – so bear in mind that Windows apps can still see your Linux files!

A last note on installers: Many Windows programs are now supplied in .msi format, for which you'll need the msiexec utility (included with Wine) followed by the /i parameter and the package filename to install:

msiexec /i <program>.msi

You can then locate the program inside the drive_c directory.

Advanced Features

At this point, you can start trying to install your favorite old Windows programs and games, but chances are that you'll have some problems. Wine is far from perfect (see the "Chasing a Moving Target" box for reasons why), but it's also highly configurable; you have so many settings to tweak, to (one hopes!) coax some programs into running.

Chasing a Moving Target

Given that Wine has been in development for 23 years, you might wonder why it still has issues running some Windows programs. After all, that must be enough time to recreate the Windows API, right? Especially when the project has benefited from commercial backing. Well, there are two main reasons why compatibility is still not perfect.

First, a lot of the Windows internals are not documented – at least, not publically. Details for many API calls are thin on the ground, and Microsoft hasn't been particularly forthcoming with them. Yes, there have been some source code leaks of Windows versions, but Wine developers don't want to go anywhere near them for legal reasons. If they reimplement something in Wine after seeing original Windows code, Microsoft's lawyers could spring into action. So "clean room" implementations are required, accomplished by studying the behavior of Windows.

Second, Windows is a moving target. If the Wine team had set a goal of supporting, say, Windows 98 with maximum compatibility, they might have reached that by now, and the open source world would have a fully FOSS Windows 98 alternative. However, many other Wine users want support for newer APIs and Windows features, so the Wine team has had to keep chasing this ever-changing goal. It's tough work, so massive kudos to the developers for doing it.

Enter winecfg to start Wine's graphical setup tool, and look at the tabs along the top (Figure 3). Of special interest for compatibility is Applications, which should contain a list of programs you've installed in Wine. (If not, click Add Application and locate them.) In the drop-down list at the bottom, you can choose which version of Windows should be imitated for each app.

Figure 3: The winecfg tool provides a fairly user-friendly front end for fine-tuning your Wine installations.

Another tab worth looking at is Libraries. Wine ships with a number of DLL files that provide much of the functionality of Windows' own libraries, but with some limitations and bugs. In many cases, you can improve compatibility by using real Windows DLLs – provided you have a legitimate copy of Windows, of course.

To see where Wine places these libraries, go into ~/.wine/drive_c/windows, and then the system32 or syswow64 directories. Enter ls at the command line, and you'll see lots of DLLs created by the Wine team. If you want to use a native library, it's best to place the native DLL alongside the EXE file of the program you want to run. Then, in the winecfg tool, you can choose to override Wine's version with the native version.

Other tabs to look at include Drives (where you can change the mapping of C: and Z:), Graphics, and Audio. Now, say you've done all the tweaking possible to make a program work in your Wine installation, but you want to install another app that requires very different compatibility, library override, and graphics settings. Do you have to poke around inside Winecfg each time you switch apps?

Fortunately not. Wine includes a feature called "prefixes" (or "bottles") that let you maintain multiple Wine installations simultaneously. It's a bit like having separate versions of Windows on your machine. If you've downloaded a program called CoolApp that you want to install and run in its own Wine installation, you can create a new prefix by setting an environment variable like so:

env WINEPREFIX=~/.wine_coolapp wine coolapp.exe

This creates a new folder in your home directory called .wine_coolapp with all the Windows directory structure, DLLs, and tools as before, but it's completely separate from your other Wine installation. To use programs inside it (or indeed the Winecfg tool), just specify the environment variable before the command, as above. These separate Wine installations can take up a fair amount of disk space, however, so don't forget to remove them when you no longer need an app or game!

A similar environment variable is WINEARCH, which chooses whether to run in 64-bit or 32-bit mode. If you're running a 64-bit distro but having trouble with some Windows apps in Wine, try using env WINEARCH=win32 at the start of your commands.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Gaming with Wine

    Although Linux has made great strides in gaming, users sometimes miss the games that are only available on Windows. Linux provides a way to solve this problem with Wine, the Windows "not an emulator."

  • Wine

    The Wine compatibility layer lets Linux users run Windows programs. Unfortunately, configuring Wine is anything but trivial, and it helps if you enjoy experimenting.

  • New Wine with More Functions

    A new version of Wine, the program loader that lets Windows run on Linux, has been released.

  • Practical Wine

    More and more Windows applications run on Linux thanks to Wine. If you spend a little time on configuration and troubleshooting, you won’t be stuck in Windows – even with applications that no one dreamed would run on Linux.

  • Wine

    Users who move from Windows to Linux often miss some of their favorite programs and games. Wouldn't it be practical to run Windows applications on the free Linux operating system? Time for a little taste of Wine.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News