Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体

35
votes
answers
楼主
73 views
+10

Rubygems,Bundler和RVM之間的關係

按照目前的最佳做法,每種方法的作用是什麼? 基於我對Bundler和RVM的有限理解,似乎他們 - 像Rubygems - 有自己的寶石安裝位置。另外,對於每一個,都可以選擇使用sudo或安裝到主目錄中的系統路徑。然後有能力使用Bundler供應寶石(適用時,例如使用Rails)。 所以在我看來現在至少有七個地方可以安裝寶石: Rubygems系統路徑 Rubygems用戶路徑 RVM系統路徑 RVM用戶路徑 Bundler系統路徑 Bundler用戶路徑 供應商(每個應用程序) 那麼,管理這一切的最佳方法是什麼?我們是否使用全部三個(Rubygems,Bundler,RVM)並告訴他們所有人將寶石安裝到同一個地方?我們sudo一直在使用,有時候還是從不使用?我們是否應該在生產和開發機器上使用不同的策略? 在相關的說明中,圍繞Rubygems的Bundler和RVM包裝器,它們是它們的替代品,還是它們完全正交?
up vote 32 down vote accepted favorite
沙发
+320
+50

來自Bundler的網站

Bundler可以輕鬆確保您的應用程序具有啟動和運行所需的依賴項,而不會出現錯誤。

這意味著,對於其他開發人員或您在另一台計算機上,準備進一步開發或使用它,通過運行bundle install並且您擁有啟動和運行所需的一切,這是微不足道的

RVM用於在同一台機器上管理多個版本的Ruby,並在它們之間進行切換。Gemsets是RVM提供的一項強大功能,可將一個應用程序/庫的gem與系統的其餘部分隔離開來。

當一起使用RVM和Bundler時,RVM告訴Bundler gem應該去哪裡,Bundler將它們安裝到RVM文件夾中。

兩者(關於RVM中的gems)使用並依賴於Rubygems,因此它們最接近包裝器。

我個人使用Bundler和RVM來完成我的所有項目。沒有gemsets,只有Bundler來解決和修復問題,它確實沒有失敗。安裝gems沒有sudo,最終在RVM定義的地方。我的系統上的默認Ruby安裝是獨立的,並且沒有任何內容安裝到Rubygems系統/用戶路徑

when rvm is installed, how is rvm telling bundler, where to install gems ? – Anand Jan 5 '11 at 12:34

without RVM, bundler installs the gems into the default system location for gems (for example /usr/lib/ruby/gems, which is the default on my Gentoo-box). RVM tells Bundler where to install by providing the GEM_HOME environment variable. – PerfectlyNormal Jan 5 '11 at 16:37

no, never found anything that really needed it. – PerfectlyNormal Dec 5 '10 at 23:34

your answer was very clear. but when rvm is not installed, where will bundler install the gems. – Anand Jan 5 '11 at 12:34

Do you use sudo/rvmsudo? – rlkw1024 Dec 5 '10 at 23:29

+30

我現在這樣做的方式(雖然仍在嘗試一下)是這樣的:

  1. Use RVM to set up the ruby version and a gemset to use for an app. I use an .rvmrc-file in the root of the app directory to make sure the correct ruby and gemset is used all the time.

  2. Bundler is installed using gem without sudo in the given gemset.

  3. Any gems needed by the app is added to the apps Gemfile and installed using Bundler. I'm not using sudo for this.

This way I use Bundler to keep track of the dependencies for each app, and RVM to isolate each app's gems from each other. Works really smooth, actually.

I have not yet installed RVM on my deployment server, there I just use Bundler to make sure each apps dependecies are handled. I will probably install RVM there as well, but have to figure out how that plays ball with Passenger first.

As for your last question, Bundler is a wrapper around gem, RVM just manipulates the gempath where gems are installed. It seems to be smart enough that it picks up the gems from the same place though so I don't need to recompile any that are already installed in some other gemset.

I've stopped using sudo for installing gems after starting to use RVM. There's really no reason over just installing them in the rvm user path. I'm unsure about the best practice if you have more developers on the same machine like a test server or something like that.

Gemsets are RVM-only. Bundler is unaware of anything different. You can either switch manually, or add a .rvmrc-file ( docs ) that takes care of it. You should read the documentation for Gemsets for more details – PerfectlyNormal Dec 6 '10 at 0:59

Thanks! Do you switch to the right gemset when you go to work on a certain application, or can Bundler handle that for you? – rlkw1024 Dec 5 '10 at 23:25

A gemset starts out empty, completely separate from the rest of the system. Bundler and the Gemfile still do the same thing, but installed into the gemset instead of globally. – PerfectlyNormal Dec 5 '10 at 23:17

"Use RVM to set up the ruby version and a gemset to use for an app"--How does this gemset interact with the Gemfile and Bundler? – rlkw1024 Dec 5 '10 at 23:11

discard