劉明鑫
劉明鑫

Reputation: 1061

EACCES: permission denied in VS Code MAC

When I change any file, the system will deny me access. What's going on? How do I properly set permissions on Mac?

enter image description here

Upvotes: 100

Views: 292307

Answers (25)

bsingh013
bsingh013

Reputation: 491

Just adding current user with root permission should work

sudo chown -R $(whoami) .

Upvotes: 0

Shahmir Jadoon
Shahmir Jadoon

Reputation: 670

Go to the respective project folder, and type the following command to get your username:

$ whoami

After that copy your username that you get in the above command response and replace it with the username below. Also replace the directory-name with the project folder name:

$ sudo chown -R <username> <directory-name>

Upvotes: 3

Luiz Felipe Lopes
Luiz Felipe Lopes

Reputation: 1

This solution helped me:

  1. Open your terminal;
  2. Go to path that have your directory;
  3. Run the command below:

sudo chmod -R 777 <your-direcotory>

Upvotes: -2

James Zhan
James Zhan

Reputation: 1

I have another solution to this:

I changed my VS code permission for some stupid purposes (e.g. access to Mac font), and I cannot open it anymore via Application.

Below is what I did (suggested by GPT4):

sudo chown -R $(whoami) ~/Library/Application\ Support/Code

It worked for me

Upvotes: 0

ali sampson
ali sampson

Reputation: 467

This solution helped me. All you have to do is to;

1.Open your terminal in vscode and type:

sudo chown -R <username> 'path-to-your-project-folder' 

2.Hit enter and you're sorted.

Upvotes: 0

Nirvik Basnet
Nirvik Basnet

Reputation: 361

Easy fix:

  1. In VSC press cmd+shift+p
  2. Type 'uninstall code'
  3. Select 'uninstall code'
  4. Reinstall it again with cmd+shift+p and type 'install code' and select "install code".

Upvotes: 11

Balalen
Balalen

Reputation: 498

Right click on the folder go to Get Info sharing and permission on the bottom unlock the lock and press the 3 dots you will see a drop down apply to enclosed items make it happen, and try again

Upvotes: 1

Mohit Dabas
Mohit Dabas

Reputation: 2361

Try This

sudo chown -R <username> ~/Library/Application\ Support/Code 
sudo chown -R <username> ~/.vscode/extensions

Upvotes: 0

Black
Black

Reputation: 20382

The problem is, that you are probably trying to access a project which is owned by a another user e.g. the user which is not currently logged in.

You need to login as that user to work on the project.

Upvotes: 0

PariSh KhAn
PariSh KhAn

Reputation: 612

I Fix this on my M1 mac using this command.

sudo chown -R <userName> *

This command will allow ownership to the user for all files.

Upvotes: 0

jsnid00
jsnid00

Reputation: 686

I found a fix. I simply uninstalled the code command from PATH in vscode and reinstalled. i.e open the command pallete, search "uninstall 'code' command in PATH" and select the first option to uninstall. Then do the same to install it back "install 'code'...". Do same for installing too. That should fix it

https://github.com/microsoft/vscode/issues/129884

props to lazy-poet

Upvotes: 10

user1324418
user1324418

Reputation: 395

Uninstall the code command from PATH in vscode and reinstall it.

  1. Open the command pallete (command + shift + P), search "uninstall 'code'" and select the first option to uninstall.
  2. Open the command pallete (command + shift + P), search "install 'code'" and click "Install 'code' command in PATCH

Upvotes: 29

Zach Bellay
Zach Bellay

Reputation: 362

In my case, it turned out that the VSCode application was in the Downloads folder, and not in the Applications folder.

After I moved it to the Applications folder, I deleted the /usr/local/bin/code symlink. Then, I closed and re-opened VSCode, and hit Command+Shift+P and typed code which brought up Shell Command: Install 'code' command in PATH and successfully added code to the path!

Upvotes: 3

Arkadiusz Kałkus
Arkadiusz Kałkus

Reputation: 18443

In my case it was problems with mixed permissions within .git/objects directory. Some of them been my user, some - surprisingly - root.

This helped:

cd: .git/objects
sudo chown -R username:usergroup *

If mismatch with permissions occur not only within git objects but whole repo, chown command can be executed in upper directory.

Upvotes: 4

Persistent Plants
Persistent Plants

Reputation: 829

None of the above solutions solved this issue for me, here's what finally worked:

System Preferences > Security and Privacy > Privacy (tab) > (scroll down to) Files and Folders > Select Desktop Folder

enter image description here

Upvotes: 21

Nilbog
Nilbog

Reputation: 422

I managed to fix this on Mac while running this in Terminal

sudo chown -R $(whoami) /Users/$(whoami)/.vscode

hope this helps someone

Upvotes: 28

ricardoaleixoo
ricardoaleixoo

Reputation: 29

This is the solution for me.

Open the Terminal and enter this command:

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

This is for Ubuntu 16.04.

Upvotes: 2

Ahmad Sadiq
Ahmad Sadiq

Reputation: 172

Go to your project, double click on the app.js file and select 'Get info'. There will be an option of 'Sharing & Permission'. From there you can change access permissions for other users.

enter image description here

Upvotes: 3

janekkkk
janekkkk

Reputation: 366

If you want to fix permissions for the current user use sudo chown -R $(whoami) ~/.vscode/.

  • $(whoami) is a variable with the current user that's logged in
  • ~ is a shorthand for the home directory of the current user

Upvotes: 5

user11595769
user11595769

Reputation:

Here's the solution: You probably tried to save the file to "Macintosh Hd" which is the default place when you click on "Save as", so you can't just save a file to the computer inside itself, you have got to choose a directory, like you can save it to /Desktop or /users/your_username/... something like that. But saving to "Macintosh Hd" will always be unsuccessful.

Upvotes: 0

Mogician Ha
Mogician Ha

Reputation: 85

Go to your terminal and input the command:

sudo "/Applications/Visual Studio Code.app/Contents/MacOS/Electron" ~/.bash_profile

It works for me.

However, according to the answers on the websites, it is not recommended to get super user permission when you launch the vs code. I am new to vs code as well so I don't know the right method to get permission.

Besides, on my mac, you will get only permission once when you type in the command and after you exit your vs code, you will not possess the permission if you open the vs code again. I am still working on it and try to fix.

But this answer should fix your problem.

Upvotes: 0

Ahmed Adewale
Ahmed Adewale

Reputation: 3143

cd to the project directory and run cd .. to move back one folder run sudo chmod -R 777 <project_dir_name> it works for me vscode never asked me for password when saving my file again.

Upvotes: 13

Arun Tom
Arun Tom

Reputation: 889

First, take note of the current permissions of all files and folders by issuing the command:

ls -lR <project_dir_name> > old_permissions.txt

which will save the output of the command ls -l <project_dir_name> to the file old_permissions.txt in the current directory.

If you have no idea of how permissions work and what the results of the previous command represent, please, have a look at https://ss64.com/bash/syntax-permissions.html and https://ss64.com/bash/chmod.html.

At this point, to modify any of the files under <project_dir_name>, you can give full permission to all subfolders and files recursively by issuing the command:

sudo chmod -R 777 <project_dir_name>

Note that you're responsible for the changes your perform!

After having saved the updates, you can reset the previous permission settings of the folders by looking at the old permissions saved in the file old_permissions.txt. You should set the permissions manually (unless you create e.g. a script to do it automatically using the info saved in old_permissions.txt).

Note: it's probably a better idea to only modify the permissions of the specific files that you want to modify (and not of the whole folder).

Upvotes: 56

Nikhita Raghunath
Nikhita Raghunath

Reputation: 4464

It is generally not a good idea to run VS Code as sudo. Instead change the permission for the directory.

You can change the ownership of the directory so that you can open it without needing root privileges.

$ sudo chown -R <user-name> <directory-name>

Upvotes: 190

Karan Alangat
Karan Alangat

Reputation: 2224

I had a similar issue. I had error when I tried to create a new component. I just navigated to the path displayed in Finder. For me it was ProjectFolder/src/. So I did right click on "src" folder and selected "Get Info". In that change access to "Read&Write" for my user account. Thats it !!!

As you are trying to update a file, try to change access permission for that file (ie. app.component.css). If it didn't work try to change access for "app" folder.

Note: Changing the access of parent/super-parent folder won't work. So change the exact folder's access preferences.

Upvotes: 2

Related Questions