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