Apple - How to install Visual Studio Code's `code` command permanently?
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/
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!
OK, it seems "ln" command not work for me (I use this command set up sublime text). But I got an another solution.
edit your ~/.bash_profile file.
add the following code in it.
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
after save. do not forget to run
source ~/.bash_profile
.Finished and test it, type
code