ruby 如何从 Gemfile 安装 gems?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37777131/
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 to install gems from Gemfile?
提问by jcubic
I want to add code coverage to my project and sign up coveralls.io and create Gemfile with:
我想为我的项目添加代码覆盖率并注册 coveralls.io 并使用以下命令创建 Gemfile:
gem 'coveralls', require: false
but how can I install the gem from Gemfile?
但是如何从 Gemfile 安装 gem?
回答by Sergioet
run the command bundle installin your shell, once you have your Gemfile created.
bundle install创建 Gemfile 后,在 shell 中运行命令。
This command will look your Gemfile and install the relevant Gems on the indicated versions.
此命令将查看您的 Gemfile 并在指定的版本上安装相关的 Gems。
The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.
安装 Gemfile 是因为在您的 Gemfile 中您指出了可以从中下载 gem 的来源。
Your can create a Gemfile just by typing bundle initin your shell
你可以通过bundle init在你的 shell 中输入来创建一个 Gemfile
I add a Gemfile example for your reference:
我添加了一个 Gemfile 示例供您参考:
source "https://rubygems.org" # where gems will be downloaded from
ruby "2.2.3" # ruby version, change for the one you use
gem "sinatra"
gem "sinatra-flash"
gem "sinatra-partial"
gem "bcrypt"
gem "dm-validations"
gem "dm-transactions"
gem "data_mapper"
gem "dm-postgres-adapter"
gem "pg"
gem "database_cleaner"
group :test do # you can make groups for test, development, production..
gem "rspec"
gem "capybara"
gem "rspec-sinatra"
gem "cucumber"
gem "coveralls", require: false
end
回答by briankip
First install bundler if you don't have it
如果没有,请先安装 bundler
gem install bundleror sudo gem install bundlerif you don't have the required permissions. Bundler is a gem that manages gem dependencies.
gem install bundler或者sudo gem install bundler如果您没有所需的权限。Bundler 是一个管理 gem 依赖的 gem。
then you can follow the above instruction for creating the gemfile, after which you can issue the command
然后你可以按照上面的说明创建gemfile,之后你可以发出命令
bundle install
bundle install

