5

I just followed the top-voted answer here and successfully installed Visual Studio Code's code command in my terminal.

However, the code command fails to launch Visual Studio Code every time after I restart my MacBook Pro.

~ code
zsh: command not found: code

Is it possible to install code permanently so that I don't have to install it every time I turn on my MacBook Pro?

~ where code
/usr/local/bin/code

~ ls -l /usr/local/bin/code
lrwxr-xr-x  1 myName  admin  167 Aug  5 13:41 /usr/local/bin/code -> /private/var/folders/bh/525lnbns1213cx2651s97my00000gp/T/AppTranslocation/EA379FC4-05D2-4739-BE49-1D8870E47B8A/d/Visual Studio Code.app/Contents/Resources/app/bin/code

I also find out that the folder EA379FC4-05D2-4739-BE49-1D8870E47B8A get deleted after I restart my laptop.

This is the reason that I cannot run code after the laptop is restarted.

Why is code installed in a temporary folder?

My MacBook Pro's version is macOS Sierra version 10.12.6

10

Looks like your whole Visual Studio got installed in a temporary folder.

  • Remove the current link with sudo rm /usr/local/bin/code
  • Start Visual Studio from within /Applications
  • Reinstall code as described in https://stackoverflow.com/a/29971430:

    Now open the Command Palette (F1 or ⇧⌘P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command.

If it still doesn't work you can also link manually by running

sudo ln -fs "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/
  • 1
    Thank you. The solution works. I found that my Visual Studio Code.app was in Downloads folder. The code command is installed in /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code after I dragged it to Applications folder. – Brian Aug 5 '17 at 6:43
  • Moving VSCode from /Downloads to /Applications and re-running the VSCode pallette command did the trick for me too. – Lauren Aug 8 '18 at 21:54
  • Same problem here... I had it in my /Downloads folder. Thanks! – Lucas Saldanha Apr 15 at 2:44
1

OK, it seems "ln" command not work for me (I use this command set up sublime text). But I got an another solution.

  1. edit your ~/.bash_profile file.

  2. add the following code in it. code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}

  3. after save. do not forget to run source ~/.bash_profile.

  4. Finished and test it, type code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .