在 VS Code 中设置全局 $PATH 环境变量 [英] Set global $PATH environment variable in VS Code

查看:228
本文介绍了在 VS Code 中设置全局 $PATH 环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 ~/.bash_profile(在 Mac 上)中定义了一个自定义的 $PATH 环境变量,如下所示:

I'm defining a custom $PATH environment variable in my ~/.bash_profile (on a Mac), like so:

PATH="$HOME/.cargo/bin:$PATH:$HOME/bin"

然而,VS Code 当然不会运行我的 .bash_profile,所以它没有我的自定义路径.事实上,如果我切换开发者工具并检查process.env.PATH,它甚至似乎没有/usr/local/bin.

However, VS Code of course does not run my .bash_profile, so it does not have my custom paths. In fact, if I Toggle Developer Tools and check process.env.PATH, it doesn't even seem to have /usr/local/bin.

如何在 VS Code 中全局设置 $PATH 环境变量?

How do I globally set the $PATH environment variable in VS Code?

(我想全局设置它,而不是每个项目或每个任务,因为我要维护很多小包.)

(I want to set it globally, not per project or per task, since I'm maintaining a lot of small packages.)

推荐答案

如果你只需要在集成终端设置$PATH,可以使用VS Code的terminal.integrated.env.变量(在 1.15 版中添加).按 Cmd+Shift+P(或 Ctrl+Shift+P) 并搜索首选项:打开设置 (JSON)".然后将以下条目添加到设置文件中:

If you only need the $PATH to be set in the integrated terminal, you can use VS Code's terminal.integrated.env.<platform> variable (added in version 1.15). Press Cmd+Shift+P (or Ctrl+Shift+P) and search for "Preferences: Open Settings (JSON)". Then add the following entry to the settings file:

"terminal.integrated.env.osx": {
  "PATH": "...:/usr/bin:/bin:..."
}

(根据需要将 .osx 替换为 .linux.windows.)

(Replace .osx with .linux or .windows as needed.)

要查看系统的 $PATH,请在 Terminal.app 中输入 echo "$PATH",然后将其复制并粘贴到上面的设置片段中.

To see your system's $PATH, type echo "$PATH" in Terminal.app, and copy and paste it into the settings snippet above.

至于让 $PATH everwhere 在 VS Code 中可用,这样它就会由调用二进制文件的扩展程序使用,到目前为止我发现的唯一解决方法是:

As for having the $PATH available everwhere in VS Code, so that it will be used by extensions that call binaries, the only workaround I've found so far is this:

  1. 配置您的 shell(默认为 bash)以拥有您想要的 $PATH.例如,我的 ~/.bash_profile 有以下行:

  1. Configure your shell (bash by default) to have the $PATH you want. For example, my ~/.bash_profile has the following line:

PATH="$PATH:$HOME/bin"

  • 在 VS Code 中,按 ⇧⌘P 并输入 install 'code' command 如果您以前没有这样做过.

  • In VS Code, press ⇧⌘P and type install 'code' command if you haven't done so before.

    退出 VS Code.

    Quit VS Code.

    启动 VS Code 不是通过单击 Dock 或 Launchpad 中的图标,而是打开 Terminal.app 并输入 code.您新设置的路径将在 VS Code 中处于活动状态,直到您退出为止.

    Launch VS Code not by clicking the icon in the dock or in Launchpad, but by opening Terminal.app and typing code. Your newly set path will be active in VS Code until you quit it.

    如果 VS Code 重新启动,例如由于升级,$PATH 将重置为系统默认值.在这种情况下,退出 VS Code 并通过键入 code 重新启动它.

    If VS Code restarts, for example due to an upgrade, the $PATH will reset to the system default. In that case, quit VS Code and re-launch it by typing code.

    这篇关于在 VS Code 中设置全局 $PATH 环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆