admin管理员组

文章数量:1122846

I have a new mac setup on apple silicon (M2). I've installed homebrew, nvm, and pnpm via the mac terminal (zsh) and added all to path, and have verified the installations by typing nvm -v command etc.

However, the terminal in VS Code gives me command not found error for all:

When I type echo $PATH the path variables are the same in both terminals. What can I do to allow vs code to find these installed packages?

I have a new mac setup on apple silicon (M2). I've installed homebrew, nvm, and pnpm via the mac terminal (zsh) and added all to path, and have verified the installations by typing nvm -v command etc.

However, the terminal in VS Code gives me command not found error for all:

When I type echo $PATH the path variables are the same in both terminals. What can I do to allow vs code to find these installed packages?

Share Improve this question asked Nov 22, 2024 at 19:33 chuckieDubchuckieDub 1,8359 gold badges28 silver badges47 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

1. Ensure VS Code Is Using Your Default Shell

  • Open VS Code.
  • Go to Settings (Cmd + , or File > Preferences > Settings).
  • Search for terminal.integrated.defaultProfile.osx (or terminal.integrated.shell.osx for older versions of VS Code).
  • Ensure the default profile is set to zsh:

{ "terminal.integrated.defaultProfile.osx": "zsh" }

If the setting does not exist, add the following to your settings.json file:

{ "terminal.integrated.defaultProfile.osx": "zsh" }

Restart the VS Code terminal to apply the changes.

2. Ensure Environment Variables Are Loaded

For macOS, environment variables defined in your shell configuration files (like .zshrc) may not be loaded in VS Code's integrated terminal. To fix this:

  1. Open your ~/.zshrc file:
nano ~/.zshrc
  1. Ensure you have the necessary exports for nvm, pnpm, and Homebrew:
export PATH="/opt/homebrew/bin:$PATH" # Homebrew
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh" # nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion"
export PATH="$HOME/.pnpm:$PATH" # pnpm
  1. Reload your shell configuration:
source ~/.zshrc
  1. Restart VS Code to load the updated environment.

3. Load the Shell Environment for GUI Applications

macOS doesn’t always load the same shell configuration for GUI applications like VS Code. To fix this:

  1. Create or edit the ~/.zprofile file:

    nano ~/.zprofile

  2. Add the following to load your .zshrc for GUI apps:

    if [ -f ~/.zshrc ]; then source ~/.zshrc fi

  3. Save the file and restart VS Code.

4. Check the VS Code Terminal Profile adf

  • Open the VS Code integrated terminal.

  • Type:

    echo $SHELL

Ensure it outputs /bin/zsh or the path to your zsh shell.

If it doesn’t, you may need to manually set the terminal profile. Go to the Command Palette (Cmd + Shift + P) and select Terminal: Select Default Profile. Choose zsh from the list.

  1. Verify the Fix
  • Open a new terminal in VS Code.

  • Run:

    nvm -v pnpm -v brew -v

These commands should now work without the command not found error.

If the problem persists, ensure your VS Code is fully updated, and check for any conflicting extensions or settings that might override terminal behavior. Let me know if you need further assistance!

Good Luck :)

本文标签: macosVS Code not finding any installed packages in terminal on mac installationStack Overflow