144

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

Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68
Marian I
  • 1,441
  • 2
  • 4
  • 3

14 Answers14

324

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.

Sudam
  • 7
  • 2
Sabrina Tolmer
  • 3,391
  • 1
  • 5
  • 9
  • 6
    I'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
64

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.

Found this solution on github

Ash Singh
  • 3,921
  • 2
  • 25
  • 30
45

Try run:

sudo chown -R yourUsername /usr/local/bin
GChaves
  • 469
  • 3
  • 3
14

For Mac I have run below steps in my terminal and it resolve my issue. you can also Try:

  1. Open terminal.
sudo chown -R your_user_name /usr/local/bin
  1. Open visual studio code.
  2. use keybord command + shift + p
  3. Type the bellow command. install 'code' Vs Code
  4. For test go to terminal and run code .
Sujeet Singh
  • 141
  • 1
  • 3
12

This command solves user just for copy paste.

sudo chown -R $USER /usr/local/bin

uruapanmexicansong
  • 3,068
  • 1
  • 18
  • 22
11

I've run into this a few times on before. Steps I took to that fixed it for me:

  1. open vs code and press cmd + shift + p to open the command palette
  2. search for uninstall 'code' and press Enter
  3. lastly, search for install 'code' and press Enter
Stephen Petrey
  • 111
  • 2
  • 4
8

I had the same issue on my mac. The problem is solved for me with that:

  1. Open VSCode
  2. Click on File then chose Close Window
  3. reopen VSCode (You have to see the welcome page) and press cmd + shift + p to open the command palette
  4. search for uninstall 'code' and press Enter
  5. search for install 'code' and press Enter

After that i can open from terminal with code . from any library.

kaskoo
  • 81
  • 1
  • 1
7

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.

benson23
  • 16,369
  • 9
  • 19
  • 38
3

For macOS:

  1. Try uninstalling and reinstalling. (command + shift + p) >shell Command: Uninstall 'code' command from Path

  2. 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 $* ;}
    
  • 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
1

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.

orangey
  • 53
  • 7
1

For Mac users the solution is:

sudo chown -R your_username /usr/local/bin
  • 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
1

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.

ofarukc
  • 11
  • 2
0

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!

Ali Adravi
  • 21,707
  • 9
  • 87
  • 85
0

I ran into this problem on Mac (none of the above suggested solutions worked for me). I solved it by:

  1. deleting VSCode & re-installing it (I unzipped the folder onto my desktop & then physically moved the application (VSCode) into my Applications folder).

  2. then I opened VSCode & used cmd + shift + p to select "Shell Command: Install 'code' command in PATH".

  3. I closed the program, & tried code . in the terminal (it worked).

  4. I restarted my computer & again ran code . in the terminal & it worked! Cheers!

  • 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