How to fix code command for opening VSCode in Terminal for OSX
If the code . command is not working in your terminal, it’s likely that Visual Studio Code’s command-line tool isn’t properly installed or linked. Here’s how you can fix it:
Verify VSCode Installation
Open Finder.
Navigate to /Applications and confirm that Visual Studio Code is listed there.
Install the Command-Line Tool
Make sure that VSCode is properly installed.
Open VSCode.
Press CMD + Shift + P to open the Command Palette.
Type Shell Command: Install ‘code’ command in PATH and select it.
This should create a symbolic link in /usr/local/bin pointing to the VS Code binary.
Manually Create the Symlink (if Command-Line Tool installation fails)
Open Terminal
Run this command to create the symlink:
sudo ln -s "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/code
Enter your password when prompted.
Add /usr/local/bin to Your PATH (if not already)
If the command still isn’t found, it could be that /usr/local/bin isn’t in your PATH.
Open your .zshrc (or .bashrc, etc.)
Add the following line, and then save:
export PATH="$PATH:/usr/local/bin"
Reload your Terminal
source ~/.zshrc
Verify Installation
Check if the code command is now available:
Should return /usr/local/bin/code