Ubuntu – ERROR: “Failed to save. Insufficient permissions.” When trying to save changes in VS Code

18.04permissions

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?

Best Answer

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
Related Question