“PHP 作曲家"与“Ruby Gems and Bundler"相比;作曲家、quot、PHP、Ruby

2023-09-06 16:41:35 作者:宁乡小王子

(首先,这个问题不是哪个更好"的问题.我只是想知道它们在功能方面的相似之处和不同之处.)

(As first, this question is not "which is better" question. I just want to know how they are similar and differ in functionality perspective.)

我是 php 开发人员,目前正在学习 ruby.现在,许多 php 开发人员被鼓励使用 Composer 进行依赖管理.在提问之前,我想先验证我的知识.

I'm php developer and currently learning ruby. In these days, many php developers are encouraged to use Composer for dependency management. Before asking questions, I would like to validate my knowledge first.

据我了解

Composer是一个php库(或包)的依赖管理工具.Composer 为每个项目安装 php 库(所谓的本地).我的意思是为 project1 安装的 php 库不能重新用于 project2,而无需再次为 project2 安装. Composer is a dependency management tool for php libraries (or packages). Composer installed php library per project basis (so-called locally). I mean php library installed for project1 cannot be reused for project2 without install again for project2.

我注意到Ruby还有非常好的依赖管理工具RubyGems".据我所知,

I've noticed that Ruby also has very good dependency management tool "RubyGems". According to my knowledge,

RubyGems"是Gems"的包管理器.Gem"是以标准格式打包的Ruby程序或库,用于共享.(Rails 也是一颗宝石.)Gem 可以通过 gem install sinatra 之类的命令安装.但是,还有所谓的Bundler",它也是为应用程序捆绑 gem 的 gem.当命令 bundle install 运行时(在特定的 ruby​​ 项目目录下),Gemfile 中列出的所有 gem 都会为这个 ruby​​ 项目安装. "RubyGems" is a package manager for "Gems". "Gem" is a Ruby program or library packaged in a standard format for sharing. (Rails is also a gem.) Gem can be installed by command like that gem install sinatra. But, there is also so-called "Bundler" which is also a gem for bundling gems for an application. When command bundle install runs (under specific ruby project directory), all the gems listed in the Gemfile are installed for this ruby project.

所以,我的问题在这里.

So, my questions are here.

Composer 类似于 RubyGems 还是 Bundler ?当运行 gem install sinatra 时,它是安装在系统级的吗?运行 bundle install 时,无论是在本地(仅在此项目上)还是在系统范围内安装 Gem?如果我需要一个 gem 的两个版本(例如 sinatra)用于不同的项目,我应该如何处理? Composer is similar to whether RubyGems or Bundler ? When run gem install sinatra, is it installed on system-wide level ? When run bundle install, the Gems are installed whether locally (on this project only) or system-wide level ? If I need two versions of one gem (for e.g. sinatra) for different projects, how should I handle ?

(对不起,我的问题很长.如果我的理解有问题,再次抱歉,请指出正确的.)

(Sorry for my long question. If my understandings are something wrong, sorry again and please point out the right one.)

推荐答案

1) Composer 更类似于 bundler.Composer 将所有内容带入您的项目,bundler 将所有内容带入您的系统并在您的项目上下文中链接"它们.Bundler 在后面使用 gems.

1) Composer is more similar to bundler. Composer brings everything in your project, bundler brings everything to your system and "links" them in the context of your project. Bundler is working with gems in the back.

2) 是的.gem install 在系统范围内执行操作(或者如果您使用 rbenv 或 rvm 之类的,则按用户执行)

2) yes. gem install does things system-wide (or per user if you use something like rbenv or rvm)

3) 查看 1. 系统范围,并在您通过 bundle exec 运行时根据 Gemfile 正确选择

3) see 1. system wide and are correctly picked according to the Gemfile when you run things through bundle exec

4) 我建议使用 Gemfile,将您感兴趣的版本放在那里,然后让 bundler 完成剩下的工作(它将在后面安装多个版本并选择正确的版本).不过一定要运行bundle exec".如果您使用 rvm,您还可以选择使用 rvm gemset,但这更难处理,而且您在尝试部署时会遇到非常糟糕的情况.

4) I recommend using a Gemfile, putting the version you're interested in there and letting bundler do the rest (it will in the back install multiple versions and pick the right one). Be sure to run "bundle exec" though. You also have the option of using an rvm gemset if you're into rvm but that's harder to handle and you will have a really bad time when attempting to deploy.