I am new to Ruby and trying to wrap my head around following concepts: bundler vs RVM vs gems vs RubyGems vs gemsets vs system rub and I'm confused.
我是Ruby的新手,试图用我的头脑来思考以下的概念:bundler vs RVM vs . RubyGems对gemset vs系统rub,我很困惑。
Can someone please describe a 'best practice' of how I should manage all this on a fresh install of the latest version of Ubuntu? What should I install, and how should I use it all?
有人能描述一下我应该如何在最新版本的Ubuntu的新安装上管理这一切的“最佳实践”吗?我应该安装什么,应该如何使用它?
I'm guessing that doing a sudo apt-get install ruby
is not be recommended, but I am not sure. I tried it on my system in addition to 'all the other Ruby stuff'. It's just adding to my confusion. I am not talking about Rails but just regular Ruby gems (e.g. Vagrant, Chef, scripts).
我猜想,做一个sudo apt-get安装ruby是不可取的,但我不确定。除了“所有其他Ruby内容”之外,我还在我的系统上试用了它。这只是增加了我的困惑。我说的不是Rails,而是普通的Ruby gem(例如:Vagrant, Chef, scripts)。
2 个解决方案
#1
132
As per the previous answer, this is quite a lot to cover, so consider this a short introduction.
正如前面的答案一样,这需要大量的介绍,因此请将其视为一个简短的介绍。
gems are the way Ruby libraries are packaged. They are to Ruby what jars are to Java. Inside a gem file, you find Ruby code (.rb files), but also tests, and a special file giving information on the gem itself, such as its name, dependencies and version (gemspec). Any Ruby project can define the gems it needs via a Gemfile that just need to declare dependencies. Rubygems is the name of the package manager - the tool used to install the packages (while the gems are the packages themselves). Rubygems is now part of Ruby.
gems是Ruby库的打包方式。它们对于Ruby就像jar对于Java一样。在gem文件中,您可以找到Ruby代码(。还有测试和一个特殊的文件,提供关于gem本身的信息,比如它的名称、依赖项和版本(gemspec)。任何Ruby项目都可以通过只需声明依赖项的Gemfile定义它需要的gem。Rubygems是包管理器的名称——用来安装包的工具(gem是包本身)。Rubygems现在是Ruby的一部分。
Bundler is what make managing gems bearable. Based on your Gemfile, a simple call to bundler using bundle install will download and install all the required gems. Using standard gem command, you would have to install each of them manually, using gem install <gem_name>
. Bundler is not part of Ruby (it is itself packaged as a gem), but it a "de facto standard" for most applications (you will not find many people not using it, and no good reasons not to use it, actually).
Bundler正是使管理宝石成为可以忍受的。根据Gemfile,使用bundle install简单地调用bundler,将下载并安装所有必需的gems。使用标准的gem命令,您必须手动安装它们,使用gem安装
RVM is a tool allowing you to install multiple versions of Ruby on a machine, switching between them when needed. This can be used to install both a Ruby 1.8 and 1.9, or even a "MRI" (Matz's Ruby, the default implementation) and alternatives (such as JRuby or Rubinius). Note that RVM is not alone in this field, see for instance rbenv.
RVM是一种工具,允许您在一台机器上安装多个版本的Ruby,在需要时在它们之间进行切换。这可以用于安装Ruby 1.8和1.9,甚至“MRI”(Matz的Ruby,默认实现)和替代(如JRuby或Rubinius)。请注意,在这个字段中并不只有RVM,例如rbenv。
A gemset in RVM is a set of gems specific to a given context, typically a project. This is useful if you are for example developing different applications, each with its own sets of gems, and want to keep them separate.
RVM中的gemset是特定于给定上下文(通常是项目)的一组gems。如果您正在开发不同的应用程序(每个应用程序都有自己的gem集)并希望保持它们的独立性,那么这将非常有用。
system Ruby is, when using RVM, the Ruby version installed on the machine (ie, not via RVM).
系统Ruby在使用RVM时是安装在机器上的Ruby版本(即不是通过RVM)。
If you are just starting, gems and bundler are of interest to you. You can let RVM and gemsets aside for now.
如果你刚刚开始,你就会对gems和bundler感兴趣。你现在可以把RVM和gemset放在一边。
#2
1
You're asking for more information in one question than is in-scope for Stack Overflow. To cover it all would take a book.
您在一个问题中要求的信息比堆栈溢出范围内的信息要多。要盖住这一切需要一本书。
On Ubuntu it's easy to install and remove gems to the "system" version of Ruby, so get used to installing and removing regular gems via sudo
. (On Mac OS I'd give different advice because Apple bundles Ruby for their own use and it's not a great idea to mess with it.) Then, when you have an idea how the whole gem idea works, and you know you want multiple Ruby versions on your system, try "rbenv" or "RVM" and install a version or two in your sandbox.
在Ubuntu上,很容易将gems安装和移除到Ruby的“系统”版本中,所以要习惯通过sudo安装和移除常规的gems。(在Mac OS上,我会给出不同的建议,因为苹果将Ruby打包供自己使用,搞砸不是一个好主意。)然后,当您了解整个gem想法是如何工作的,并且您知道您想要在您的系统上有多个Ruby版本时,可以尝试“rbenv”或“RVM”,并在沙箱中安装一个或两个版本。
Linux makes it easy to add/remove Ruby via a distribution, but we're limited to the versions the distro maintainers have packaged, so I usually install from source. But, that's a pain when managing several versions of Ruby for development, test and production systems, which is why rbenv and RVM were invented -- they handle the dirty detail allowing us to concentrate on programming.
Linux使得通过发行版添加/删除Ruby变得很容易,但是我们仅限于发行版维护人员打包的版本,所以我通常从源代码安装。但是,当管理用于开发、测试和生产系统的多个Ruby版本时,这是一件痛苦的事情,这就是为什么要发明rbenv和RVM——它们处理肮脏的细节,允许我们专注于编程。
I've used both rbenv and RVM, and have been using rbenv for the last six months or so, with good results. It's less complicated than RVM which I like. In either case they make it easy to have different versions installed, with separate sets of Gems. You can have different Ruby versions open in different terminal windows if you want, making it easy to test for compatibility.
我已经使用了rbenv和RVM,并且使用rbenv已经有六个月了,效果很好。它没有我喜欢的RVM那么复杂。无论哪种情况,它们都使得安装不同版本的gem变得很容易,并且可以使用不同的gem集。如果您愿意,可以在不同的终端窗口中打开不同的Ruby版本,这使得测试兼容性变得很容易。
Rule one when debugging is to make changes one at a time, which is true for learning to program or learning a new language. Don't be distracted, just keep it simple.
规则一,调试是每次改变一个,这对于学习编程或学习一门新语言是正确的。不要分心,保持简单。
#1
132
As per the previous answer, this is quite a lot to cover, so consider this a short introduction.
正如前面的答案一样,这需要大量的介绍,因此请将其视为一个简短的介绍。
gems are the way Ruby libraries are packaged. They are to Ruby what jars are to Java. Inside a gem file, you find Ruby code (.rb files), but also tests, and a special file giving information on the gem itself, such as its name, dependencies and version (gemspec). Any Ruby project can define the gems it needs via a Gemfile that just need to declare dependencies. Rubygems is the name of the package manager - the tool used to install the packages (while the gems are the packages themselves). Rubygems is now part of Ruby.
gems是Ruby库的打包方式。它们对于Ruby就像jar对于Java一样。在gem文件中,您可以找到Ruby代码(。还有测试和一个特殊的文件,提供关于gem本身的信息,比如它的名称、依赖项和版本(gemspec)。任何Ruby项目都可以通过只需声明依赖项的Gemfile定义它需要的gem。Rubygems是包管理器的名称——用来安装包的工具(gem是包本身)。Rubygems现在是Ruby的一部分。
Bundler is what make managing gems bearable. Based on your Gemfile, a simple call to bundler using bundle install will download and install all the required gems. Using standard gem command, you would have to install each of them manually, using gem install <gem_name>
. Bundler is not part of Ruby (it is itself packaged as a gem), but it a "de facto standard" for most applications (you will not find many people not using it, and no good reasons not to use it, actually).
Bundler正是使管理宝石成为可以忍受的。根据Gemfile,使用bundle install简单地调用bundler,将下载并安装所有必需的gems。使用标准的gem命令,您必须手动安装它们,使用gem安装
RVM is a tool allowing you to install multiple versions of Ruby on a machine, switching between them when needed. This can be used to install both a Ruby 1.8 and 1.9, or even a "MRI" (Matz's Ruby, the default implementation) and alternatives (such as JRuby or Rubinius). Note that RVM is not alone in this field, see for instance rbenv.
RVM是一种工具,允许您在一台机器上安装多个版本的Ruby,在需要时在它们之间进行切换。这可以用于安装Ruby 1.8和1.9,甚至“MRI”(Matz的Ruby,默认实现)和替代(如JRuby或Rubinius)。请注意,在这个字段中并不只有RVM,例如rbenv。
A gemset in RVM is a set of gems specific to a given context, typically a project. This is useful if you are for example developing different applications, each with its own sets of gems, and want to keep them separate.
RVM中的gemset是特定于给定上下文(通常是项目)的一组gems。如果您正在开发不同的应用程序(每个应用程序都有自己的gem集)并希望保持它们的独立性,那么这将非常有用。
system Ruby is, when using RVM, the Ruby version installed on the machine (ie, not via RVM).
系统Ruby在使用RVM时是安装在机器上的Ruby版本(即不是通过RVM)。
If you are just starting, gems and bundler are of interest to you. You can let RVM and gemsets aside for now.
如果你刚刚开始,你就会对gems和bundler感兴趣。你现在可以把RVM和gemset放在一边。
#2
1
You're asking for more information in one question than is in-scope for Stack Overflow. To cover it all would take a book.
您在一个问题中要求的信息比堆栈溢出范围内的信息要多。要盖住这一切需要一本书。
On Ubuntu it's easy to install and remove gems to the "system" version of Ruby, so get used to installing and removing regular gems via sudo
. (On Mac OS I'd give different advice because Apple bundles Ruby for their own use and it's not a great idea to mess with it.) Then, when you have an idea how the whole gem idea works, and you know you want multiple Ruby versions on your system, try "rbenv" or "RVM" and install a version or two in your sandbox.
在Ubuntu上,很容易将gems安装和移除到Ruby的“系统”版本中,所以要习惯通过sudo安装和移除常规的gems。(在Mac OS上,我会给出不同的建议,因为苹果将Ruby打包供自己使用,搞砸不是一个好主意。)然后,当您了解整个gem想法是如何工作的,并且您知道您想要在您的系统上有多个Ruby版本时,可以尝试“rbenv”或“RVM”,并在沙箱中安装一个或两个版本。
Linux makes it easy to add/remove Ruby via a distribution, but we're limited to the versions the distro maintainers have packaged, so I usually install from source. But, that's a pain when managing several versions of Ruby for development, test and production systems, which is why rbenv and RVM were invented -- they handle the dirty detail allowing us to concentrate on programming.
Linux使得通过发行版添加/删除Ruby变得很容易,但是我们仅限于发行版维护人员打包的版本,所以我通常从源代码安装。但是,当管理用于开发、测试和生产系统的多个Ruby版本时,这是一件痛苦的事情,这就是为什么要发明rbenv和RVM——它们处理肮脏的细节,允许我们专注于编程。
I've used both rbenv and RVM, and have been using rbenv for the last six months or so, with good results. It's less complicated than RVM which I like. In either case they make it easy to have different versions installed, with separate sets of Gems. You can have different Ruby versions open in different terminal windows if you want, making it easy to test for compatibility.
我已经使用了rbenv和RVM,并且使用rbenv已经有六个月了,效果很好。它没有我喜欢的RVM那么复杂。无论哪种情况,它们都使得安装不同版本的gem变得很容易,并且可以使用不同的gem集。如果您愿意,可以在不同的终端窗口中打开不同的Ruby版本,这使得测试兼容性变得很容易。
Rule one when debugging is to make changes one at a time, which is true for learning to program or learning a new language. Don't be distracted, just keep it simple.
规则一,调试是每次改变一个,这对于学习编程或学习一门新语言是正确的。不要分心,保持简单。