Preloader
Ubuntu
  • Estimated reading time: 1 Minute

How to run Visual Studio Code (VSCode) as Root in Ubuntu

"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 !

Share:
Carlos Delgado

Carlos Delgado

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.

Related articles
How to install the latest version of Git in Ubuntu 20.04
26 Aug, 2022
  • Estimated reading time: 1 Minute
How to install aapanel in Ubuntu 20.04
14 Aug, 2022
  • Estimated reading time: 1 Minute
How to install Prometheus Node Exporter on Ubuntu 20.04
27 Mar, 2022
  • Estimated reading time: 4 Minutes
How to extract the content of a tar.gz file in Ubuntu
16 Nov, 2021
  • Estimated reading time: 1 Minute
How to install Anaconda in Ubuntu 20.04
6 Nov, 2021
  • Estimated reading time: 3 Minutes
How to install Elasticsearch 7 in Ubuntu 20.04
29 Apr, 2021
  • Estimated reading time: 5 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.