无法在 Windows 上使用 sensu-install - gem 和 ruby​​ bin 不在系统路径中

无法在 Windows 上使用 sensu-install - gem 和 ruby​​ bin 不在系统路径中

尝试使用 sensu-install 时失败,因为它找不到 Gem/Ruby:

C:\opt\sensu\bin\sensu-install.bat -p sensu-plugins-windows:0.0.10

[SENSU-INSTALL] installing Sensu plugins ...
[SENSU-INSTALL] provided Sensu plugins: ["sensu-plugins-windows:0.0.10"]
[SENSU-INSTALL] compiled Sensu plugin gems: ["sensu-plugins-windows:0.0.10"]
[SENSU-INSTALL] determining if Sensu plugin gem 'sensu-plugins-windows:0.0.10' is already installed ...
[SENSU-INSTALL] gem list -i sensu-plugins-windows --version '0.0.10'
[SENSU-INSTALL] Sensu plugin gem 'sensu-plugins-windows' has not been installed
[SENSU-INSTALL] Sensu plugin gems to be installed: ["sensu-plugins-windows:0.0.10"]
[SENSU-INSTALL] installing Sensu plugin gem 'sensu-plugins-windows:0.0.10'
[SENSU-INSTALL] gem install sensu-plugins-windows --version '0.0.10' --no-ri --no-rdoc --verbose
[SENSU-INSTALL] failed to install Sensu plugin gem 'sensu-plugins-windows'
[SENSU-INSTALL] please take note of any failure messages above
[SENSU-INSTALL] make sure you have build tools installed (e.g. gcc)
[SENSU-INSTALL] trying to determine the Sensu plugin homepage for sensu-plugins-windows ...
'gem' is not recognized as an internal or external command,
operable program or batch file.

答案1

这是因为安装程序嵌入的 ruby​​ 和 gem 二进制文件C:\opt\sensu\embedded\bin\未添加到系统路径中。

可以通过在提升的 powershell 中运行以下命令来解决此问题,该命令将嵌入式 bin 目录添加到系统路径(持久):

$CurrentPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
$NewPath=$CurrentPath+’;C:\opt\sensu\embedded\bin\’
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH –Value $NewPath

您现在可以成功运行以下命令:

sensu-install -p sensu-plugins-windows:0.0.10

相关内容