ruby 如何列出远程站点上可用的 gem 的所有版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9146012/
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
How do I list all versions of a gem available at a remote site?
提问by opensas
I'm trying to find out all the remotely available versions of a specified gem.
我试图找出指定 gem 的所有远程可用版本。
I tried using:
我尝试使用:
gem list rhc --remote
But it shows:
但它显示:
*** REMOTE GEMS ***
rhc (0.84.15)
rhcp (0.2.18)
rhcp_shell (0.2.12)
Any ideas?
有任何想法吗?
回答by opensas
Well, it was easier than I thought (well, not really, let's say as easy as it should be):
嗯,这比我想象的要容易(嗯,不是真的,让我们说应该很简单):
gem list rhc --remote --all
Which returns:
返回:
*** REMOTE GEMS ***
rhc (0.84.15, 0.84.13, 0.83.9, 0.82.18, 0.81.14, 0.80.5, 0.79.5, 0.77.8, 0.75.9, 0.74.6, 0.74.5, 0.73.14, 0.72.29, 0.71.2, 0.69.6, 0.69.3, 0.68.5)
rhcp (0.2.18, 0.2.17, 0.2.16, 0.2.15, 0.2.14, 0.1.9, 0.1.8, 0.1.7, 0.1.6, 0.1.5, 0.1.4, 0.1.3, 0.1.2)
rhcp_shell (0.2.12, 0.2.11, 0.0.9, 0.0.7, 0.0.6, 0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1)
回答by Eyal Levin
According to RubyGem's Guideyou should use the searchkeyword. So the command could be:
根据RubyGem's Guide你应该使用search关键字。所以命令可能是:
gem search rhc --all
gem search rhc --all
If you want the exact name use:
如果您想要确切的名称,请使用:
gem search ^rhc$ --all
gem search ^rhc$ --all
If you want to include prerelease versions use --pre
如果要包含预发布版本,请使用 --pre
gem search ^rhc$ --pre
gem search ^rhc$ --pre
And if you're using zshadd quotes:
如果您使用zsh添加引号:
gem search '^rhc$' --all
gem search '^rhc$' --all
回答by Jared Beck
To extend @eyalev's answer, if you want a list of one version per line, here's a one-liner:
为了扩展@eyalev 的答案,如果你想要每行一个版本的列表,这里有一个单行:
gem search '^rspec$' --all \
| grep -o '\((.*)\)$' \
| tr -d '() ' \
| tr ',' "\n" \
| sort
0.0.10
0.1.0
0.1.1
# etc.
To make this a bit more re-usable, you could write some functions (pardon my limited bash skills):
为了使其更易于重用,您可以编写一些函数(请原谅我有限的 bash 技能):
function extract_gem_versions() {
echo "" \
| grep -o '\((.*)\)$' \
| tr -d '() ' \
| tr ',' "\n";
}
function gem_versions() {
local gem_name="";
local pattern="^${gem_name}$";
local vers_str="$(gem search ${pattern} --all)";
extract_gem_versions "$vers_str";
}
gem_versions rspec | sort
0.0.10
0.1.0
0.1.1
# etc.
回答by Only Bolivian Here
Try:
尝试:
gem list [STRING] [options]
For example:
例如:
gem list rhc -r
Or try:
或尝试:
gem list -r rhc
(the documentation, and the example provided seem to contradict each other - try both)
(文档和提供的示例似乎相互矛盾 - 两者都尝试)
See the documentation:
请参阅文档:

