When I type echo at here:

skyI@skyI-MP-i1640:~$ echo $XDG_RUNTIME_DIR    

It displays /run/user/1000, but when type echo here:

root@skyI-MP-i1640:/SLAM/DSO/dso# echo $XDG_RUNTIME_DIR

It does not display the /run/user/1000

Why and how can I solve it?


Each user has environment variables. XDG_RUNTIME_DIR is most likely not defined in root user's environment or is being overwritten as empty.

To fix it in your current shell (temporarily), login as root and type export XDG_RUNTIME_DIR="/run/user/1000"

To fix it every time root logs in you can define it in ~root/.profile. Just add the line export XDG_RUNTIME_DIR="/run/user/1000" at the bottom of the file. Then either source ~/.profile or logout & login again.

You can verify which environment variables are defined in the current shell, type env, or a specific one with env | grep XDG_RUNTIME_DIR

| improve this answer | |
  • While technically correct answer, I don't think it is what the requester needs, to have root using user directory. Question is why they need the variable and how it is set for regular user. – marosg Jun 4 at 6:11

it is solved. Sorry very simple answer. Why: They are different user. Different users have different .bashrc files. How: Just export like this, export XDG_RUNTIME_DIR="/run/user/1000"

| improve this answer | |

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.