How to install Visual Studio Code's `code` command permanently?

Solution 1:

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/

Solution 2:

If you're on Mac OS Catalina, you need to edit your .zprofile instead of .bash_profile.

  1. Edit your ~/.zprofile file: vim ~/.zprofile
  2. Add the following code in it, on it's own line: code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
  3. Save the file: :wq
  4. Re-run the updated file: source ~/.zprofile.
  5. Test that running code . opens your current folder in VS Code!