The wikis are now using the new authentication system.
If you did not migrate your account yet, visit https://idp-portal-info.suse.com/

User:Tsu2/Install Ruby

Jump to: navigation, search

Install Ruby on openSUSE

openSUSE versions

Although this Guide is written for 13.2 the instructions should be safe to follow for all currently supported versions of openSUSE, and possibly for all hardware platforms. If you are running on another version of openSUSE, simply edit the "13.2" in command line to match whatever your version is, and should work both forward and backwards.

When do I need to install Ruby?

Although some ruby tools and libraries may be included in a default openSUSE install, there will be scenarios where they are insufficient. The following is a short and incomplete list of situations where you will want to install a complete Ruby system

  • An app won't run, throwing a Ruby error, in particular "file not found"
  • You intend to Develop either Ruby apps, Ruby on Rails apps or other web frameworks based on Ruby like Jekyll which is the recommended framework deploying free websites on Github.

Major preliminary decision - openSUSE Ruby or Ruby from the official Ruby repos?

Although openSUSE provides ample support for various Ruby versions, it's also possible to install Ruby from the official Ruby repos as well. You may factor different reasons for your decision, like whether you intend to build only for yourself, for the openSUSE community or whether you are participating in a team with each member using a different distro (or even OS). Ruby is a cross-platform technology that runs on practically every OS in existence, this is both nice to build something that is not dependent on a hardware or OS platform, but may also mean that issues have to be anticipated during the planning stage.


Start Here!

Preamble

Because some generic applets from the Ruby repos don't work on openSUSE (in particular the very important bundle!) it's important to install openSUSE tools first, then continue to install the entire Ruby version from OSS or from the Ruby repos.

Add the special openSUSE Ruby repository

Execute the following command with root permissions which adds the repo and does a repo refresh to populate the local cache. Accept the GPG keys if prompted.

zypper ar http://download.opensuse.org/repositories/devel:/languages:/ruby:/extensions/openSUSE_Leap_15.0/ devel:languages:ruby:extensions && zypper ref

For those who may not be running openSUSE 13.2, you can open a web browser to the following URL to see the current supported OS. If you don't see your OS listed (and officially supported) you can still try something close on the chance it might provide just the gem and bundle tools you need to install everything else from the Ruby repos.
http://download.opensuse.org/repositories/devel:/languages:/ruby:/extensions/

Execute the command installing your basic tools

Execute the the following command with root permissions to install tools and nodejs which provides a javascript runtime. It also includes installing git if it's not already installed and additional generally recommended files. Remove any/all files from the list you do not wish to install.

zypper in ruby rubygem-bundler nodejs git    gcc make libopenssl-devel sqlite3-devel

Update March 2017: Ruby packages have changed slightly for openSUSE 42.2. Other openSUSE versions may similarly need to be modified.

zypper in ruby ruby2.1-rubygem-bundler nodejs4 git    gcc make libopenssl-devel sqlite3-devel

Update July 2018: Ruby packages have changed slightly for openSUSE LEAP 15. Other openSUSE versions may similarly need to be modified. Note also that system installed bundle/bundler is now managed by update-alternatives although if the official Ruby repository is onfigured, the bundle/bundler from there could be used. The bottom line for installing is to have a working version installed.

zypper in ruby ruby2.5-rubygem-bundler nodejs8 git    gcc libopenssl-devel sqlite3-devel

Install Ruby from the openSUSE repos

The following command installs the current latest Ruby from the openSUSE repos. If you intend to install Ruby from the Ruby repos, you can skip this step and go to the section describing installing from the Ruby repos.

zypper in ruby2.5 ruby2.5-devel rubygem-rubygems-update

Notice that openSUSE invokes different versions of Ruby in an unorthodox way. Instead of a generic "ruby" command, as of this writing the following is implemented

Now, Test your handiwork! Skip down to step 8 below, but remember anytime you invoke Ruby from now on, you'll need to use one of the two binaries below depending on what you have installed.

The full path is described below only for information but is not required because the binaries should already be in the system PATH.

Ruby 2.0

/usr/bin/ruby2.0

Ruby2.1

/usr/bin/ruby.ruby2.1

Install Ruby from the Ruby repos

The Necessary RVM vs RBENV choice

When you install Ruby from the Ruby repos, you should make an important decision first which Ruby Version Manager you intend to use so that you can easily switch between Ruby environments. If you don't use a version manager, you are pretty much locked into whatever version you install and any attempt to change involves great pain. Although RVM is very popular and typically installed by default, this Guide will describe using rbenv instead because unlike RVM, rbenv leaves all system commands untouched and uses "shims" to bridge functionality. The full documentation describing its architecture and User commands is an essential read at the following URL
The Official rbenv Project

Installing rbenv

These steps closely follow what is described at Laura Diane Hamilton's Blog which in turn is from the Official rbenv Documentation but are modified to incorporate current openSUSE methods and "Best Practices."

Important Notes
This guide describes installing rbenv in a subdirectory of the User's Home directory which is consistent with the official rbenv documentation, but the reader may notice that I describe creating a system (not user) path to the rbenv binary and the files installed from the Ruby repos. The advantage to this configuration is that the current User can "sudo" and "su" rataining full support to rbenv and its ruby packages. But, if the User prefers to invoke the root login (su -l or su --login), the current recommendation will fail without a slight modification because the $HOME variable would then re-point to the root home directory instead of continuing to point to the original User home directory.

So, if the User insists on using the root login command one of the two following modifications are required
A. Change the $HOME variable to explicitly describe the fixed path the the User home directory where rbenv is located
B. Locate rbenv in a system directory instead of the User directory. I would recommend a new subdirectory in /opt/ for safety reasons. Although it might make more sense to locate in one of the various lib or lib64 directories, if done incorrectly it could cause conflicts or damage to regular libraries.

This document has been updated several times over the years. Read each section including updates to gather all information that applies to your scenario (primarily version of openSUSE) before executing what is described.

Addendum March 2017
Required rbenv build prerequisites

zypper install automake gdbm-devel libyaml-devel ncurses-devel readline-devel zlib-devel


1. Open a console in your User's home directory (typically the default location when you first open a console). From that location, execute the following command

Icon-warning.png

The following 2 "git clone" commands must be done with ordinary User permissions, not root

.
git clone git://github.com/sstephenson/rbenv.git .rbenv

Update July 2018
- Configure support for BASH auto-complete(Execute as normal User)

cd ~/.rbenv && src/configure && make -C src

2. Install the "ruby-build" plugin for rbenv into a subdirectory of the above. This step is entirely optional but can enhance the experience of installing and removing different Ruby versions

Update July 2018
The Following command is now superceded by instructions at the following URL (choose the rbenv option)
https://github.com/rbenv/ruby-build#readme

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

3. Execute the following command which adds the new location to the system PATH.

Icon-warning.png

The following 2 commands write to a location outside the /Home partition so require "su" or "sudo" root permissions.

.
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> /etc/profile.local

4. Enable rbenv shims and autocompletion in the console

echo 'eval "$(rbenv init -)"' >> /etc/profile.local

5. Activate your system profile modifications which include your new PATH addition and integrating rbenv into your console immediately without a reboot.

Icon-warning.png

The following command should be executed using your normal, non-root User permissions.

.
source /etc/profile

6. Close and Re-start your Console

7. (Optional) Check your handiwork by running the following command

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

Install a Ruby

7. Install a Ruby. As of this writing there are two widely used and supported versions, 2.0 and 2.1.
Version 2.2.2 (with its openSSL patch) has very recently been released while 1.9 is still supported for legacy purposes.

# list all available versions:
rbenv install -l

rbenv install 2.5.1
rbenv rehash

Don't forget to run "rbenv rehash" to wire up your rbenv shims with your newly downloaded Ruby after the download has completed!
In fact, read the rbenv docs. You'll need to re-run "rbenv rehash" after any ruby update and new ruby install to ensure that your shims are wired properly.

8. Test.
First, you need to configure rbenv to apply your newly downloaded Ruby...
Note that you have 3 ways to apply any Ruby version...

  • Globally At this time, I have found that critical openSUSE apps like YAST which were written to earlier versions of Ruby are functioning just fine with the current latest (2.5.1). Kudos to the openSUSE contrbutors!
  • Local which means Application-specific
  • Shell which is specific to your console app.

Because I haven't found any problems running native openSUSE apps written in the most recent version of Ruby, so for now I recommend setting globally as follows

rbenv global 2.5.1

You can now verify your ruby version with the following rbenv command

rbenv version

And your overall system command

ruby -v

The orginal Laura Diane Hamilton's Blog describes setting up a Rails bootstrap, if a rails project is your objective then you can follow her blog, starting where she describes "Let's Make a New Project." Alternatively, I will describe how to setup a Jekyll Bootstrap static website complete with instructions for uploading and deploying to Github.

The current <very early> draft to install Jekyll on openSUSE and deploy to Github is located at
(Skip to Install Jekyll section)
Create a Free Jekyll blogging website on Github using openSUSE