I can add the "shell command install 'code' command". Testing it works, but if i close out of the VS Code or after a couple of hours of adding the command it doesn't work. Terminal says "zsh: command not found: code" and on VS when click on the "shell command install code command" has a "EACCES: permission denied, unlink 'usr/local/bin/code' " pop up. How should i go about this? I'm using a macbook 2020 if that matters
14 Answers
Uninstall the code command from PATH in VS Code and reinstall it.
Open the command palette in VS Code using cmd + shift + p
. Search "uninstall 'code'"
and select the first option to uninstall.
Once uninstalled, "install 'code'"
for installing.
That should fix it.

- 7
- 2

- 3,391
- 1
- 5
- 9
-
6I've had to do this again after a while. Sometimes it doesn't get fixed the first time. Sometimes I have to switch directories till it works. Not sure what the cause is – mfaani Apr 14 '22 at 19:05
-
it worked but what is the cause of this? – gaurav Aug 30 '23 at 10:53
This happened to me on Macbook Pro M1 Chip. Basically follow this:
Simply uninstall the code command from PATH in vscode and reinstalled. i.e open the command pallete, search "uninstall 'code'" and select the first option to uninstall. Do same for installing too. That should fix it.

- 3,921
- 2
- 25
- 30
-
5I'd suggest restarting Visual Studio code after each step. My VS Code editor didn't seem to update these optons properly until I restarted after each step – Bharat Mallapur May 13 '22 at 00:32
-
1
-
1
Try run:
sudo chown -R yourUsername /usr/local/bin

- 469
- 3
- 3
-
4
-
1
-
1Without running this, I wasn't able to uninstall the code command from PATH and re-install it as suggested by other answers. – mfonism Mar 28 '22 at 12:40
For Mac
I have run below steps in my terminal and it resolve my issue.
you can also Try:
- Open terminal.
sudo chown -R your_user_name /usr/local/bin
- Open visual studio code.
- use keybord
command
+shift
+p
- Type the bellow command.
install 'code'
Vs Code - For test go to terminal and run
code .

- 141
- 1
- 3
This command solves user just for copy paste.
sudo chown -R $USER /usr/local/bin

- 3,068
- 1
- 18
- 22
I've run into this a few times on before. Steps I took to that fixed it for me:
- open vs code and press
cmd + shift + p
to open the command palette - search for
uninstall 'code'
and press Enter - lastly, search for
install 'code'
and press Enter

- 111
- 2
- 4
I had the same issue on my mac. The problem is solved for me with that:
- Open VSCode
- Click on File then chose Close Window
- reopen VSCode (You have to see the welcome page) and
press cmd + shift + p
to open the command palette - search for
uninstall 'code'
and press Enter - search for
install 'code'
and press Enter
After that i can open from terminal with code .
from any library.

- 81
- 1
- 1
From a sample size of me and three friends, this is a common problem on M1 MacBooks and Mac Minis. Running the command:
sudo chown -R yourUsername /usr/local/bin
This resolved the VS issue for me and allowed me to install npm packages globally.

- 16,369
- 9
- 19
- 38

- 71
- 1
- 2
For macOS:
Try uninstalling and reinstalling. (command + shift + p) >shell Command: Uninstall 'code' command from Path
append the following to your ~/.bash_profile file (~/.zshrc in case you use zsh).
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}

- 31
- 1
-
Number 1. was enough. Why is the extra step needed? Is it for future-proofing? Thank you for this answer. – aghwotu Apr 28 '22 at 03:50
for any mac
users, you can try
sudo rm -f /usr/local/bin/code
That should help. It's important to note that you should be careful using sudo, since you can do a lot of damage in files and folders with it. But in the most dire instances, you should use it, similar to using any kind of --force
commands, you should not use it often.

- 53
- 7
For Mac
users the solution is:
sudo chown -R your_username /usr/local/bin

- 11
- 1
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 21 '23 at 15:49
I found a solution with these steps. When I applied these steps and even restarted my Mac, it worked.
1- Open downloads. Copy Vs Code. Paste in finder applications.
2- If you already installed 'code' on Vs Code. (Else jump to next step.) Use keyboard command + shift + p. Type and select; Shell command "uninstall".
3- Open terminal and type
sudo chown -R mac_user /usr/local/bin
4- Open Vs Code. Use keyboard command + shift + p. Type and select; Shell command "install".
5- Now open terminal and try
code .
I hope it will work for rest of not have solution.

- 11
- 2
I was getting same error to Install on Windows 11:
Just deleted folder C:\Users\my-username\AppData\Local\Programs\Microsoft VS Code\bin
Also removed VS Code from environment variables
Installed successfully!

- 21,707
- 9
- 87
- 85
I ran into this problem on Mac (none of the above suggested solutions worked for me). I solved it by:
deleting VSCode & re-installing it (I unzipped the folder onto my desktop & then physically moved the application (VSCode) into my Applications folder).
then I opened VSCode & used cmd + shift + p to select "Shell Command: Install 'code' command in PATH".
I closed the program, & tried code . in the terminal (it worked).
I restarted my computer & again ran code . in the terminal & it worked! Cheers!

- 23
- 3
-
This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/34710950) – Ram Chander Jul 25 '23 at 13:07
-
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? **If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient.** Can you kindly [edit] your answer to offer an explanation? – Jeremy Caney Jul 27 '23 at 00:24
-
I added my answer because I tried all of the above answers & they didn't work so I thought someone else might find my solution useful. I think the previous answers aren't sufficient because they did not work in my situation. – c3nturi0n2013 Jul 28 '23 at 14:25