Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSL - GEDIT Unable to init server: Could not connect: Connection refused [closed]

I'm using Ubuntu 18.04 as Windows Subsystem for Linux on my Windows 10 machine.
I've installed gedit without any errors or warnings.

But whenever I try to use the command gedit something (here something is a filename)
I get this error:

Unable to init server: Could not connect: Connection refused

(gedit:48): Gtk-WARNING **: 21:03:26.729: cannot open display:
like image 817
Ayush Basak Avatar asked Feb 18 '20 15:02

Ayush Basak


People also ask

What version of WSL am I running?

Check which version of WSL you are running You can list your installed Linux distributions and check the version of WSL each is set to by entering the command: wsl -l -v in PowerShell or Windows Command Prompt.


3 Answers

You need an X server to run graphical applications like gedit. I use VcXsrv or Xming on my Windows desktops, both are very small and easy to install, but there exist other servers like Cygwin/X.

Short instructions for VcXsrv/Xming:

  • download and install the Windows package
  • start XLaunch or Xming
  • export the DISPLAY variable in your WSL terminal and start gedit

    export DISPLAY=0:0
    gedit
    

I have the problem that some checkboxes in gedit's preferences are not working (dconf error, I don't care), but other than that the editor is usable.

Related:

  • What's the easiest way to run GUI apps on Windows Subsystem for Linux as of 2018? (askubuntu.com)
like image 127
Freddy Avatar answered Oct 17 '22 03:10

Freddy


To fix this problem

Step 1- Download and Install this Windows X Server https://sourceforge.net/projects/vcxsrv/

Step 2- Open XLaunch

Step 3- Select " Full screen " option

Step 4- Choose " Start no client " option

Step 5- Simply do next and finish

Step 6- Open terminal and type :

export DISPLAY=0:0                                 
gedit filename

In case your Linux machine is available with host name = 'hostname' and you'd want to ssh into the hostname and then open gedit then execute the following commands:

  1. Enable X11Forwarding in the ssh server
[hostname] $ vim /etc/ssh/sshd_config
             # and set X11Forwarding to yes
             X11Forwarding yes
  1. Set the DISPLAY env in the client terminal and then ssl with -X flag
export DISPLAY=0:0
ssh -X yourusername@hostname
                                 
[hostname] $ gedit filename
like image 42
Rishabh Ankit Avatar answered Oct 17 '22 03:10

Rishabh Ankit


It's probably because you are running it with root user. Run it as non-root user.

(If you don't know that if you are running it as root or not, enter the command below and if it returns 0, it means you are root and you must to login to non-root user: id -u)

(If you had run sudo su or something like that, It means you are root and you must use exit to go back!)

like image 1
Farbod Ahmadian Avatar answered Oct 17 '22 03:10

Farbod Ahmadian