Question or issue on macOS:
The command “code .” doesn’t work in this manual?
All the other steps before that worked. How can I call the Visual Studio Code in OSX terminal?
Monas-MacBook-Pro:myExpressApp mona$ pwd /Users/mona/nodejs/myExpressApp Monas-MacBook-Pro:myExpressApp mona$ code . -bash: code: command not found
EDIT: I ended up opening it from within Visual Code Studio by changing the workspace but I am wondering why that command “code .” won’t work?
How to solve this problem?
Solution no. 1:
1. Make sure you drag Visual Studio Code app into the -Applications- folder
Otherwise (as noted in the comments) you’ll have to go through this process again after reboot
2. Next, open Visual Studio Code
Open the Command Palette via (⇧⌘P) and type shell command
to find the Shell Command:
> Install ‘code’ command in PATH** command.
After executing the command, restart the terminal for the new $PATH
value to take effect. You’ll be able to simply type ‘code .’ in any
folder to start editing files in that folder. The “.” Simply means “current directory”
(Source: VS Code documentation)
NOTE: If you’re running a build based off the OSS repository… You will need to run code-oss .
@Dzeimsas Zvirblis
Solution no. 2:
If you want to add it permanently:
Add this to your ~/.bash_profile
, or to ~/.zshrc
if you are running MacOS Catalina
or later.
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
source: https://code.visualstudio.com/docs/setup/mac
Solution no. 3:
Open the ~/.bashrc
file using vi/vim
$ vi ~/.bashrc
Enter the following by pressing i
to insert:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
Save the file using :wq
Reflect the settings in ~/.bashrc
using the following command:
source ~/.bashrc
Solution no. 4:
For those of you that run ZShell with Iterm2, add this to your ~/.zshrc
file.
alias code="/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"
Solution no. 5:
https://code.visualstudio.com/Docs/setup
Tip: If you want to run VSCode from the terminal, append the following to your .bashrc file
code () { if [[ $# = 0 ]] then open -a "Visual Studio Code" else [[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}" open -a "Visual Studio Code" --args "$F" fi }
Then $ source ~/.bashrc
Solution no. 6:
On my MAC I got it working:
add to .bash_profile
code() { open -a Visual\ Studio\ Code.app $1 }
save and in terminal ‘source .bash_profile’
Then in terminal code index.html (or whatever) will open that file in VS Code.
Solution no. 7:
It was quite simple to follow the documentation to install ‘code’ to PATH but didn’t work.
I simply uninstalled it first, then installed it again.
Open the Command Palette (⇧⌘P)
Shell Command: Uninstall 'code' command in PATH command.
then install it again.
Shell Command: Install 'code' command in PATH command.
Don’t forget to restart your terminal to have the new PATH included.
Solution no. 8:
This work for me:
sudo ln -fs "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/
Solution no. 9:
Here are the steps which I followed to make it working on MAC:
Install “Shell” extension from VSCode:
Restart VSCode.
Press F1 when VSCode is opened.
Type “Shell” and select the following option:
Shell Command: Install ‘code’ command in PATH command
That will give you the following message:
Shell command ‘code’ successfully installed in PATH.
Running “which code” command will give you a proof the code command working now:
Solution no. 10:
I foolishly deleted my /usr/local/bin/code
symbolic link and did not know the correct path. A brew reinstall recreated it:
brew cask reinstall visual-studio-code
path turned out to be:
/usr/local/bin/code -> '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'