Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open VS Code from command line on macOS?

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.

like image 738
Jim Avatar asked May 18 '26 18:05

Jim


2 Answers

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
like image 112
Paul Brennan Avatar answered May 22 '26 06:05

Paul Brennan


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.

like image 25
Kevin L Xu Avatar answered May 22 '26 07:05

Kevin L Xu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!