Learn how to execute Visual Studio Code as root in your Ubuntu system.

"Opening Visual Studio Code as Root is an horrible idea", that's basically what everyone says on the web. But, how the hell are you supposed to work directly on a project directory where you can't change file/directory permissions (which is the real horrible idea) and you need to edit a lot of files quickly? I mean, i'm not doing sudo nano file on every single file just for a panic sake advice. 

When you try to run VSCode as root (with super user permissions) with the following command in the terminal:

sudo code

The application will throw the following error message:

It is recommended to start vscode as a normal user. To run as root, you must specify an alternate user data directory with the --user-data-dir argument.

Solution

In order to open Visual Studio Code as root user, you can simply run the following command in the terminal:

sudo code --user-data-dir="~/.vscode-root"

This will allow you to edit any file on the system as you are running it as root. It's worth to say that you need to be careful, as you have all the permissions, so just try to don't delete anything accidentally, would you?.

Happy coding !


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors