在 Windows 中安装 Ruby Gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18908708/
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-06 06:11:11  来源:igfitidea点击:

Installing Ruby Gem in Windows

rubygeminstall

提问by user2797743

I'm new to ruby. I tried to install GEM on my PC by following the steps given in the site http://rubygems.org/pages/download.

我是红宝石的新手。我尝试按照网站http://rubygems.org/pages/download 中给出的步骤在我的 PC 上安装 GEM 。

I downloaded the package from the mention site and changed the directory to the directory in which the setup resides and tried to run setup using the command,

我从提及站点下载了包并将目录更改为安装程序所在的目录并尝试使用命令运行安装程序,

setup.rb in command prompt.

命令提示符中的 setup.rb。

but I get a window pop up that says "Windows can't open this file" and prompts me to select a program to open this file.

但是我弹出一个窗口,上面写着“Windows 无法打开这个文件”,并提示我选择一个程序来打开这个文件。

What should I do now? Let me know, if I do something wrong..

我现在该怎么办?让我知道,如果我做错了什么..

采纳答案by Mirage

I recommend you just use rubyinstaller

我建议你只使用rubyinstaller

It is recommended by the official Ruby page - see https://www.ruby-lang.org/en/downloads/

它由官方 Ruby 页面推荐 - 参见https://www.ruby-lang.org/en/downloads/

Ways of Installing Ruby

We have several tools on each major platform to install Ruby:

  • On Linux/UNIX, you can use the package management system of your distribution or third-party tools (rbenv and RVM).
  • On OS X machines, you can use third-party tools (rbenv and RVM).
  • On Windows machines, you can use RubyInstaller.

安装 Ruby 的方法

我们在每个主要平台上都有几个工具来安装 Ruby:

  • 在 Linux/UNIX 上,您可以使用发行版或第三方工具(rbenv 和 RVM)的包管理系统。
  • 在 OS X 机器上,您可以使用第三方工具(rbenv 和 RVM)。
  • 在 Windows 机器上,您可以使用 RubyInstaller。

回答by belgoros

To setup you Ruby development environment on Windows:

在 Windows 上设置 Ruby 开发环境:

  1. Install Ruby via RubyInstaller: http://rubyinstaller.org/downloads/

  2. Check your ruby version: Start - Run - type in cmdto open a windows console

  3. Type in ruby -v
  4. You will get something like that: ruby 2.0.0p353 (2013-11-22) [i386-mingw32]
  1. 通过 RubyInstaller 安装 Ruby:http://rubyinstaller.org/downloads/

  2. 检查您的 ruby​​ 版本:开始 - 运行 - 输入cmd以打开 Windows 控制台

  3. 输入 ruby -v
  4. 你会得到这样的东西: ruby 2.0.0p353 (2013-11-22) [i386-mingw32]

For Ruby 2.4 or later, run the extra installation at the end to install the DevelopmentKit. If you forgot to do that, run ridk installin your windows console to install it.

对于 Ruby 2.4 或更高版本,最后运行额外的安装来安装 DevelopmentKit。如果您忘记这样做,请ridk install在您的 Windows 控制台中运行以安装它。

For earlier versions:

对于早期版本:

  1. Download and install DevelopmentKit from the same download page as Ruby Installer. Choose an ?exe file corresponding to your environment (32 bits or 64 bits and working with your version of Ruby).
  2. Follow the installation instructions for DevelopmentKit described at: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit#installation-instructions. Adapt it for Windows.
  3. After installing DevelopmentKit you can install all needed gems by just running from the command prompt (windows console or terminal): gem install {gem name}. For example, to install rails, just run gem install rails.
  1. 从与 Ruby 安装程序相同的下载页面下载并安装 DevelopmentKit。选择与您的环境(32 位或 64 位并使用您的 Ruby 版本)相对应的 ?exe 文件。
  2. 按照以下位置描述的 DevelopmentKit 安装说明进行操作:https: //github.com/oneclick/rubyinstaller/wiki/Development-Kit#installation-instructions。使其适用于 Windows。
  3. 安装 DevelopmentKit 后,您只需从命令提示符(Windows 控制台或终端)运行即可安装所有需要的 gem:gem install {gem name}. 例如,要安装 rails,只需运行gem install rails.

Hope this helps.

希望这可以帮助。

回答by MiaeKim

Installing Ruby

安装 Ruby

Go to http://rubyinstaller.org/downloads/

转至http://rubyinstaller.org/downloads/

Make sure that you check "Add ruby ... to your PATH". enter image description here

确保选中“将 ruby​​ ... 添加到您的路径”​​。 在此处输入图片说明

Now you can use "ruby" in your "cmd".

现在您可以在“cmd”中使用“ruby”。

If you installed ruby 1.9.3 I expect that the ruby is downloaded in C:\Ruby193.

如果您安装了 ruby​​ 1.9.3,我希望 ruby​​ 以C:\Ruby193.

Installing Gem

安装 Gem

install Development Kitin rubyinstaller. Make new folder such as C:\RubyDevKitand unzip.

在 ruby​​installer 中安装开发工具包。制作新文件夹,例如C:\RubyDevKit并解压缩。

Go to the devkit directory and type ruby dk.rb initto generate config.yml.

转到 devkit 目录并键入ruby dk.rb init以生成config.yml.

If you installed devkit for 1.9.3, I expect that the config.ymlwill be written as C:\Ruby193.

如果你为 1.9.3 安装了 devkit,我希望它config.yml会被写成C:\Ruby193.

If not, please correct path to your ruby folders.

如果没有,请更正 ruby​​ 文件夹的路径。

After reviewing the config.yml, you can finally type ruby dk.rb install.

查看之后config.yml,您终于可以键入ruby dk.rb install.

Now you can use "gem" in your "cmd". It's done!

现在您可以在“cmd”中使用“gem”。完成!

回答by nimrod

Another way is to let chocolateymanage your ruby package (and any other package), that way you won't have to put ruby in your path manually:

另一种方法是让Chocolatey管理您的 ruby​​ 包(和任何其他包),这样您就不必手动将 ruby​​ 放在您的路径中:

Install chocolateyfirst by opening your favourite command prompt and executing:

首先通过打开您最喜欢的命令提示符并执行来安装Chocolatey

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

then all you need to do is type

然后你需要做的就是输入

cinst ruby

In your command prompt and the package installs.

在您的命令提示符和软件包安装中。

Using a package manager provides overall more control, I'd recommend this for every package that can be installed via chocolatey.

使用包管理器提供了更多的总体控制,我建议每个可以通过巧克力安装的包都使用它。

回答by fangxing

Use chocolateyin PowerShell

在 PowerShell 中使用巧克力

choco install ruby -y
refreshenv
gem install bundler

回答by nephewtom

I use scoopas command-liner installer for Windows... scoop rocks!
The quick answer (use PowerShell):

我使用scoop作为 Windows 的命令行安装程序... scoop 摇滚!
快速回答(使用 PowerShell):

PS C:\Users\myuser> scoop install ruby


Longer answer:

更长的答案:

Just searching for ruby:

只是在寻找红宝石:

PS C:\Users\myuser> scoop search ruby
'main' bucket:
    jruby (9.2.7.0)
    ruby (2.6.3-1)

'versions' bucket:
    ruby19 (1.9.3-p551)
    ruby24 (2.4.6-1)
    ruby25 (2.5.5-1)

Check the installation info :

检查安装信息:

PS C:\Users\myuser> scoop info ruby
Name: ruby
Version: 2.6.3-1
Website: https://rubyinstaller.org
Manifest:
  C:\Users\myuser\scoop\buckets\main\bucket\ruby.json
Installed: No
Environment: (simulated)
  GEM_HOME=C:\Users\myuser\scoop\apps\ruby\current\gems
  GEM_PATH=C:\Users\myuser\scoop\apps\ruby\current\gems
  PATH=%PATH%;C:\Users\myuser\scoop\apps\ruby\current\bin
  PATH=%PATH%;C:\Users\myuser\scoop\apps\ruby\current\gems\bin

Output from installation:

安装输出:

PS C:\Users\myuser> scoop install ruby
Updating Scoop...
Updating 'extras' bucket...
Installing 'ruby' (2.6.3-1) [64bit]
rubyinstaller-2.6.3-1-x64.7z (10.3 MB) [============================= ... ===========] 100%
Checking hash of rubyinstaller-2.6.3-1-x64.7z ... ok.
Extracting rubyinstaller-2.6.3-1-x64.7z ... done.
Linking ~\scoop\apps\ruby\current => ~\scoop\apps\ruby.6.3-1
Persisting gems
Running post-install script...
Fetching rake-12.3.3.gem
Successfully installed rake-12.3.3
Parsing documentation for rake-12.3.3
Installing ri documentation for rake-12.3.3
Done installing documentation for rake after 1 seconds
1 gem installed
'ruby' (2.6.3-1) was installed successfully!
Notes
-----
Install MSYS2 via 'scoop install msys2' and then run 'ridk install' to install the toolchain!
'ruby' suggests installing 'msys2'.
PS C:\Users\myuser>

回答by ITemius

Check that ruby interpreter is already installed and try "ruby setup.rb" in command prompt.

检查 ruby​​ 解释器是否已经安装并在命令提示符下尝试“ruby setup.rb”。