Linux Applications

How to Install and Configure Wine in Ubuntu

This article will explain how to install and configure Wine in Ubuntu to run Windows compatible apps.

About Wine

Wine is a free and open source software that allows you to run Microsoft Windows compatible programs and games on Linux, macOS, and Android (experimental support). Wine has been in development for over two decades and application compatibility has improved considerably since its first release. It is often misinterpreted as an emulator. However, it is just a compatibility layer that converts Windows API calls to POSIX calls in real time, providing nearly identical performance as Windows (and in some cases even better). Wine stands for “Wine Is Not an Emulator”.

Installing Wine in Ubuntu

Wine packages are included in Ubuntu repositories by default. However they are not always up to date and on par with the latest releases. So it is recommended to install wine packages from the official Ubuntu PPA provided by the wine team. To do so, run the following commands in succession:

For Ubuntu 19.10:

$ sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ eoan main'
$ sudo apt update

For Ubuntu 18.04:

$ sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main'
$ sudo apt update

You can now install wine stable, developer or staging builds by running one of the commands below:

$ sudo apt install winehq-stable
$ sudo apt install winehq-devel
$ sudo apt install winehq-staging

Differences Between Different Wine Builds

The official wine repository provides three different builds, “stable”, “devel” and “staging”. Stable builds, as the name suggests, provide the latest stable version of wine while developer builds are in-development, cutting edge versions. Staging builds contain many experimental patches intended to test some features or fix compatibility issues. There is no guarantee that all of these patches will be included in the stable branch in the future.

WINEARCH

After installing wine, you can use the WINEARCH environment variable to define correct architecture for wine prefixes. By default, all wine apps are installed in a 64-bit environment. However, you can change the behavior by using WINEARCH environment variable in the following format:

  • WINEARCH=win32
  • WINEARCH=win64

Note that you need to use WINEARCH only once when creating a new prefix (explained below).

Understanding the WINEPREFIX Feature

WINEPREFIX is a pretty useful feature of wine where you can isolate and containerize windows applications, system libraries, and configuration files by confining them in a single directory. You can create as many prefixes as you want and each of them will be treated separately.

Many Linux users prefer to create a separate prefix for each of the Windows apps or games they want to install and run using wine. Often installation of a Windows app requires installing third party libraries and toolkits. Using separate prefixes for apps ensures better compatibility, fewer conflicts, and cleaner filesystem. You can create a new WINEPREFIX by using an environment variable in the following format:

$ WINEPREFIX=/path/to/prefix wine /path/to/file.exe

The command above will run “file.exe” using prefix path specified in the WINEPREFIX variable. If the path doesn’t exist, a new directory will be created automatically. If you omit WINEPREFIX variable, all apps will be installed in the default prefix located at hidden “wine” folder in your home directory (~/.wine).

Using WINEARCH and WINEPREFIX Together to Run a Windows App

You can combine WINEARCH with a custom WINEPREFIX to correctly specify architecture for a prefix.

$ WINEARCH=win32 WINEPREFIX=/path/to/prefix wine /path/to/file.exe

Filesystem Layout of a Wine Prefix

All wine prefixes, default or custom, include many files and folders that represent a typical Windows file system where all system libraries and apps are installed in “C” drive. These prefixes contain a number of libraries that are part of Wine open source project. The screenshot below will give you some idea about directory layout:

If you run a “.exe” or “.msi” installer using wine, the app will be installed in “Program Files” under “drive_c” (unless you provide a custom path). So in order to run a “.exe” file after installation has finished, you may have to go to the application folder in “Program Files” directory to launch the app.

Winecfg

You can change many settings and behaviour of a wine prefix by running the “winecfg” command. Some of the settings include display settings, external drive settings and audio settings.

Run one of the following commands to launch winecfg:

$ winecfg
$ WINEPREFIX=/path/to/prefix winecfg

Wine Control Panel

“Wine control Panel” is another useful utility included in wine that allows you to configure gamepads and tweak other useful options.

You can run winecontrol using one of the commands below:

$ wine control
$ WINEPREFIX=/path/to/prefix wine control

Winetricks

Winetricks is a handy tool shipped with wine, that allows you to install many third party libraries and apps from a GUI interface. It also allows you to change settings for a wineprefix and do maintenance tasks. While the GUI of winetricks is not as intuitive as other typical GTK and Qt Linux apps, it gets the job done.

To install winetricks in Ubuntu, run the command below:

$ sudo apt install winetricks

You can now run winetricks using one of the following commands:

$ winetricks
$ WINEPREFIX=/path/to/prefix winetricks

Winetricks also has a nice command line interface, you can know more about it by running the command below:

$ winetricks --help

Running “Lnk” Files in Wine

So far the examples above have explained how to run “.exe” files using Wine. However, some apps in Windows come with “.lnk” files which are nothing but shortcuts to executable binaries with some extra customizations and parameters.

To run “.lnk” files using wine, you have to run a command using one of the following formats:

$ wine start /path/to/file.lnk
$ WINEPREFIX=/path/to/prefix wine start /path/to/file.lnk

Running “Bat” files in Wine

Bat files are bash-like script files that can be run in Windows using command prompt or interpreter. Wine includes a “wineconsole” utility that can be used to launch command prompt and run “.bat” files. You can run “.bat” files using one of the following commands:

$ wineconsole /path/to/file.bat
$ WINEPREFIX=/path/to/prefix wineconsole /path/to/file.bat

The command interpreter shown above supports all major commands compatible with Windows.

Conclusion

Wine is capable of running numerous Windows apps in Linux, bridging the gap between two platforms. While some popular apps are not yet working with Wine, overall compatibility has improved considerably. In the recent past, Valve announced the “Proton” compatibility layer for running Windows games on Linux using Steam. Proton is based on Wine and comes with additional features, quality of life updates and compatibility patches.

About the author

Nitesh Kumar

I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.