Hướng dẫn chạy file exe trên ubuntu

Wine is an open-source compatibility layer that allows you to run Windows applications on Unix-like operating systems such as Linux, FreeBSD, and macOS. Wine is an acronym for “Wine Is Not an Emulator”. It translates Windows system calls into equivalent POSIX calls used by Unix-based operating systems, allowing you to seamlessly integrate Windows programs into your desktop environment.

Installing Wine 5.0 on Ubuntu

The Wine packages are included in the default Ubuntu repositories and can be easily installed with the

sudo apt install wine64 wine32

1 package manager. This is the easiest way to install Wine on Ubuntu. However, the distro version may lag behind the latest release of Wine.

Most of the Windows applications are built for 32-bit architecture. The first step is to enable multiarch, which allows you to install both 64 and 32-bit packages on the machine:

sudo dpkg --add-architecture i386

sudo apt update

Install Wine:

sudo apt install wine64 wine32

Once the installation is complete, verify it by printing the wine version :

wine --version

The current version of Wine available in the Ubuntu 20.04 repositories is

sudo apt install wine64 wine32

2.

wine-5.0 (Ubuntu 5.0-3ubuntu1)

That’s it. Wine has been installed on your machine, and you can start using it.

Installing Wine 6.0 on Ubuntu

In this section, we will provide a step by step instructions about how to install Wine version 6 on Ubuntu 20.04.

If you are running a 64-bit Ubuntu system, enable the 32-bit architecture and update the packages list:

sudo dpkg --add-architecture i386 sudo apt update

Import the WineHQ repository’s GPG key:

wget -qO- https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add -

Add the WineHQ repository to your system:

sudo apt install software-properties-common sudo apt-add-repository "deb http://dl.winehq.org/wine-builds/ubuntu/ $(lsb_release -cs) main"

Install Wine by typing:

sudo apt install --install-recommends winehq-stable

This will install a bunch of packages. Once completed, verify the Wine installation by typing:

wine --version

At the time of writing this article, the latest major release of the Wine is version 6.0:

wine-6.0

Wine has been installed and ready to be used.

Configuring Wine

To start configuring Wine, run the

sudo apt install wine64 wine32

3 command in your terminal. The command installs Mono and Gecko and sets the Wine environment:

sudo apt install wine64 wine32

0

A dialog will appear asking whether you want to install the wine-mono package:

Click on the “Install” button, and the installation will start. Once done, a new dialog will appear, prompting you to install Gecko. Again click on the “Install” button.

When the installation is completed, the Wine configuration dialog will be shown. Here you can configure various Wine settings. The default settings should be sufficient in most cases. Once finished, close the dialog box.

Installing Notepad++ on Ubuntu

Now that Wine is installed and configured, we will explain how to install Windows applications on your Ubuntu.

In this tutorial, we’ll show you how to install Notepad++, one of the most popular Windows text editors. Launch your browser and download the installation file from the Notepad++ download page .

Once the download is complete, start the installation by right-clicking on the

sudo apt install wine64 wine32

4 file and selecting “Open With Wine Windows Program Loader”.

The installation wizard will start, select the language, and install Notepad++ in the same way you would install any application on a Windows computer.

Windows applications are installed in the

sudo apt install wine64 wine32

5 directory.

To start the Notepad++ editor navigate to the

sudo apt install wine64 wine32

6 directory and double click on the

sudo apt install wine64 wine32

7 file.

Các file thực thi của C/C++ sau khi compile trên Ubuntu chỉ chạy được trên Subsystem của Linux mà không chạy được trên Windows. Vậy muốn compile để thành file thực thi .exe trên Windows thì phải làm như thế nào ?

Rất đơn giản, bạn chỉ cần cài package có tên mingw-w64 như sau:

sudo apt-get install mingw-w64

Sau đó bạn có thể compile file C bằng lệnh như sau để tạo file .exe chạy trên Windows 32-bit:

i686-w64-mingw32-gcc -o main32.exe main.c

Với windows 64-bit, bạn dùng câu lệnh như sau:

x86_64-w64-mingw32-gcc -o main64.exe main.c

Tương tự với C++, bạn chỉ cần sửa gcc ở cuối thành g++ là được.

x86_64-w64-mingw32-g++ -o main64.exe main.cpp

Rất đơn giản đúng không. Lưu ý thêm rằng file .exe sau khi compile bằng cách này chỉ chạy trên môi trường Windows, không hoạt động trên Linux được. Nếu muốn chạy trên Linux bạn sẽ phải compile bằng gcc và g++ thông thường.