How to run Visual Studio Code as root without --user-data-dir argument?
I can run VS code with following command
sudo code ~/.zshrc --user-data-dir="/root/.vscode"
But it annoyed me.
How do I config it so I can run VScode as root without --user-data-dir argument?
You can try with adding the -H
parameter for sudo:
-H, --set-home
Request that the security policy set the HOME environment
variable to the home directory specified by the target user's
password database entry. Depending on the policy, this may be
the default behavior.
That would be:
sudo -H code ~/.zshrc
This way, ~/.zshrc
would still refer to your calling users .zshrc
, but the home directory for code
would appear as the one for root (~root
).
Although what you are doing (running vs code as root) sounds wrong. Maybe you have your reasons, but in general it is not recommended to run programs as root.