2

How can I run Gitk on WSL 2?

I already installed Gitk in WSL 2.

After I installed Gitk, I tried to run it but it failed with below error log:

application-specific initialization failed: no display name and no $DISPLAY environment variable
Error in startup script: no display name and no $DISPLAY environment variable
    while executing
"load /usr/lib/x86_64-linux-gnu/libtk8.6.so Tk"
    ("package ifneeded Tk 8.6.8" script)
    invoked from within
"package require Tk"
    (file "/usr/bin/gitk" line 10)

Could you help me how can run Gitk on WSL 2?

Lii
  • 11,553
  • 8
  • 64
  • 88
Kang
  • 75
  • 1
  • 9

2 Answers2

4

You can install and run gitk straight from ubuntu terminal on Windows 11, using apt install.

I've just followed the steps from the following post and it worked: https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps

I had to update not only the graphic driver but also the WSL.

Now, I can use either gitk or any linux app on Windows 11.

  • Good. thanks for your comment. According to link you mentioned it seems needs windows 11. After update to windows 11, I try and let you know. thanks – Kang Dec 15 '21 at 15:21
  • This answer is a good addition. :) But it would be even better it you included the gist of the solution in the answer text! Quite often I run across old answer with links to external pages that no longer exist. – Lii Feb 07 '22 at 07:41
  • Windows 11 / wsl2. it seems working fine. good. – Kang Mar 24 '22 at 13:02
1

If git is installed on windows, you can find the gitk.exe by typing the following command to windows cmd:

where gitk

you can reach this folder from your wsl by changing the path e.g. from

C:\Git\cmd\gitk.exe

to

/mnt/c/Git/cmd/gitk.exe

and by typing this path to the terminal of your linux distribution, gitk can be opened.

UPDATE:

If you want to open gitk by typing it, you can add the path to ~/.bashrc with the following command (needed only once):

echo 'alias gitk="/mnt/c/Git/cmd/gitk.exe"' >> ~/.bashrc

And after that you can open gitk like:

gitk
acgabor
  • 151
  • 8
  • Thanks for your help. gitk which I tried is installed in wsl, and it seems couldn't work because if gui limitation on wsl. And I tried with gitk which installed in windows and it works properly – Kang Oct 01 '21 at 10:29
  • @acabor Isn't this just gitk for windows? – leeand00 Sep 16 '22 at 22:56
  • 1
    @leeand00 gitk is installed on windows, but you can use it for you repos in wsl without limitation, and you have the gui this way. – acgabor Sep 18 '22 at 06:03
  • @acgabor I didn't think it would like the paths. – leeand00 Sep 18 '22 at 17:01