Search code examples
macosvisual-studio-code

"code ." is not working in on the command line for Visual Studio Code on OS X/Mac


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 an OS X terminal?

pwd

/Users/mona/nodejs/myExpressApp

code .

-bash: code: command not found


I ended up opening it from within Visual Code Studio by changing the workspace, but why won't that command code . part work?

Enter image description here


Solution

  • 1. Make sure you drag the Visual Studio Code application into the Applications folder

    Otherwise (as noted in the comments), you'll have to go through this process again after a reboot.

    For example, sometimes the VSCode application might be in your downloads folder, so make sure to move it out of there.


    2. Next, open Visual Studio Code

    Open the Command Palette via P and type shell command to find the Shell Command:

    Use the Uninstall 'code' command in the PATH command before the "Install 'code' command in PATH" command.

    ![Command Palette

    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: Visual Studio Code documentation)


    👉 Remember to Restart your machine afterwards

    Note: If you're running a build based off the OSS repository, you will need to run code-oss . (Dzeimsas Zvirblis' comment)


    EACCES: permission denied, unlink '/usr/local/bin/code'

    If you see this EACCES error, just run the "Uninstall 'code' command from PATH, then the 'install' it again, and you'll be all set!