Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 命令提示中的系统变量路径不同_Ruby_Windows_Cmd_Registry_Environment Variables - Fatal编程技术网

Ruby 命令提示中的系统变量路径不同

Ruby 命令提示中的系统变量路径不同,ruby,windows,cmd,registry,environment-variables,Ruby,Windows,Cmd,Registry,Environment Variables,我见过各种各样的问题,但我已经为此奋斗了一整天,所以请给我一些帮助:) 简短的故事:我在系统变量面板和cmd中有不同的路径变量。无法运行exe文件 长话短说:我正在尝试安装Ruby。尝试使用不同的版本,但问题是相同的:我更新了我的路径值,Ruby就在那里但是从cmd使用时,无法识别rubyecho%PATH%给出的值与环境变量面板中的值不同 第一个附件:环境变量面板: 用户变量的值: C:\Users\morifey\nvmw\nodejs\v0.10.36;C:\ProgramData\Or

我见过各种各样的问题,但我已经为此奋斗了一整天,所以请给我一些帮助:)

简短的故事:我在系统变量面板和cmd中有不同的路径变量。无法运行exe文件

长话短说:我正在尝试安装Ruby。尝试使用不同的版本,但问题是相同的:我更新了我的路径值,Ruby就在那里但是从cmd使用时,无法识别ruby
echo%PATH%
给出的值与环境变量面板中的值不同

第一个附件:环境变量面板:

用户变量的值:
C:\Users\morifey\nvmw\nodejs\v0.10.36;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;“C:\Program Files\Intel\WiFi\bin\”;“C:\Program Files\Common Files\Intel\WirelessCommon\”;“C:\ProgramFiles(x86)\Skype\Phone\”;“C:\ProgramFiles(x86)\Intel\OpenCL SDK\3.0\bin\x86”;“C:\ProgramFiles(x86)\Intel\OpenCL SDK\3.0\bin\x64”;“C:\ProgramFiles\nodejs\”;C:\wamp\bin\php\php5.5.12;C:\ProgramData\Composer安装程序\bin;“C:\ProgramFiles\TortoiseGit\bin”;“C:\ProgramFiles(x86)\Git\cmd”;“C:\Program Files\Intel\WiFi\bin\”;“C:\Program Files\Common Files\Intel\WirelessCommon\”;C:\Users\morifey\AppData\Roaming\npm;C:\Ruby21\bin

系统变量的值:
C:\Ruby21\bin;C:\Users\morifey\nvmw\nodejs\v0.10.36;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;“C:\Program Files\Intel\WiFi\bin\”;“C:\Program Files\Common Files\Intel\WirelessCommon\”;“C:\ProgramFiles(x86)\Skype\Phone\”;“C:\ProgramFiles(x86)\Intel\OpenCL SDK\3.0\bin\x86”;“C:\ProgramFiles(x86)\Intel\OpenCL SDK\3.0\bin\x64”;“C:\ProgramFiles\nodejs\”;C:\wamp\bin\php\php5.5.12;C:\ProgramData\Composer安装程序\bin;“C:\ProgramFiles\TortoiseGit\bin”;“C:\ProgramFiles(x86)\Git\cmd”;“C:\Program Files\Intel\WiFi\bin\”;“C:\Program Files\Common Files\Intel\WirelessCommon\”;“C:\Users\morifey\AppData\Roaming\npm”;%SystemRoot%\system32;%SystemRoot%

我将它们与HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment进行比较-它们都是相同的

但是我运行cmd并使用
echo%PATH%
。结果:
C:\Users\morifey\nvmw\nodejs\v0.10.36;C:\ProgramData\Oracle\Java\javapath;C:\Win
dows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPow
erShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Int
el\WirelessCommon\;C:\ProgramFiles(x86)\Skype\Phone\;C:\ProgramFiles(x86)\In
电话\OpenCLSDK\3.0\bin\x86;C:\ProgramFiles(x86)\Intel\OpenCLSDK\3.0\bin\x64;C
:\Program Files\nodejs\;C:\wamp\bin\php\php5.5.12;C:\ProgramData\Composer安装程序\b
在里面C:\ProgramFiles\TortoiseGit\bin;C:\ProgramFiles(x86)\Git\cmd;C:\Fi程序
les\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\用户
\莫里菲\AppData\Roaming\npm

Ruby不见了以管理员身份运行和不以管理员身份运行都是一样的(实际上我只有一个管理员用户)

我尝试过设置路径(通过set或setx),更改注册表和环境变量,但没有任何效果。我尝试在有空格的路径中添加引号(
),没有区别

除非我以管理员身份运行cmd并使用
setx路径“%PATH%”;C:\Ruby21\bin“
!然后,
echo%PATH%
返回real(更新)路径,我可以在此cmd中运行
ruby
。如果我关闭它,然后作为管理员再次打开它-更改将丢失

请告诉我如何处理这个问题?我只需要运行Ruby:)

Windows7Ultimate,服务包1,64位; 下载的Ruby(来自)-Ruby 2.2.2(32和64位),Ruby 2.1.6(32和64位)-结果都是一样的


编辑:在一些人说我不需要引号之后,我已经删除了它们,并完全按照@eryksun所说的内容放置。结果如下:

C:\Users\morifee>echo%PATH%
C:\Users\morifey\nvmw\nodejs\v0.10.36;C:\ProgramData\Oracle\Java\javapath;C:\Win
dows\system32;C:\Windows;C:\Windows\system32\Wbem;C:\Windows\system32\WindowsPow
erShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Int
el\WirelessCommon\;C:\Program Files(x86)\Skype\Phone\;C:\Program Files(x86)\In
电话\OpenCL SDK\3.0\bin\x86;C:\Program Files(x86)\Intel\OpenCL SDK\3.0\bin\x64;C
:\Program Files\nodejs\;C:\wamp\bin\php\php5.5.12;C:\ProgramData\Composer Setup\b
在;C:\Program Files\TortoiseGit\bin;C:\Program Files(x86)\Git\cmd;C:\Program Fi
les\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users
\莫里菲\AppData\Roaming\npm

很奇怪,有些输入在重复:

C:\Program Files\Intel\WiFi\bin\;
C:\Program Files\Intel\WiFi\bin\;
C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\ProgramFiles(x86)\Intel\OpenCLSDK\3.0\bin\x86;
C:\ProgramFiles(x86)\Intel\OpenCLSDK\3.0\bin\x64;
尽管它们与我在系统变量路径中粘贴的行不同


更新-我已使用PowerShell和脚本检查系统变量中是否存在重复。我正在上载带有结果的图像。非常奇怪的是路径正是应该的,但正如您所看到的,在CMD中我看到了不同的东西



更新-今天我试着从PowerShell运行Ruby-一切正常。所以似乎只有CMD不知道发生了什么!只是提醒你-重新启动没有帮助!:)

如果你的系统变量路径长度超过某个值,它会
#REQUIRES -Version 3.0

<#
.SYNOPSIS
    A script to add or remove folders to %PATH%
.DESCRIPTION
    It contains 2 functions, one for adding and one for removing. It reads the registry and does the modifications there.
.NOTES
    File Name      : AddRemovePath.ps1
    Author         : Iulian Dita (iulian.dita@gmail.com)
    Prerequisite   : PowerShell V3 over Vista and upper.
    Copyright 2015 - Iulian Dita
.LINK
    Script located at:
    \\%server%\dsm2$\Work\Master\Projects\29532\Extern$
.VERSION
    0.7
.VERSION_HISTORY
    0.1 Initial version
    0.2 Bug fixes
    0.3 Cosmetic fixes, automatic removal of preceding ";"
    0.4 Fixed double entries
    0.5 Kill Explorer and CMD processes before making any modifications
    0.6 Check if folder to be removed already exists in PATH
        Escaping special characters no longer needed for the removal function
    0.7 Cleaned the code and removed some syntax missmatches
        Included the sendmessage function to avoid killing the explorer task
        Used [reges]::escape() to avoid running into troubles with the path-string and -match methode
        Contributed by Maik Krammer
#>

if (-not ("win32.nativemethods" -as [type])) {
    # import sendmessagetimeout from win32
    add-type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(
   IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam,
   uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
"@
}

$HWND_BROADCAST = [intptr]0xffff;
$WM_SETTINGCHANGE = 0x1a;
$result = [uintptr]::zero

function global:ADD-PATH
{
    [Cmdletbinding()]
    param ( 
        [parameter(Mandatory=$True, ValueFromPipeline=$True, Position=0)] 
        [string] $Folder
    )

    # See if a folder variable has been supplied.
    if (!$Folder -or $Folder -eq "" -or $Folder -eq $null) { 
        throw 'No Folder Supplied. $ENV:PATH Unchanged'
    }

    # Get the current search path from the environment keys in the registry.
    $oldPath=$(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path

    # See if the new Folder is already in the path.
    if ($oldPath | Select-String -SimpleMatch $Folder){ 
        return 'Folder already within $ENV:PATH' 
    }

    # Set the New Path and add the ; in front
    $newPath=$oldPath+';'+$Folder
    Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath -ErrorAction Stop

    # Show our results back to the world
    return 'This is the new PATH content: '+$newPath

    # notify all windows of environment block change
    [win32.nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [uintptr]::Zero, "Environment", 2, 5000, [ref]$result)
}

function global:REMOVE-PATH {
    [Cmdletbinding()]
    param ( 
        [parameter(Mandatory=$True, ValueFromPipeline=$True, Position=0)]
        [String] $Folder
    )

    # See if a folder variable has been supplied.
    if (!$Folder -or $Folder -eq "" -or $Folder -eq $NULL) { 
        throw 'No Folder Supplied. $ENV:PATH Unchanged'
    }

    # add a leading ";" if missing
    if ($Folder[0] -ne ";") {
        $Folder = ";" + $Folder;
    }

    # Get the Current Search Path from the environment keys in the registry
    $newPath=$(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path

    # Find the value to remove, replace it with $NULL. If it's not found, nothing will change and you get a message.
    if ($newPath -match [regex]::Escape($Folder)) { 
        $newPath=$newPath -replace [regex]::Escape($Folder),$NULL 
    } else { 
        return "The folder you mentioned does not exist in the PATH environment" 
    }

    # Update the Environment Path
    Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath -ErrorAction Stop

    # Show what we just did
    return 'This is the new PATH content: '+$newPath

    # notify all windows of environment block change
    [win32.nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [uintptr]::Zero, "Environment", 2, 5000, [ref]$result)
}


# Use ADD-PATH or REMOVE-PATH accordingly.

#Anything to Add?

ADD-PATH "%_PATH_TO_BE_ADDED%"

#Anything to Remove?

ADD-PATH "%_PATH_TO_BE_REMOVED%"