0

When I type gedit filename.c:

Unable to init server: Could not connect: Connection refused

(gedit:76): Gtk-WARNING **: 17:57:16.278: cannot open display:

This is the error is displayed and those numbers shown is random everytime I execute it,

when ls -l ~/.config/gedit

is entered

ls: cannot access '/home/blank/.config/gedit': No such file or directory

is displayed

how to fix this?

Pilot6
  • 88,764
  • 91
  • 205
  • 313
Manish Kumar
  • 1
  • 1
  • 1
  • 2
  • That's because you used gedit with sudo – Pilot6 Feb 27 '19 at 12:37
  • Please [edit] your question and add output of `ls -l ~/.config/gedit` command. – Pilot6 Feb 27 '19 at 12:38
  • If the file is not owned by you, then `sudo -H gedit /path_to/filename.c`. If you're running in Wayland, either log back into your session using the "Ubuntu" option, or disable Wayland by editing `/etc/gdm3/custom.conf`. Report back to @heynnema – heynnema Feb 27 '19 at 15:37
  • @Pilot6 its updated ..hav a look – Manish Kumar Feb 28 '19 at 19:39
  • That is the problem. Now run it with sudo `sudo ls -l ~/.config/gedit` – Pilot6 Feb 28 '19 at 19:41
  • 1
    Possible duplicate of [Can't launch graphical apps from terminal after updating to 15.10](https://askubuntu.com/questions/768508/cant-launch-graphical-apps-from-terminal-after-updating-to-15-10) – Eric Carvalho Aug 06 '19 at 18:06

2 Answers2

1

Most likely the problem is that gedit config files are owned by root. This happens when you run sudo gedit in a terminal, that is wrong.

You can fix it by running

sudo chown -R $USER:$USER /home/$USER/.config/gedit

That will set correct ownership for these files.

Next time if you really need to run gedit with sudo (not recommended), do it this way:

sudo -H gedit
Pilot6
  • 88,764
  • 91
  • 205
  • 313
0

I has a similar issue when running Ubuntu on Windows with WSL2.

What it works for me was to to follow the instructions at https://wiki.ubuntu.com/WSL paragraph: Running Graphical Applications

Before I was using Xming, but gedit or any graphical visualization was not working. Then I tried with VcXsrv and after gedit worked!

https://sourceforge.net/projects/vcxsrv/