-1

I was following a link to add Xampp server in "Show all application" section where normally we can see all GUI apps installed.

But it's different in case of Xampp. We have to do things manually. So I opened the file using:

pkexec nano /usr/share/applications/xampp-control-panel.desktop

Because I can't use this:

007@bond:~$ pkexec gedit /usr/share/applications/xampp-control-panel.desktop

Unable to init server: Could not connect: Connection refused

(org.gnome.gedit:17349): Gtk-WARNING **: 20:18:25.529: cannot open display: 

Anyhow when I tried putting to check whether Xampp run pkexec, I got this error:

007@bond:~$ Exec=pkexec /opt/lampp/manager-linux-x64.run
bash: /opt/lampp/manager-linux-x64.run: Permission denied

My questions/doubt:

  1. Isn't pkexec is a replacement of gksudo? Then why don't it works sometimes?
  • 1
    Why did you use Exec=pkexec there but not in the other commands? – muru Aug 13 '19 at 14:58
  • @muru u didn't read the link i mentioned in the question, did u? See the "accepted answer". In "usr/share/applications/xampp-control-panel.desktop" we need to add exec = gksudo < > . Since gksudo has been removed with pkexec. So, i tried using it. – Pranav Aug 13 '19 at 15:06
  • Nowhere in the link do they tell you to run Exec=pkexec in a terminal. – muru Aug 13 '19 at 15:07
  • @muru no. Both question and answer is when gksudo existed. pkexec doesn't work when i also use it without exec. Exec is just a small way to run something. – Pranav Aug 13 '19 at 15:12
  • 1
    No, it's not. It's a line from a .desktop file. The command run on the terminal shouldn't have the Exec=, like in your earlier two attempts. – muru Aug 13 '19 at 15:13
3

The pkexec command is used in a GUI to open a file that only root normally can write to. For instance, if you want to use gedit to open the file, you should use pkexec on it.

However, your paste of the error you had trying to open it with pkexec shows that you're most probably not in a GUI, since the $DISPLAY variable is empty (according to that message):

Gtk-WARNING **: 20:18:25.529: cannot open display: 

It's possible that you're in a GUI, but that somehow you lost the $DISPLAY setting. For example, if you're ssh'd into another machine, you need to use ssh's X11 forwarding options (-X or perhaps -Y) to forward the GUI display so clients on that machine can display on yours.

If you don't mind using a terminal text mode editor, such as nano, then simply use sudo directly:

$ sudo nano /usr/share/applications/xampp-control-panel.desktop

Or, even better, use sudoedit (or equivalent sudo -e) with the path of the file you want to edit, if you have configured your editor correctly, in which case sudo will create a copy of the file that you can edit, then open your editor as your unprivileged user and finally copy the modified contents back to the original location, overwriting the file you wanted to modify.

| improve this answer | |
  • @fibranden I know that sudo nano know. Problem is why pkexec becomes useless for me. Yes, I am a GUI laptop (Ubuntu 19.04) user. How can I solve this "display" warning that shows up in the terminal? – Pranav Aug 13 '19 at 15:17
  • If you type echo "$DISPLAY", does it show you something, or just an empty line? If an empty line, then there's your problem... – filbranden Aug 13 '19 at 15:26
  • It shows me this: ":0" A colon and a zero. What this means? – Pranav Aug 13 '19 at 15:28
  • That looks correct. I assume you'll be able to use gedit by itself to open the file (only you won't be able to save it.) There seems to be something wrong when you call pkexec then... But it's hard to tell from that message alone, it really looks as the $DISPLAY is being lost, but hard to tell where... Keep digging see if you find anything. – filbranden Aug 13 '19 at 15:30
  • 1
    I would prefer sudoedit instead of sudo nano – Kulfy Aug 13 '19 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.