0
solitude@Solitude:~/Desktop$ sudo gedit ~/.bashrc
error: XDG_RUNTIME_DIR not set in the environment.

(gedit:12631): Gtk-WARNING **: cannot open display: 
Zanna
  • 70,465
  • 1
    You can't run X11 apps without an X11 display for them to connect to. You might want the vi command instead of gedit there. – dobey Mar 28 '18 at 15:37
  • Related https://elementaryos.stackexchange.com/questions/468/why-can-i-not-open-gedit-with-pkexec – Sergey Ponomarev Nov 04 '22 at 12:29

1 Answers1

2

You should never use normal sudo to start graphical applications as root. For a complete explanation of this read the answers to this question: Why should users never use normal sudo to start graphical applications?.

Nautilus Admin (nautilus-admin) is a simple Python extension for the Nautilus file manager that adds some administrative actions to the right-click menu:

  • Open as Administrator: opens a folder in a new Nautilus window running with administrator (root) privileges.
  • Edit as Administrator: opens a file in a Gedit window running with administrator (root) privileges.

To install Nautilus Admin in all currently supported versions of Ubuntu open the terminal and type:

sudo apt install nautilus-admin

An alternative way of editing the same file is to use the system's default text editor program that is designed to run from the terminal without needing any other graphical environment.

sudoedit path/to/file
karel
  • 114,770