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?
This question is related to
macos
visual-studio-code
Otherwise (as noted in the comments) you'll have to go through this process again after reboot
Open the Command Palette via (??P) and type shell command
to find the Shell 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
Alternative to commandline Solution:
Recently I was playing with Services in Mac OS X. I added a service to a folder or file so that I can open that folder or file in Visual Studio Code. I think this could be an alternative to using 'code .' command if you are using the Finder app. Here are the steps:
Verify:
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'
had this problem in kali. deleted go and reinstalled and now it works perfectly.
:)
If you are using VS Code Insiders Build:
code-insiders .
With regular VS Code:
code .
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:
If you are on Windows and facing the same problem, have a look at this answer of @Inazense https://stackoverflow.com/a/52869803/4567504.
In Visual studio code I was not able to find “Shell Command: Install 'code' command in PATH command.” so I had to do this manually.
"C:\Users\Your_Username\AppData\Local\Programs\Microsoft VS Code\bin"
Now you are done! restart command prompt and try again
If you have trouble using the Command Palette solution, you can manually add VS Code to the $PATH
environment variable when your terminal starts:
cat << EOF >> ~/.bash_profile
# Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio
Code.app/Contents/Resources/app/bin"
EOF
I've tried install add code
command to PATH with Visual Studio Code's command pannel, but it's disabled after restart bash. if you want it be consolidated, just create a code
file in your PATH;
I create a code
file in usr/local/bin
and add
#!/usr/bin/env bash
function realpath() { python -c "import os,sys;print(os.path.realpath(sys.argv[1]))" "$0"; }
CONTENTS="/Applications/Visual Studio Code.app/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?
just replace this CONTENTS with your VS Code's installed path. and don't forget make it excuteable with chmod +x /usr/local/bin/code
EDIT: If this is happening on mint/ubuntu, it is likely because you installed vscode through the software manager. This will cause other problems during debugging. Instead install it using the .deb file on the vscode website.
If you really want to use the software manager, the solution below still works:
use find / -name code 2> /dev/null
to find the path to the visual studio bin file. It should end in /extra/vscode/bin/code
If you're using the mint software manager, you might only find paths with a ridiculously long name in the middle like this:
".../stable/7a22830d9e8fbbdc9627e43e072005eef66c14d2a4dd19992427ef4de060186a/..."
Just replace the long part with "/active/"
Once you have it, create a sym link:
ln -s path_you_found/extra/vscode/bin/code /usr/local/bin/code
If you don't have the rights, or only want it to be accessible for yourself, simply add this line to your .bashrc / .zshrc:
export PATH="$PATH:path_you_found/extra/vscode/bin/
Note that I removed the 'code' filename at the end
Steps to follow:-
Hope this steps will be helpful for you.
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.
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.
It might be possible that you have not installed the code in your system. So, please install it first. the command is here -
sudo snap install --classic code
Details are available is here
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
For code .
to work in OSX terminal append code as described here https://code.visualstudio.com/Docs/setup but instead of to .bashrc
, in OSX try .profile
which is loaded at terminal session start.
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"
Define the path of the Visual Studio in your ~/.bash_profile as follow
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
for the people who face the same problem in Windows - 10 please follow the below instructions,
https://github.com/Microsoft/vscode/issues/21957
It might be the case that, C:\Program Files (x86)\Microsoft VS Code\bin is missing in environment variables., kindly look into the following image for the solution, https://cloud.githubusercontent.com/assets/4076309/23575794/61d7cc2a-00b9-11e7-843b-bcd6f00f595f.png
For that to work there needs to be an executable named 'code' in your bash path, which some installers add for you, but this one apparently did not. The best way to do this could be to add a symlink to the visual studio code app in your /usr/local/bin
folder. You can do this by using a command like the following in your terminal.
ln -s "/Path/To/Visual Studio Code" "/usr/local/bin/code"
You will likely need to put sudo
in front of that to have the permissions for it to complete successfully.
For Mac OSX: There is a way to install Visual Studio Code through Brew-Cask.
Now run following command and it will install latest Visual Studio Code on your Mac.
$> brew cask install visual-studio-code
Above command should install Visual Studio Code and also set up the command-line calling of Visual Studio Code.
If above steps don't work then you can do it manually. By following Microsoft Visual Studio Code documentation given here.
This work for me:
sudo ln -fs "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/
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"
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
Source: Stackoverflow.com