It is very dangerous to run VScode as root (as it is any other application) however, should you absolutely need to:
You must specify the user data directory to use when running vs code:
sudo code --user-data-dir="~/.vscode-root"
Then from the window you can open your project folder
Again: This is not recommended. Have fun.
Update May 2018
For everyone asking why this isn't recommended, you clearly don't understand why sudo
even exists. From this AskUbuntu Question:
It defeats the security model that's been in place for years. Applications are meant to be run with non-administrative security (or as mere mortals) so you have to elevate their privileges to modify the underlying system. For example, you wouldn't want that recent crash of Rhythmbox to wipe out your entire /usr directory due to a bug. Or that vulnerability that was just posted in ProFTPD to allow an attacker to gain a ROOT shell.
It's just good practice on any operating system to run your applications on a user level and leave administrative tasks to the root user, and only on a per-need basis.
I'm not saying that you should never use VSCode as root(though its pretty easy to avoid doing) I'm saying you should be careful when you want to do so and know the risks.
The absolute best thing to do to is make a copy of a restricted file, edit it, and copy it back when you're absolutely sure it's finished.
Also for editing files to which your user does not have permissions, I would now recommend Talha Junaid's answer which asks for permissions every single time you want to save a file. The prompt for root access did not exist when I wrote this answer.
Watch this short video that explains each of the confinement models available in snaps, why --classic
exists and its use case.
Sources: The following documentation is taken from snapcraft.io: confinement policies.
strict
This is the default security policy applied to snaps. The snap has read and/or write rights only in its own install space and selected areas. It has access to libraries it bundles and/or provided by the core or ubuntu-core snap. Extended rights can be granted with interfaces, which are connected either at install time or by the user with the snap connect command. For example, the home interface will grant read rights in the user’s home.
Strict confinement gives you the following readable and/or writable paths:
- /snap/snapname/revision (read-only, snap install path)
- /var/snap/snapname/revision (read/write, per-revision data)
- /var/snap/snapname/common (read/write, common data)
- /home/$USER/snap/snapname/revision (read/write, per-revision user data)
- /home/$USER/snap/snapname/common (read/write, common user data)
See the list of environment variables for more details on what is visible to a strictly confined snap, as well as ways to access a shell within the confined space of a snap.
devmode
Developer mode, also known as devmode, uses the same security policies as strict confinement, but security denials are turned into warnings in /var/log/syslog
(see Debugging). This is useful when snapping an application, to discover which interfaces need to be declared. Snaps in developer mode can not be released into the stable and candidate store channels.
classic
A snap in classic confinement behaves as a traditionally packaged application, with full access to the system. As opposed to strict and devmode, what a classic snap sees as "/" is the host system’s "/" and not the core snap’s "/". Snaps using this fully open security policy are manually reviewed in the store and are only allowed on systems where snapd is installed on top of a traditional Linux distribution, as opposed to system booting from an Ubuntu Core image. They can be released in all store channels.
Best Answer
To install Visual Studio Code Ubuntu 18.04, ust press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:
Source.