DEV Community

Tim Jones
Tim Jones

Posted on

Install Tmux on Git for Windows

Git for Windows is a special version of the MSYS2 with some customizations for better integration with Windows. In particular, in my experience, MSYS2 with Git does not work properly with Visual Studio Code, while Git for Windows works perfectly without any tweaking. However, Git for Windows version of MSYS2 does not include many of the other tools that are available in the standard MSYS2 installation, including Tmux. Nevertheless, we can install Tmux from the MSYS2 repositories with a little bit of effort.

Before making these changes, you should back up the Git for Windows installation directory, typically C:\Program Files\Git. You can simply copy this directory to another folder so that you have a backup in case something goes wrong in the update process.

Newer packages from the MSYS2 repositories <http://repo.msys2.org/msys/x86_64/> use Facebook's new Zstandard compression. These files have .zst file extension. To decompress them, you will need to download the zstd for Windows native Windows tool. Place the tool in a directory in your path, such as C:\Windows, since you will be running this tool from the Windows Command Prompt.

In addition, you will also need a tool capable of extracting tar archives. Fortunately, the Git for Windows installation includes the tar utility as one of the standard tools. Or your can use a GUI tool such as 7-Zip, which supports this archive type.

In addition to the Tmux executable itself, a few other files from the standard MSYS2 installation, particularly from the libevent library, are needed. So we will download several packages from the MSYS2 repositories. Since packages are updated frequently, the version numbers of the packages may change. Accordingly, in the list below, the version numbers are represented by x.y.z-p. You will need to replace these with the current/latest version number.

libevent-x.y.z-p-x86_64.pkg.tar.xz
tmux-x.y.z-p-x86_64.pkg.tar.zst
Enter fullscreen mode Exit fullscreen mode

To decompress the Zstandard compressed files, run the native Windows zstd tool (see above) at a Windows Command Prompt with the -d ("decompress") option:

zstd -d tmux-x.y.z-p-x86_64.pkg.tar.zst
Enter fullscreen mode Exit fullscreen mode

This will give you two tar archives that can then be extracted using the tar tool at the Git Bash prompt:

tar -xvf tmux-x.y.z-p-x86_64.pkg.tar
tar -Jxvf libevent-x.y.z-p-x86_64.pkg.tar.xz
Enter fullscreen mode Exit fullscreen mode

Since you have updated the files in the running Git Bash session, you will need to close the Git Bash prompt and open a new session. (Note: Tmux only works with the MinTTY version of Git Bash (git-bash.exe). If you usually use the native bash.exe or git-cmd.exe Git prompts, you'll get the error open terminal failed: not a terminal when trying to run Tmux.)

In the new Git Bash instance, launch a new Tmux session normally by running tmux. You should see the usual Tmux status bar and you'll be able to use the normal Tmux functions and keyboard shortcuts. Likewise, if you run Git Bash (again, the MinTTY version) in ConEmu, Tmux works just fine in it, as well.

Top comments (2)

Collapse
 
daxgames profile image
Dax T Games • Edited

This does not work for me.

I did everything as specified except I used the packages from repo.msys2.org/msys/i686/ since I only have the i686 versions of Git for Windows installed.

I created and used the below script based on this tutorial:

#!/usr/bin/env bash

[[ -f /tmp/zstd.zip ]] && rm -f /tmp/zstd.zip
[[ -d /tmp/zstd_Win32 ]] && rm -rf /tmp/zstd_Win32

ls -la /tmp |grep zst

curl -Lko /tmp/zstd.zip https://downloads.sourceforge.net/project/zstd-for-windows/zstd_Windows7%5BMinGW%5D%28static%29.zip?ts=gAAAAABjUce39lZxqUQ7zjZRoMyz3QNG7qlkwDNxopc6BWKtzWjATuGdYh09qrrX49lTZX1nJc7n3klJYnDq4Obuj2ZjLFgxlA%3D%3D&r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fzstd-for-windows%2Ffiles%2Fzstd_Windows7%255BMinGW%255D%2528static%2529.zip%2Fdownload
sleep 3

cd /tmp
ls /tmp/zstd.zip
unzip /tmp/zstd.zip
ls -la /tmp/zstd_Win32
sleep 3

curl -Lko /tmp/tmux-3.1-1-i686.pkg.tar.zst https://repo.msys2.org/msys/i686/tmux-3.1-1-i686.pkg.tar.zst
curl -Lko /tmp/libevent-2.1.11-2-i686.pkg.tar.xz https://repo.msys2.org/msys/i686/libevent-2.1.11-2-i686.pkg.tar.xz
/tmp/zstd_Win32/zstd.exe -df /tmp/tmux-3.1-1-i686.pkg.tar.zst

sleep 3
cd /
tar -xvf /tmp/tmux-3.1-1-i686.pkg.tar
tar -Jxvf /tmp/libevent-2.1.11-2-i686.pkg.tar.xz
Enter fullscreen mode Exit fullscreen mode

For some odd reason the sleep 3 lines are required because the script executes out of order without them. For example the unzip fails becaus ethe file is not there yet. I have no idea why other than I am running htis on my new REALLY fast machine.

Running tmux results in no output to screen and $?=127 in mintty

Collapse
 
daxgames profile image
Dax T Games • Edited

Got it to work by modifying my script to allow multi architecture with a default to x86_64:

#!/usr/bin/env bash

export tmux_ver=${1:-3.2.a-1}
export libevent_ver=${2:-2.1.12-2}
export arch=${3:-x86_64}

[[ -f /tmp/zstd.zip ]] && rm -f /tmp/zstd.zip
[[ -d /tmp/zstd_Win32 ]] && rm -rf /tmp/zstd_Win32

ls -la /tmp |grep zst

curl -Lko /tmp/zstd.zip https://downloads.sourceforge.net/project/zstd-for-windows/zstd_Windows7%5BMinGW%5D%28static%29.zip?ts=gAAAAABjUce39lZxqUQ7zjZRoMyz3QNG7qlkwDNxopc6BWKtzWjATuGdYh09qrrX49lTZX1nJc7n3klJYnDq4Obuj2ZjLFgxlA%3D%3D&r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fzstd-for-windows%2Ffiles%2Fzstd_Windows7%255BMinGW%255D%2528static%2529.zip%2Fdownload
sleep 3

cd /tmp
ls /tmp/zstd.zip
unzip /tmp/zstd.zip
ls -la /tmp/zstd_Win32
sleep 3

curl -Lko /tmp/tmux-${tmux_ver}-${arch}.pkg.tar.zst https://repo.msys2.org/msys/${arch}/tmux-${tmux_ver}-${arch}.pkg.tar.zst
curl -Lko /tmp/libevent-${libevent_ver}-${arch}.pkg.tar.zst https://repo.msys2.org/msys/${arch}/libevent-${libevent_ver}-${arch}.pkg.tar.zst
/tmp/zstd_Win32/zstd.exe -df /tmp/tmux-${tmux_ver}-${arch}.pkg.tar.zst
/tmp/zstd_Win32/zstd.exe -df /tmp/libevent-${libevent_ver}-${arch}.pkg.tar.zst

sleep 3
cd /

tar -xvf /tmp/tmux-${tmux_ver}-${arch}.pkg.tar
tar -xvf /tmp/libevent-${libevent_ver}-${arch}.pkg.tar
Enter fullscreen mode Exit fullscreen mode