Ruby

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

Installing Ruby

For the latest version of Ruby, install the ruby package.

To install IRB, install the ruby-irb package.

Multiple versions

If you want to run multiple versions on the same system (e.g. 2.0.0-p0 and 1.9.3-p392), the easiest way is to use one of RVM, chrubyAUR, rbenv, asdf-vmAUR.

Documentation

To make documentation available through the ri command-line tool, install ruby-rdoc and ruby-docs for the documentation itself. You can then query the docs with: , ri Array.pop etc. (much like man-pages)

JRuby

The Java implementation of Ruby, JRuby can be installed with the jruby package.

RubyGems

RubyGems is a package manager for Ruby modules (called gems), somewhat comparable to what pacman is to Arch Linux. It can be installed with the package, which is a dependency of ruby.

Setup

By default in Arch Linux, when running , gems are installed per-user (into ), instead of system-wide (into ). This is considered the best way to manage gems on Arch, because otherwise they might interfere with gems installed by Pacman.

The recommended way to setup that is by manually specifying your , which then can be appended to your $PATH environment variable in order to allow RubyGems binaries to be executed:

~/.profile
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$PATH:$GEM_HOME/bin"

This is required for executable gems to work without typing out the full location, although libraries will work without having to modify your path.

Use to view the current RubyGems environment:

$ gem env

Usage

To see what gems are installed:

$ gem list

To get information about a gem:

$ gem spec gem_name

By default, and use the option, which forces gem to search only the local system. This can be overridden with the flag. Thus, to search for the mysql2 gem:

$ gem list --remote mysql2

To install a gem:

$ gem install mysql2

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

$ gem install mysql2 --no-document

To update all installed gems:

$ gem update

Installing gems system-wide

Gems can be installed system wide by running the command as root, appended with the flag. This flag can be set as default by replacing --user-install by in (system-wide) or ~/.gemrc (per-user, overrides system-wide).

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

Bundler

Bundler allows you to specify which gems your application depends upon, and optionally which version those gems should be. Once this specification is in place, Bundler installs all required gems (including the full gem dependency tree) and logs the results for later inspection. By default, Bundler installs gems into a shared location, but they can also be installed directly into your application. When your application is run, Bundler provides the correct version of each gem, even if multiple versions of each gem have been installed. This requires a little bit of work: applications should be called with , and two lines of boilerplate code must be placed in your application's main executable.

To install Bundler:

$ gem install bundler

To start a new bundle:

$ bundle init

Then edit in the current directory (created by bundle init) and list your required gems:

Run the following to install gems into :

$ bundle install

Alternatively, run the following to install gems to in the working directory:

$ bundle config set --local path '.bundle'

Do not forget to edit your main executable:

Finally, run your program:

bundle exec main_executable_name.rb

Managing RubyGems using pacman

Instead of managing gems with , you can use pacman, or an AUR helper. Ruby packages follow the naming convention ruby-gemname.

This option provides the following advantages:

  • Gems are updated along with the rest of your system.
  • Installed gems are available system-wide, instead of being available only to the user who installed them.

Quarry

Quarry is a tool that allows to maintain a rubygems binary repository for Arch Linux, as an easier alternative to building packages manually from the AUR. The source is hosted at Github.

The repository is maintained by the Arch developer anatolik at https://pkgbuild.com/~anatolik/quarry/. It contains many popular gems and new gems can be added upon request.

See Unofficial user repositories#quarry to enable it.

Then install the required gem. The name of the package is ruby-gem name.

General questions can be asked at https://bbs.archlinux.org/viewtopic.php?id=182729.

Interactive Shell

Pry

Pry is a powerful alternative to the standard IRB shell for Ruby. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing.

$gem install pry
$pry
gollark: But unless you have an *actual security reason* I would disagree with that.
gollark: > This status code is commonly used when the server does not wish to reveal exactly why the request has been refused,That's the use I was talking about, I guess, but not always relevant.
gollark: 10.4.5 404 Not Found The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.
gollark: I can't ctrl+F that in RFC 2616.
gollark: It's one of those necessary-evil things if you have some security reason. Otherwise no.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.