简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM