9

I'm trying to figure out how to open the Mac version of VS Code from the terminal command line on my Mac and this question here says says to open the Command Pallete and issue either of these two commands:

shell command

install code

On my computer, both commands result in the response "No matching commands". Do I need to install any special extensions to get this to work? I'm running macOS 11.1 and VS Code 1.52.1.

Paul Brennan
  • 2,638
  • 4
  • 19
  • 26
Jim
  • 13,430
  • 26
  • 104
  • 155
  • After installation, launch VS Code. 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 – Christoph Jan 06 '21 at 21:38
  • Did you type `>shell command` or just `shell command`? According to the [VSC docs](https://code.visualstudio.com/docs/setup/mac) you should be able to just type that command. – jaykip Jan 06 '21 at 21:39

2 Answers2

10

https://code.visualstudio.com/docs/setup/mac has a discussion on how to do it.

Here is a quote from the document.

Instead of running the command above, you can manually add VS Code to your path, to do so run the following commands:

cat << EOF >> ~/.bash_profile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF

Start a new terminal to pick up your .bash_profile changes.

Note: The leading slash \ is required to prevent $PATH from expanding during the concatenation. Remove the leading slash if you want to run the export command directly in a terminal.

Note: Since zsh became the default shell in macOS Catalina, run the following commands to add VS Code to your path:

cat << EOF >> ~/.zprofile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF
Paul Brennan
  • 2,638
  • 4
  • 19
  • 26
  • 2
    Just a note to remind others to be sure you've actually been running VS Code from your Applications folder. :) I had been using Alfred to launch code and never paid attention to the fact that I never actually dragged it from my Downloads folder into Applications! So, of course, updating the path in my profile never made a difference. – Kenneth LeFebvre Jun 09 '23 at 13:40
1

Similar to above, except take out the '' in front of $PATH since that will cause the dollar sign to be treated like a normal dollar sign which will kill your system. You can simply add the line

export PATH="${PATH}:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

to your .zshrc if on Mac, which should effectively be what that command line does argument does if you take out the backslash.

Kevin L Xu
  • 158
  • 1
  • 2
  • 8