Starting VSCode in Linux:

while as a root user:

  1. Installed the VSCode (forgot exact way - but was easy, just googled).
  2. when trying to start VSCode by using code ., got this error:
You are trying to start Visual Studio Code as a super user which isn't recommended. 
If this was intended, please add the argument `--no-sandbox` and specify an alternate user data directory using the `--user-data-dir` argument.

Tried different ways to run it:

  1. created a new user anant(some 1 liner to create the new user) and switched to it (su anant).

Googled everything.

None of it worked.

Used chatGPT with prompt:

How to start Visual Studio code NOT as a super user.

Got the following response:

To start Visual Studio Code (VSCode) as a regular user and not as a super user, you can follow these steps:

Open your terminal or command prompt.

Navigate to the directory where the VSCode executable is located. The location can vary depending on your operating system and installation method. Common locations include:

Windows: C:\Program Files\Microsoft VS Code\ macOS: /Applications/Visual Studio Code.app/Contents/Resources/app/bin/ Linux: /usr/share/code/ If you installed VSCode using a package manager, you can usually run the code command directly from the terminal without specifying the full path.

Once you are in the correct directory, run the code command with the –user-data-dir flag followed by the path to a directory where you want to store your user-specific data and configurations. For example:

./code --user-data-dir=~/vscode-data This command starts VSCode with the specified user data directory.

Note: Make sure to replace ~/vscode-data with the actual path to the directory where you want to store your VSCode user data.

VSCode should now start as a regular user without requiring superuser privileges. You can use it normally and install extensions, modify settings, and work on your projects.

By specifying a custom user data directory, you ensure that your extensions, settings, and other user-specific data are separate from the system-wide installation. This approach allows you to run VSCode as a regular user and avoid potential permission issues.

Followed above:

  • Indeed the VSCode was installed at /usr/share/code
  • its bin dir had the code.sh
  • Tried in the /usr/share/code to do ./code --user-data-dir=~/annvscode-data

This failed with error:

–no-sandbox flag notused

Atleast something worked!

Added the --no-sandbox flag

gives this error (but atleast the applicatoin starts!! for the first time!! (seems like app was starting and faced network issue, maybe due to office internet)):

–no-sandbox flag used