Skip to content

Instantly share code, notes, and snippets.

@jarek-przygodzki
Created June 8, 2018 18:20
Show Gist options
  • Save jarek-przygodzki/671e9922c8906fbb78194355acd2f449 to your computer and use it in GitHub Desktop.
Save jarek-przygodzki/671e9922c8906fbb78194355acd2f449 to your computer and use it in GitHub Desktop.
Add VS Code to PATH in macOS

To add code to PATH in macOS (in order to run code from the command line) we may to open up VS Code and open the 'Command Palette' with Shift+Command+P on Mac, or Shift+Control+P on Linux. In it, enter shell command and look for the Shell Command: Install 'code' command in PATH option. After doing this any new shell we open should be able to run code.

@aisnote
Copy link

aisnote commented Dec 22, 2022

but how about there is no admin privilege?

@mr-kollie
Copy link

Well that was of no help at all.

@weizhiqimail
Copy link

👍

@evilgeniuscreative
Copy link

Doesn't work. Period.

@beaudjango
Copy link

😎

@Alacrity01
Copy link

Alacrity01 commented Feb 12, 2024

I think this is what he meant to say:

  • In VS Code, open the command palette using Command + Shift + P (Mac) or Command + Control + P (Linux).
  • In the VS Code command palette, search/select the option that reads >Shell Command: Install 'code' command in Path
  • Click it (it should say something like "successfully added code to path").

Now try opening a folder in code in your terminal using code . (if you want to open the current directory in VS Code).

@Nelwhix
Copy link

Nelwhix commented Mar 16, 2024

If you get this error from vscode EACCES: permission denied, unlink '/usr/local/bin/code'

Run in a new shell

   sudo rm /usr/local/bin/code

Then run the Shell command from vscode again

@dhan2325
Copy link

If you get this error from vscode EACCES: permission denied, unlink '/usr/local/bin/code'

Run in a new shell

   sudo rm /usr/local/bin/code

Then run the Shell command from vscode again

I just found this issue on my Mac, this fix worked for me. Thanks!

@Blu3u
Copy link

Blu3u commented May 24, 2024

Thank you! Works like a charm 🎉

@helderlj
Copy link

helderlj commented Jun 7, 2024

If you get this error from vscode EACCES: permission denied, unlink '/usr/local/bin/code'

Run in a new shell

   sudo rm /usr/local/bin/code

Then run the Shell command from vscode again

That did it, tks sir

@ThiwankaS
Copy link

Yup it works!!! Thank you

@TheFriendlyCoder
Copy link

I recently discovered that if you have given VSCode "full disk access" permission on MacOS, then using the "add to shell" feature doesn't work properly. I'm not sure the exact reason for this, but for anyone hitting this issue in the future, try disabling "Visual Studio Code" under "Settings -> Privacy & Security -> Full Disk Access"

@Catalin-Ionut
Copy link

export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

Add this to .zprofile or .zshrc

@TheFriendlyCoder
Copy link

Another issue I found which can cause a very similar problem to happen is if you store your app package for VSCode in a temporary location / private folder (ie: in ~/Downloads for example) then the path to the application executable gets resolved to a transient temporary folder. The result of this is that after you shut down VSCode the symlink that is created in the /usr/local/bin folder breaks, because the transient folder gets removed post-shutdown.

To correct this particular issue, make sure to move your app package (ie: the "Visual Studio Code.app" file) to your applications folder (ie: /Applications) before launching the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment