KnitPkg for MetaTrader on Linux: Installation & Configuration Guide

KnitPkg for MetaTrader on Linux: Installation & Configuration Guide

18 March 2026, 12:57
Douglas Nascimento Rechia
0
24

KnitPkg for MetaTrader on Linux: Installation & Configuration Guide

KnitPkg is “Windows‑first” because MetaTrader itself is a Windows application, but as of v1.0.1 you can use KnitPkg on Linux by running the MetaEditor compiler through Wine. The  kp  CLI runs natively on Linux; Wine is only used when it’s time to compile your MQL4/MQL5 source code.

Below is a concise guide to get KnitPkg working on Linux: first installation, then configuration.

1. Installing KnitPkg on Linux (via Wine)

1.1. Prerequisites

Before installing KnitPkg on Linux, you need: 

  • Wine with a working MetaTrader 5 and/or MetaTrader 4 installed inside a Wine prefix
    (if you followed any standard “MetaTrader 5 on Linux via Wine” guide, you should already have this).
  • Git client installed and in your PATH.

1.2. Download the Linux binary

Download the latest Linux  kp  binary from the KnitPkg GitHub Releases page and place it in a folder you control, for example: 

mkdir -p ~/bin/knitpkg
mv /path/to/downloaded/kp ~/bin/knitpkg/
chmod +x ~/bin/knitpkg/kp

1.3. Set environment variables

Add these lines to your shell profile (e.g.  ~/.bashrc ,  ~/.zshrc ): 

export WINEPREFIX=/home/<user>/.mt5
export PATH="$PATH:/home/<user>/bin/knitpkg"
  • WINEPREFIX  must point to the Wine prefix where MetaTrader is installed.
  • Add the folder containing  kp  to  PATH  so you can call  kp  from any terminal.

Reload your shell:

source ~/.bashrc # or source ~/.zshrc

1.4. Verify the installation

Run:

kp --version

If the command runs and prints a version, your Linux KnitPkg binary is correctly installed.

You can also install via PyPI ( pip install knitpkg-mt ) on Linux, but the Wine + MetaEditor configuration still applies when compiling. 

2. Configuring KnitPkg on Linux

KnitPkg needs to know where your MetaEditor compiler is and where your MetaTrader data folder is. There are three configuration layers, in descending order of priority: 

  1. Environment variables
  2. Project‑specific config ( .knitpkg/config.yaml  inside your project)
  3. Global config ( ~/.knitpkg/config.yaml  in your home directory)

If something isn’t configured, KnitPkg falls back to default values and some auto‑detection, but for Linux+Wine it is better to configure things explicitly.

2.1. What must be configured

At minimum, configure: 

  • MQL5 compiler path (MetaEditor executable)
  • MQL5 data folder (MetaTrader 5 data folder, containing the  MQL5  directory / Standard Library)

The same applies for MQL4 if you are using MT4 projects.

On Linux, the defaults look like this (inside your Wine prefix): 

  • MQL5 compiler: ~/.mt5/drive_c/Program Files/MetaTrader 5/MetaEditor64.exe
  • MQL4 compiler: ~/.mt5/drive_c/Program Files/MetaTrader 5/metaeditor.exe
  • MQL5/MQL4 data folder (auto-detect if not set):
    • %USERPROFILE%/AppData/Roaming/MetaQuotes/Terminal
    • ~/.mt5/drive_c/Program Files/MetaTrader 5 (for MQL5)
    • ~/.mt5/drive_c/Program Files (x86)/MetaTrader 4 (for MQL4)

If your installation paths differ, you must override them.

Important: on Linux, always use POSIX paths (with forward slashes) when configuring KnitPkg, even for paths inside the Wine prefix. 

2.2. Project‑specific configuration ( kp config )

From inside a KnitPkg project directory, you can configure settings just for that project:

kp config --mql5-compiler-path "/home/<user>/.mt5/drive_c/Program Files/MetaTrader 5/MetaEditor64.exe"
kp config --mql5-data-folder-path "/home/<user>/.mt5/drive_c/Program Files/MetaTrader 5"

This creates/updates  .knitpkg/config.yaml  in your project with Linux paths pointing into the Wine prefix.

Use this when:

  • Different projects use different MetaTrader installations or variants.
  • You want project‑level isolation of configuration.

2.3. Global configuration ( kp globalconfig )

To configure defaults for all KnitPkg projects on your system, use:

kp globalconfig --mql5-compiler-path "/home/<user>/.mt5/drive_c/Program Files/MetaTrader 5/MetaEditor64.exe"
kp globalconfig --mql5-data-folder-path "/home/<user>/.mt5/drive_c/Program Files/MetaTrader 5"

This writes to  ~/.knitpkg/config.yaml  and will be used by any project unless overridden by environment variables or project config. 

kp globalconfig --mql4-compiler-path "/home/<user>/.mt4/drive_c/Program Files/MetaTrader 4/metaeditor.exe"
kp globalconfig --mql4-data-folder-path "/home/<user>/.mt4/drive_c/Program Files/MetaTrader 4"

2.4. Using environment variables (highest priority)

For temporary overrides, you can set environment variables:

export MQL5_COMPILER_PATH="/home/<user>/.mt5/drive_c/Program Files/MetaTrader 5/MetaEditor64.exe"
export MQL5_DATA_FOLDER_PATH="/home/<user>/.mt5/drive_c/Program Files/MetaTrader 5"

These environment variables override both project and global YAML configs. 

2.5. Telemetry

Optionally, you can configure telemetry:

# Enable telemetry globally
kp telemetry on

3. Summary

  • kp  now runs natively on Linux; Wine is only used to invoke MetaEditor for MQL compilation. 
  • Installation on Linux consists of:
    • Having Wine + MetaTrader installed in a Wine prefix.
    • Downloading the Linux  kp  binary, making it executable, and adding it to your  PATH .
    • Setting  WINEPREFIX  so KnitPkg knows which Wine environment to use.
  • Configuration is done through:
    • kp config  (per‑project)
    • kp globalconfig  (global defaults)
    • Environment variables (highest priority)

Once this is set up, you can work on your EA/indicator/utility projects on Linux almost exactly as on Windows:

kp init
kp install
kp compile