ERROR: "Failed to save. Insufficient permissions." When trying to save changes in VS Code
I am using VS Code (1.30.02) and Ubuntu 18.04. When I try to save any changes in VS Code, I get this error:
Failed to save 'SomeFileName.js': Insufficient permissions. Select 'Retry as Sudo' to retry as superuser.
I have the same issue if I try to create a new file:
Permission denied writing to file (file:///path/to/new/file/newfile.js)
I am making these changes or trying to create new files in my own directory. I am new to Ubuntu, so I apologize if this is a stupid question, but I am not sure what I am doing wrong. What is the issue?
It looks like you somehow changed file ownerships in your home directory.
One way to correct this without endangering your system is
sudo chown -c -R $USER:$USER $HOME
Explanation:
-
chown
: change the ownership of files/directories -
-c
: report all changes -
-R
: do this recursively (for all files/directories beneath the given one) -
$USER:$USER
: change the owner and the group that owns the the entry to the user that issues the command (sudo
preserves the values) -
$HOME
: do this with your home directory
You can test those environment variables with the following commands
echo $USER
sudo echo $USER
echo $HOME
sudo echo $HOME
If you want to make changes and create new files with VsCode without changing the whole home directory ownerships.
You can just change the ownerships of your project folder.
sudo chown -c -R $USER:$USER (project folder)