如何将gem冻结到Rails 3应用程序中?

时间:2021-07-15 07:16:18

I want to freeze a specific gem into my Rails application.

我想在Rails应用程序中冻结一个特定的gem。

In rails 2 there was this command:

在rails 2中有这样的命令:

rake gems:unpack

I can't find that command in Rails 3.

我在Rails 3中找不到这个命令。

13 个解决方案

#1


8  

I haven't had to do this yet, but I believe it's all handled by bundler.

我还没做过,但我相信这都是邦德勒干的。

When you create a new rails3 app, the rails dependencies are put into your Gemfile. You can run bundle install to install them. By default, they are installed into your BUNDLE_PATH.

当您创建一个新的rails3应用程序时,rails依赖项将被放入到Gemfile中。您可以运行bundle install来安装它们。默认情况下,它们被安装到BUNDLE_PATH中。

If you want to install them within your app, you can specify where: bundle install vendor/gems.

如果您想在应用程序中安装它们,可以指定:捆绑安装供应商/gems。

#2


21  

So, the short answer is, you don't.

简而言之,你不知道。

When you modify your Gemfile, and then run bundle install or bundle update, bundler handles the dependency resolution for you and determines the best (newest) versions of each gem you've required that satisfies the entire dependency chain (you won't get a new version that breaks another gem in the dependency list, etc.). You can also of course place a specific version, or a '>= 1.2.3' specification or whathaveyou in the Gemfile using the familiar syntax from the config.gem days, and bundler will make sure to satisfy that as well (or won't produce a Gemfile.lock if there is no valid resolution).

当你修改Gemfile,然后运行包安装或包更新,打包机为你处理依赖项决议和决定最好的(最新)版本的每个宝石你要求满足整个附属关系链(你不会得到一个新版本,另一个宝石依赖项列表,等等)。当然,您也可以使用配置中常见的语法在Gemfile中放置一个特定的版本,或者'>= 1.2.3'规范或任何您需要的东西。gem days和bundler将确保同样满足(或者不会生成Gemfile)。如果没有有效的解析,则锁定)。

When Bundler does its business, it creates the Gemfile.lock file, which (and this is provided you use bundler alone for managing your gem on all workstations/environments/deployments) performs the same function as freezing all of the gems you've required. For free! (Check this file into version control!) If your new development intern pulls down your source on a fresh machine, it takes one bundle install and the exact same versions of the gems that you have installed are on her machine. Push to deployment, and do a bundle install --deployment there (or more likely, throw it in your Capfile), and the same gems are installed (this time into vendor/bundle, configurable). Bundler is used in Rails 3 to manage loading all of the gems, so wherever you've told bundler to install them (whatever your normal gem install location is by default, or BUNDLE_PATH (which is recorded in .bundle/config if you install with bundle install --path=foo otherwise), bundler will load the right ones, even when they differ from system gems.

当Bundler进行业务时,它将创建Gemfile。锁文件(这是提供的,您可以使用bundler单独在所有工作站/环境/部署上管理gem)执行与冻结所有必需的gem相同的功能。免费!(将此文件检入版本控制!)如果你的新开发实习生在一台新机器上下载你的源代码,它需要一个捆绑安装,你安装的宝石的相同版本也在她的机器上。推动部署,并做一个捆绑包安装——部署在那里(或者更有可能,将它放入您的Capfile中),并且安装了相同的gem(这一次是供应商/bundle,可配置的)。Rails 3中使用打包机管理加载所有的宝石,所以无论你告诉打包机安装它们(无论你正常的gem安装位置是在默认情况下,或BUNDLE_PATH(记录在.bundle /配置如果你安装包安装——路径否则= foo),打包机将加载正确的,即使他们不同于系统宝石。

You don't need to unpack the gems and check them in to your app, because it doesn't matter: you're guaranteeing the same versions are being called regardless of where they are installed, which will likely vary from machine to machine anyways (.bundle/ should not be checked in to the repo) - so why stick another 60-80 MB of files into your repo that you won't ever be changing or using? (incidentally, this is why I wouldn't recommend a bundle install --path=vendor/gems like nfm suggested - it's not necessarily wrong, there's just no benefit to it over the normal bundler workflow, and now your repo size just ballooned up).

您不需要打开gem并将它们检入到应用程序中,因为这并不重要:无论它们安装在哪里,您都要保证调用相同的版本,这可能会因机器而异。bundle/不应该检入到repo)—那么为什么要在您的repo中再插入60-80 MB的文件,而您永远不会修改或使用这些文件呢?(顺便说一句,这就是为什么我不推荐bundle install——path=vendor/gems,就像nfm建议的那样——它不一定是错的,它与普通的bundler工作流相比没有什么好处,现在您的repo大小膨胀了)。

#3


18  

DO NOT USE THE "RECOMMENDED" ANSWER BY NFM!

不要使用NFM的“推荐”答案!

Instead, review the Bundler site, particularly the page on deployments: http://gembundler.com/deploying.html

相反,请查看Bundler站点,特别是关于部署的页面:http://gembundler.com/deploying.html

The short summary is to use specific versions in your Gemfile and run bundle install --deployment on each target system where you need the exact gem versions.

简短的总结是在Gemfile中使用特定的版本,并在每个需要确切gem版本的目标系统上运行bundle install——部署。

Using the --path option will install the gems, but it's not really what you want to do. As Matt Enright said, you just bloat your SCM with stuff that bundler can handle smartly on each target environment.

使用-path选项将安装gem,但这不是您真正想要做的。就像Matt Enright说的,你只是用bundler能够在每个目标环境中灵活处理的东西来填充SCM。

#4


7  

I had to do this for typus gem deployment on Heroku as you can't run a heroku rails generate typus on Heroku given it's a read only file system. I didn't want ALL gems put into my app, just the one that was causing me grief. Here are the steps that lead to success:

我必须在Heroku上部署typus gem,因为你不能在Heroku上运行Heroku rails生成typus,因为它是一个只读文件系统。我不希望把所有的宝石都放到我的应用里,只让我伤心。以下是通向成功的步骤:

  1. create directory in app_name/vendor/gems/gem_name (optional) ... in my case /app_name/vendor/gems/typus

    在app_name/vendor/gem /gem_name(可选)中创建目录…在我的例子中/ app_name /供应商/珠宝/ typus

  2. add the following to gemfile (this tells bundle where to find and put the gem source):

    向gemfile中添加以下内容(告诉bundle在哪里找到并放置gem源):

    gem 'typus', :git => 'https://github.com/fesplugas/typus.git', :path => "vendor/gems/typus"

    gem 'typus',:git => 'https://github.com/fesplugas/typus.git',:path => "供应商/gem /typus"

  3. then from within your app directory (this installs the gem into your app):

    然后从您的应用程序目录中(将gem安装到您的应用程序中):

    'gem unpack typus --target vendor/gems/typus'

    “gem unpack typus——目标供应商/gems/typus”

  4. then bundle install

    然后包安装

  5. then .. in my case... commit and push to repository and then deploy up to heroku... you may have to run a heroku rake db:migrate

    然后. .就我而言…提交并推送到存储库,然后部署到heroku…您可能需要运行一个heroku rake db:迁移。

#5


1  

Assuming you already have bundler gem installed:

假设你已经安装了bundler gem:

  • $ bundle lock
  • 美元捆锁
  • $ git add Gemfile.lock
  • git添加Gemfile.lock美元

#6


1  

You can bundle install on dreamhost without any issues. If you are on shared the environment is already setup to store them locally in your home directory. If you are on a VPS or Dedicated you can run bundle install as root or just add this to your .bash_profile

您可以在dreamhost上捆绑安装,没有任何问题。如果您是共享的,那么环境已经被设置为在您的主目录中本地存储它们。如果您使用的是VPS或专用版本,您可以作为root用户运行bundle install,或者将其添加到.bash_profile中

export GEM_HOME=$HOME/.gems
export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8

#7


1  

I think what you are looking for is

我想你要找的是

bundle package

checkout the man pages here: http://gembundler.com/man/bundle-package.1.html

在这里查看手册页:http://gembundler.com/man/bundle-package.1.html。

#8


1  

I second the answer by tsega (updated by coreyward). "bundle package" is the generic answer.

我支持tsega(由coreyward更新)的答案。“bundle package”是通用的答案。

The poster didn't ask WHETHER to freeze his gems. He wanted to know HOW. Answers like "Just don't do it" aren't helpful at all. Yes, it turned out his specific problem was a little different than that, but while "bundle package" might have been overkill it still solves the problem.

这张海报并没有问是否要冻结他的宝石。他想知道怎么做。像“不要做”这样的回答毫无用处。是的,事实证明他的具体问题与此稍有不同,但尽管“捆绑包”可能有些过头了,但它仍然解决了问题。

I have worked on a lot of systems, and on some you just don't have full access. Installing gems on some systems just isn't an option. So unless you package them, in general you're screwed. There are different workarounds for different hosts and systems, but none for some.

我在很多系统上工作过,有些系统你无法完全访问。在某些系统上安装gems是不可能的。所以,除非你把它们打包,一般来说,你就完蛋了。对于不同的主机和系统,有不同的解决方案,但对某些不同的系统却没有。

#9


0  

Pod - If you need to modify the gem, the best practice to do this would be forking the project, making the change, then using the 'git' flag in bundler:

Pod——如果您需要修改gem,最好的做法是将项目分叉,进行更改,然后使用bundler中的“git”标记:

git 'some_gem', :git => 'git://github.com/me/my_forked_some_gem.git'

git' some_gem',:git => 'git://github.com/me/my_forked_some_gem.git'

This way you'll be notified when the gem is updated.

这样,当gem被更新时,您将得到通知。

#10


0  

The command that you want is bundle package which just unpacks the gems and dependencies at vendor/cache folder.

您需要的命令是bundle package,它只是在vendor/cache文件夹中解包gem和依赖项。

But just a notice, the :git => .... kind of gems wont get packaged. You have to hack a way out for :git => ... related gems to get packed.

只是一个通知,:git = > ....宝石不能包装。你得想个办法:git =>……相关宝石要打包。

#11


0  

Cleaner instructions for the gem unpack and :path => option:

关于gem解包和:path =>选项的更清晰的说明:

#12


-1  

A lot of comments are somewhat saying that it's not useful to use the bundle install --path vendor/gems, but those people who are using Dreamhost, it should note that you cannot use bundle install in Dreamhost.

很多评论说使用bundle install——path vendor/gems是没有用的,但是使用Dreamhost的人应该注意,不能在Dreamhost中使用bundle install。

The solution is to get all the gems into the vendor folder and upload the whole thing to the Dreamhost directory.

解决方案是将所有的gem放到供应商文件夹中,并将整个内容上传到Dreamhost目录中。

There are other solutions to turn around this, but it's much more complicated to do.

有其他的解决办法可以扭转这一局面,但这要复杂得多。

#13


-1  

Well I have to modify slightly one of the gems I need. So I need to keep it inside my Repo. So what NFM mentioned is what I probably need.

我需要修改其中一个宝石。所以我需要把它放在我的Repo里面。NFM提到的就是我可能需要的。

#1


8  

I haven't had to do this yet, but I believe it's all handled by bundler.

我还没做过,但我相信这都是邦德勒干的。

When you create a new rails3 app, the rails dependencies are put into your Gemfile. You can run bundle install to install them. By default, they are installed into your BUNDLE_PATH.

当您创建一个新的rails3应用程序时,rails依赖项将被放入到Gemfile中。您可以运行bundle install来安装它们。默认情况下,它们被安装到BUNDLE_PATH中。

If you want to install them within your app, you can specify where: bundle install vendor/gems.

如果您想在应用程序中安装它们,可以指定:捆绑安装供应商/gems。

#2


21  

So, the short answer is, you don't.

简而言之,你不知道。

When you modify your Gemfile, and then run bundle install or bundle update, bundler handles the dependency resolution for you and determines the best (newest) versions of each gem you've required that satisfies the entire dependency chain (you won't get a new version that breaks another gem in the dependency list, etc.). You can also of course place a specific version, or a '>= 1.2.3' specification or whathaveyou in the Gemfile using the familiar syntax from the config.gem days, and bundler will make sure to satisfy that as well (or won't produce a Gemfile.lock if there is no valid resolution).

当你修改Gemfile,然后运行包安装或包更新,打包机为你处理依赖项决议和决定最好的(最新)版本的每个宝石你要求满足整个附属关系链(你不会得到一个新版本,另一个宝石依赖项列表,等等)。当然,您也可以使用配置中常见的语法在Gemfile中放置一个特定的版本,或者'>= 1.2.3'规范或任何您需要的东西。gem days和bundler将确保同样满足(或者不会生成Gemfile)。如果没有有效的解析,则锁定)。

When Bundler does its business, it creates the Gemfile.lock file, which (and this is provided you use bundler alone for managing your gem on all workstations/environments/deployments) performs the same function as freezing all of the gems you've required. For free! (Check this file into version control!) If your new development intern pulls down your source on a fresh machine, it takes one bundle install and the exact same versions of the gems that you have installed are on her machine. Push to deployment, and do a bundle install --deployment there (or more likely, throw it in your Capfile), and the same gems are installed (this time into vendor/bundle, configurable). Bundler is used in Rails 3 to manage loading all of the gems, so wherever you've told bundler to install them (whatever your normal gem install location is by default, or BUNDLE_PATH (which is recorded in .bundle/config if you install with bundle install --path=foo otherwise), bundler will load the right ones, even when they differ from system gems.

当Bundler进行业务时,它将创建Gemfile。锁文件(这是提供的,您可以使用bundler单独在所有工作站/环境/部署上管理gem)执行与冻结所有必需的gem相同的功能。免费!(将此文件检入版本控制!)如果你的新开发实习生在一台新机器上下载你的源代码,它需要一个捆绑安装,你安装的宝石的相同版本也在她的机器上。推动部署,并做一个捆绑包安装——部署在那里(或者更有可能,将它放入您的Capfile中),并且安装了相同的gem(这一次是供应商/bundle,可配置的)。Rails 3中使用打包机管理加载所有的宝石,所以无论你告诉打包机安装它们(无论你正常的gem安装位置是在默认情况下,或BUNDLE_PATH(记录在.bundle /配置如果你安装包安装——路径否则= foo),打包机将加载正确的,即使他们不同于系统宝石。

You don't need to unpack the gems and check them in to your app, because it doesn't matter: you're guaranteeing the same versions are being called regardless of where they are installed, which will likely vary from machine to machine anyways (.bundle/ should not be checked in to the repo) - so why stick another 60-80 MB of files into your repo that you won't ever be changing or using? (incidentally, this is why I wouldn't recommend a bundle install --path=vendor/gems like nfm suggested - it's not necessarily wrong, there's just no benefit to it over the normal bundler workflow, and now your repo size just ballooned up).

您不需要打开gem并将它们检入到应用程序中,因为这并不重要:无论它们安装在哪里,您都要保证调用相同的版本,这可能会因机器而异。bundle/不应该检入到repo)—那么为什么要在您的repo中再插入60-80 MB的文件,而您永远不会修改或使用这些文件呢?(顺便说一句,这就是为什么我不推荐bundle install——path=vendor/gems,就像nfm建议的那样——它不一定是错的,它与普通的bundler工作流相比没有什么好处,现在您的repo大小膨胀了)。

#3


18  

DO NOT USE THE "RECOMMENDED" ANSWER BY NFM!

不要使用NFM的“推荐”答案!

Instead, review the Bundler site, particularly the page on deployments: http://gembundler.com/deploying.html

相反,请查看Bundler站点,特别是关于部署的页面:http://gembundler.com/deploying.html

The short summary is to use specific versions in your Gemfile and run bundle install --deployment on each target system where you need the exact gem versions.

简短的总结是在Gemfile中使用特定的版本,并在每个需要确切gem版本的目标系统上运行bundle install——部署。

Using the --path option will install the gems, but it's not really what you want to do. As Matt Enright said, you just bloat your SCM with stuff that bundler can handle smartly on each target environment.

使用-path选项将安装gem,但这不是您真正想要做的。就像Matt Enright说的,你只是用bundler能够在每个目标环境中灵活处理的东西来填充SCM。

#4


7  

I had to do this for typus gem deployment on Heroku as you can't run a heroku rails generate typus on Heroku given it's a read only file system. I didn't want ALL gems put into my app, just the one that was causing me grief. Here are the steps that lead to success:

我必须在Heroku上部署typus gem,因为你不能在Heroku上运行Heroku rails生成typus,因为它是一个只读文件系统。我不希望把所有的宝石都放到我的应用里,只让我伤心。以下是通向成功的步骤:

  1. create directory in app_name/vendor/gems/gem_name (optional) ... in my case /app_name/vendor/gems/typus

    在app_name/vendor/gem /gem_name(可选)中创建目录…在我的例子中/ app_name /供应商/珠宝/ typus

  2. add the following to gemfile (this tells bundle where to find and put the gem source):

    向gemfile中添加以下内容(告诉bundle在哪里找到并放置gem源):

    gem 'typus', :git => 'https://github.com/fesplugas/typus.git', :path => "vendor/gems/typus"

    gem 'typus',:git => 'https://github.com/fesplugas/typus.git',:path => "供应商/gem /typus"

  3. then from within your app directory (this installs the gem into your app):

    然后从您的应用程序目录中(将gem安装到您的应用程序中):

    'gem unpack typus --target vendor/gems/typus'

    “gem unpack typus——目标供应商/gems/typus”

  4. then bundle install

    然后包安装

  5. then .. in my case... commit and push to repository and then deploy up to heroku... you may have to run a heroku rake db:migrate

    然后. .就我而言…提交并推送到存储库,然后部署到heroku…您可能需要运行一个heroku rake db:迁移。

#5


1  

Assuming you already have bundler gem installed:

假设你已经安装了bundler gem:

  • $ bundle lock
  • 美元捆锁
  • $ git add Gemfile.lock
  • git添加Gemfile.lock美元

#6


1  

You can bundle install on dreamhost without any issues. If you are on shared the environment is already setup to store them locally in your home directory. If you are on a VPS or Dedicated you can run bundle install as root or just add this to your .bash_profile

您可以在dreamhost上捆绑安装,没有任何问题。如果您是共享的,那么环境已经被设置为在您的主目录中本地存储它们。如果您使用的是VPS或专用版本,您可以作为root用户运行bundle install,或者将其添加到.bash_profile中

export GEM_HOME=$HOME/.gems
export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8

#7


1  

I think what you are looking for is

我想你要找的是

bundle package

checkout the man pages here: http://gembundler.com/man/bundle-package.1.html

在这里查看手册页:http://gembundler.com/man/bundle-package.1.html。

#8


1  

I second the answer by tsega (updated by coreyward). "bundle package" is the generic answer.

我支持tsega(由coreyward更新)的答案。“bundle package”是通用的答案。

The poster didn't ask WHETHER to freeze his gems. He wanted to know HOW. Answers like "Just don't do it" aren't helpful at all. Yes, it turned out his specific problem was a little different than that, but while "bundle package" might have been overkill it still solves the problem.

这张海报并没有问是否要冻结他的宝石。他想知道怎么做。像“不要做”这样的回答毫无用处。是的,事实证明他的具体问题与此稍有不同,但尽管“捆绑包”可能有些过头了,但它仍然解决了问题。

I have worked on a lot of systems, and on some you just don't have full access. Installing gems on some systems just isn't an option. So unless you package them, in general you're screwed. There are different workarounds for different hosts and systems, but none for some.

我在很多系统上工作过,有些系统你无法完全访问。在某些系统上安装gems是不可能的。所以,除非你把它们打包,一般来说,你就完蛋了。对于不同的主机和系统,有不同的解决方案,但对某些不同的系统却没有。

#9


0  

Pod - If you need to modify the gem, the best practice to do this would be forking the project, making the change, then using the 'git' flag in bundler:

Pod——如果您需要修改gem,最好的做法是将项目分叉,进行更改,然后使用bundler中的“git”标记:

git 'some_gem', :git => 'git://github.com/me/my_forked_some_gem.git'

git' some_gem',:git => 'git://github.com/me/my_forked_some_gem.git'

This way you'll be notified when the gem is updated.

这样,当gem被更新时,您将得到通知。

#10


0  

The command that you want is bundle package which just unpacks the gems and dependencies at vendor/cache folder.

您需要的命令是bundle package,它只是在vendor/cache文件夹中解包gem和依赖项。

But just a notice, the :git => .... kind of gems wont get packaged. You have to hack a way out for :git => ... related gems to get packed.

只是一个通知,:git = > ....宝石不能包装。你得想个办法:git =>……相关宝石要打包。

#11


0  

Cleaner instructions for the gem unpack and :path => option:

关于gem解包和:path =>选项的更清晰的说明:

#12


-1  

A lot of comments are somewhat saying that it's not useful to use the bundle install --path vendor/gems, but those people who are using Dreamhost, it should note that you cannot use bundle install in Dreamhost.

很多评论说使用bundle install——path vendor/gems是没有用的,但是使用Dreamhost的人应该注意,不能在Dreamhost中使用bundle install。

The solution is to get all the gems into the vendor folder and upload the whole thing to the Dreamhost directory.

解决方案是将所有的gem放到供应商文件夹中,并将整个内容上传到Dreamhost目录中。

There are other solutions to turn around this, but it's much more complicated to do.

有其他的解决办法可以扭转这一局面,但这要复杂得多。

#13


-1  

Well I have to modify slightly one of the gems I need. So I need to keep it inside my Repo. So what NFM mentioned is what I probably need.

我需要修改其中一个宝石。所以我需要把它放在我的Repo里面。NFM提到的就是我可能需要的。