Difference between revisions of "Ruby"

From ArchWiki
Jump to: navigation, search
(Add i18n Template)
(http -> https://aur.archlinux.org)
Line 50: Line 50:
 
You can install {{AUR|ruby1.8.6-legacy}} from the [[AUR]].  
 
You can install {{AUR|ruby1.8.6-legacy}} from the [[AUR]].  
  
RubyGems is not included with the ruby1.8.6-legacy package, so install [http://aur.archlinux.org/packages.php?ID=33312 rubygems] from the [[AUR]].
+
RubyGems is not included with the ruby1.8.6-legacy package, so install [https://aur.archlinux.org/packages.php?ID=33312 rubygems] from the [[AUR]].
  
 
{{Note|This package will replace the official {{Pkg|ruby}} package, as installing both Ruby 1.8 and 1.9, while possible, can cause erratic behavior of some 3rd party code.}}
 
{{Note|This package will replace the official {{Pkg|ruby}} package, as installing both Ruby 1.8 and 1.9, while possible, can cause erratic behavior of some 3rd party code.}}

Revision as of 19:24, 24 March 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Ruby is a dynamic, interpreted, open source programming language with a focus on simplicity and productivity.

Installing Ruby

The version of Ruby you need to install depends on your requirements, as not all 3rd party code is compatible with all versions. Here is a summary of the versions below and how to get them:

Ruby 1.9 (Development)

Summary: Use Ruby 1.9 for a new Rails project, or when you are sure all your required gems are supported by Ruby 1.9

Pros:

  • Vastly improved performance over 1.8
  • New features for concurrency such as fibers.
  • Various other language improvements, such as an improved CSV parser.

Cons:

  • Not compatible with many older gems (and Ruby On Rails versions prior to 2.3)
  • Changes in the language might cause older Ruby code not to run, or exhibit unexpected bugs.
Note: Visit http://isitruby19.com/ to determine if the gems/modules you require are compatible with Ruby 1.9.

To install Ruby 1.9, simply install ruby.

Ruby 1.9 also includes RubyGems (detailed below), so you can easily update to the latest RubyGems using:

# gem update --system

Ruby 1.8.7 (Stable)

Summary: Use Ruby 1.8.7 if you are unsure, or are not working on any legacy systems.

Pros:

  • Latest version of the 1.8 branch, capable of running most if not all recently updated gems and Ruby On Rails

Cons:

  • Introduces certain breaking changes from 1.8.6, which causes older lesser-maintained gems and Rails prior to 2.0 not to work without "monkey patching".

You can install ruby-1.8.7-svnAUR or ruby1.8AUR from the AUR.

RubyGems is not included with the ruby1.8AUR package, so install rubygems1.8AUR from the AUR.

Ruby 1.8.6 (Legacy)

Summary: Use Ruby 1.8.6 if you are working on old projects, older version of Rails (especially < 2.0), or simply want the least possible issues.

Pros:

  • Compatible with just about anything

Cons:

  • Missing some performance and language enhancements from 1.8.7
  • Support might be dropped with Rails 3.0 (in Beta at the time of writing)

You can install ruby1.8.6-legacyAUR from the AUR.

RubyGems is not included with the ruby1.8.6-legacy package, so install rubygems from the AUR.

Note: This package will replace the official ruby package, as installing both Ruby 1.8 and 1.9, while possible, can cause erratic behavior of some 3rd party code.

Multiple versions

If you want to run multiple versions on the same system (e.g. 1.9.1 and 1.8.7), the easiest way is to use RVM.

RubyGems

gem is the package manager of sorts for Ruby modules (called Gems), somewhat comparable to what pacman is to Arch Linux. The gem command will be installed if you followed the installation instructions above.

Running as root

When running gem as root, gems will be installed for everyone on the machine. This has the advantage of simplicity and is the most reliable method, but updating or installing gems without everyone's knowledge (like on a shared server) might cause Ruby applications to break.

When not running gem as root, the gems will be installed into ~/.gem and not affect anyone else, although it might be worth noting that not all gems are happy with be installed in this way, and might insist on being installed by root (especially if they have native extensions).

Bundler solves these problems to some extent by packaging gems into your application. See the section below on using bundler.

Updating RubyGems

# gem update --system

Installing a gem

This example installs the MySQL ruby gem:

# gem install mysql

The process can be sped up somewhat if you do not need local documentation:

# gem install mysql --no-rdoc --no-ri

The gem will now be downloaded, compiled if necessary, and installed.

Bundler

Bundler installs gems (including those with native extensions) directly into your application, which works very well for shared hosting and easy deployment of Ruby on Rails applications for example. Bundler also resolves dependencies as a whole, rather than individually like RubyGems, making things a lot easier.

It might be a good idea to install bundler as a system-wide gem so everyone can use it:

# gem install bundler

To start a new bundle:

$ bundle init

Then add your required gems into "Gemfile" in the current directory (created by bundle init):

Gemfile
gem "rails", "2.3.4"
gem "mysql"

Finally, run the following to install your gems:

$ bundle install

Or, alternatively, in order to install locally to vendor/bundle under the working directory:

$ bundle install --deployment

Managing RubyGems using pacman

Instead of using the gem command directly you can use pacman to manage the installed gems like normal packages. There are a lot of ruby packages available from AUR. Ruby packages follow the naming convention ruby-[gemname]. As an alternative you can use the tool pacgem which automatically creates arch packages from gems and installs them afterwards using pacman.

See also

References