windows 如何阻止“gem”实用程序访问我的主目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/849660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:27:15  来源:igfitidea点击:

How to stop the 'gem' utility from accessing my home directory?

windowsrubyunicoderubygems

提问by Andrew Андрей Листочкин

When I run

当我跑

gem install <somegem>

command the gemutility tries to access my home directory. It contains some non-latin characters and installation fails because of that. For example:

命令gem实用程序尝试访问我的主目录。它包含一些非拉丁字符,因此安装失败。例如:

E:\ruby\bin>gem install <somegem>
ERROR:  While executing gem ... (Errno::ENOENT)
    No such file or directory - C:\Documents and Settings\<user>

If I switch to another user account with a username containing ASCII characters only gemworks fine.

如果我使用包含 ASCII 字符的用户名切换到另一个用户帐户,则只能gem正常工作。

Does anybody know how to tell gem NOT to check my home directory?

有人知道如何告诉 gem 不要检查我的主目录吗?

UPDATE: I tried to set up GEM_HOME as suggested below but it didn't help (still checks the user home directory)

更新:我尝试按照下面的建议设置 GEM_HOME,但没有帮助(仍然检查用户主目录)

回答by Sergey 'm17' Kolosov

Just change HOMEDRIVE and HOMEPATH before running gem, and restore after (if needed).

只需在运行gem之前更改 HOMEDRIVE 和 HOMEPATH ,然后恢复(如果需要)。

I've changed my gem.batlike this:

我已经像这样改变了我的gem.bat

@ECHO OFF
SET _HOMEDRIVE=%HOMEDRIVE%
SET _HOMEPATH=%HOMEPATH%
SET HOMEDRIVE=E:
SET HOMEPATH=/Dev/Ruby
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "E:/Dev/Ruby/bin/gem" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*
SET HOMEDRIVE=%_HOMEDRIVE%
SET HOMEPATH=%_HOMEPATH%

E:/Dev/Ruby/is my Ruby path. It seems that HOMEPATH can be changed to anything else with ASCII only characters in path.

E:/Dev/Ruby/是我的 Ruby 路径。似乎可以将 HOMEPATH 更改为路径中仅包含 ASCII 字符的任何其他内容。

回答by prijutme4ty

It's simpler to write:

写起来更简单:

@ECHO OFF
SET HOMEPATH=
IF NOT "%~f0" == "~f0" GOTO :WinNT
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*

In this case you don't need to write your path and can replace or redistribute with file for new installations

在这种情况下,您无需编写路径,并且可以替换或重新分发新安装的文件

回答by Alexander.Iljushkin

just run postinstall file pi.bat or pi.sh this file is in ./RubyDevKit/postinstall.

只需运行安装后文件 pi.bat 或 pi.sh 这个文件在 ./RubyDevKit/postinstall 中。

this worked for me. it seems that installer of cygwin broke my settings.

这对我有用。cygwin 的安装程序似乎破坏了我的设置。

回答by konyak

Restart the command prompt console as something might have Hymaned it up. I had the same issue, and restarting the console reset my environment.

重新启动命令提示符控制台,因为某些东西可能已经把它顶起来了。我遇到了同样的问题,重新启动控制台会重置我的环境。

回答by ry.

Perhaps try changing the value of the GEM_HOME environment directory?

也许尝试更改 GEM_HOME 环境目录的值?

回答by MickaelFM

If you GEM_PATH is set to your user directory, it will still access it. Try changing GEM_HOME and GEM_PATH.

如果您将 GEM_PATH 设置为您的用户目录,它仍将访问它。尝试更改 GEM_HOME 和 GEM_PATH。