Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running VS Code with the root privileges not work anymore in ubuntu linux

I am using visual studio code with this command in ubuntu linux Running VS Code with the root privileges (not recommended)

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

I always use this in command line because normal way visual studio code does not allow me to save my code updates. but today

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

this code does not work anymore when i try to run it in command line, it does not open visual studio code anymore. Giving click in vscode icon run normally but it does not allow me to save anything, it asked me retry as sudo, i do and it does not do nothing, i can not enter as sudo in this way. any suggestions on how to solve this issue? Thanks in advance

like image 797
Omar Elio Torres Castillo Avatar asked Mar 01 '23 13:03

Omar Elio Torres Castillo


1 Answers

best way (recommended):

just use this : sudo code "your-directory" --user-data-dir='.' --no-sandbox

for example to open /etc/nginx/nginx.conf, use:

sudo code /etc/nginx/nginx.conf --user-data-dir='.' --no-sandbox

vscode will create files where you open terminal because of : --user-data-dir='.'

another way (not recommended):

use sudo chmod -R 777

But it will give the full access of your project directory to all users on the machine

You can use chown on the project directory to own it only for yourself

cd /location
sudo chown your_username your_project_directory

Example:

let's say I have a directory called project1 in my /var/opt location and my user name is tom.

cd /var/opt
sudo chown tom project1
like image 71
sina Avatar answered Mar 04 '23 03:03

sina