Ruby

From GeilThings

Jump to: navigation, search
Ruby
Ruby logo.png
General
Version 2.0.0-p247
Stable 2.0.0-p247
Function Programming Language
Package Manager RubyGems
Environment Manager RVM
Scripts

Contents

General

RubyGems

  • List all installed Gems: gem query --local
  • To install a particular version of a ruby gem, use -v, e.g. gem install rspec -v 1.3.2

Web Frameworks written in Ruby

Installing Ruby

  • From source.
# Remove the pre-installed ruby, if any.
yum erase ruby
yum erase ruby-libs

# Install some needed libraries.
# For gem output: libyaml, libyaml-devel
yum install libyaml libyaml-devel
# For compiling against certain libraries:
yum install readline-devel ncurses-devel
yum install gdbm-devel libffi
 
NEWVERSION=1.9.2-p180
cd /opt
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-${NEWVERSION}.tar.bz2
bzip2 -d ruby-${NEWVERSION}.tar.bz2
tar -xvf ruby-${NEWVERSION}.tar
cd ruby-${NEWVERSION}
./configure
make
make install
 
# Create an alias.
alias ruby='/usr/local/bin/ruby'
# Add the line above also to /root/.bashrc and /home/username/.bashrc
  
# Create softlink to facilitate administration.
cd /opt
ln -s ruby-${NEWVERSION} /opt/ruby

Upgrade Ruby

RAWVERSION=`ruby -v`
OLDVERSION=`echo "$RAWVERSION" | grep -Po '^.*?\K(?<=ruby ).*?(?= )'`
echo $OLDVERSION
 
RAWNEWVERSION=`curl -sd "action=ask&query=[[Ruby]]|%3FStable&format=json" http://www.geilthings.com/api.php` 
NEWVERSION=`echo "$RAWNEWVERSION" | grep -Po '^.*?\K(?<=Stable\":\[\").*?(?=\")'`  
echo $NEWVERSION
 
NEWVERSION1=`echo "$NEWVERSION" | grep -Po '^.*?\K(?<=^).*?(?=\.)'`
NEWVERSION2=`echo "$NEWVERSION" | grep -Po '^.*?\K(?<=\.).*?(?=\.)'`
MAINVERSION=$NEWVERSION1.$NEWVERSION2
echo $MAINVERSION
 
cd /opt
wget http://ftp.ruby-lang.org/pub/ruby/${MAINVERSION}/ruby-${NEWVERSION}.tar.bz2
 
bzip2 -d ruby-${NEWVERSION}.tar.bz2
tar -xvf ruby-${NEWVERSION}.tar
 
# Set Python to default, just in case.
PYTHONHOME=/usr
 
# Disable (Comment the lines containing the configuration for) Ruby's Rack, 
# Phusion Passenger, and Ruby On Rails, in the httpd vhost .conf file.
# ...
# Restart Apache httpd.
 
cd /opt/ruby-${NEWVERSION}
./configure
make
make install clean
 
# Check.
ruby -v
 
gem --version
 
# Update installed gems.
gem update
 
gem update --system
 
gem --version
 
# ++++++++++++++ If there is a new version of Phusion Passenger, 
# it has to be reinstalled: +++++++++++++++++++++
passenger-install-apache2-module
 
# Check also the settings in httpd.conf and vhosts .conf file; 
# substitute the references to the passenger files by the new one.
# ...
 
# Enable Ruby's Rack and Phusion Passenger again in the httpd vhost .conf file.
# ...
 
# Restart Apache httpd.
httpd -k restart
 
# Test applications.
# Problems starting passenger (in httpd error_log file):
# PassengerLoggingAgent: error while loading shared libraries: 
# libcurl.so.4: cannot open shared object file
# Solution: Add /usr/local/lib (libcurl.so.4 is there) to the 
# LD_LIBRARY_PATH in /etc/profile; restart putty session.
 
httpd -k restart
 
# Stopped working. ruby -v returns now like 1.9.3p327, not 1.9.3-p327. TODO.
# mv /opt/ruby-${OLDVERSION} /opt/old_ruby-${OLDVERSION}

Issues

Error: /usr/local/lib/ruby/1.9.1/yaml.rb:56:in missing psych

gem --version
# /usr/local/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
# It seems your ruby installation is missing psych (for YAML output).
# To eliminate this warning, please install libyaml and reinstall your ruby.
# 1.8.5
gem update --system
 
# Check.
gem --version
# /usr/local/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
# It seems your ruby installation is missing psych (for YAML output).
# To eliminate this warning, please install libyaml and reinstall your ruby.
# 1.8.12
 
# So: install libyaml and libyaml-devel.
# Found in the epel repository
yum install libyaml libyaml-devel
 
# Reinstall ruby.
./configure
make
make install clean

Confusing: Ruby is everywhere

  • Ruby seems to be spread everywhere after installed under Linux and having used RubyGems, so to nuke ruby manually is not that easy and probably a bad idea. Some directories have names that do not correspond to the ruby version installed (Ruby 1.9.1 was never on the system; it maybe refers to RubyGems). Ruby 1.8.5 had been installed with yum and later removed (yum erase ruby and yum erase ruby-libs), however some 1.8 directories are still there. ???
# CentOS 5.6, 5.7; ruby 1.9.2p180
find / -name ruby
 
# Answer:
/usr/local/share/doc/ruby
/usr/local/bin/ruby
/usr/local/include/ruby-1.9.1/x86_64-linux/ruby
/usr/local/include/ruby-1.9.1/ruby
/usr/local/lib/ruby
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/ruby
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/test/ruby
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/ruby
/usr/local/lib/ruby/gems/1.9.1/doc/activesupport-3.0.9/rdoc/lib/active_support/ruby
/usr/lib64/ruby
/usr/lib/ruby
 
find / -name 1.8
 
# Answer:
/usr/lib64/ruby/1.8
/usr/lib/ruby/1.8
 
gem --version
# 1.8.5

Modules

  • watchr: https://github.com/mynyml/watchr. From the website: Watchr monitors a directory tree, and triggers a user defined action whenever an observed file is modified. Its most typical use is continuous testing, and as such it is a more flexible alternative to autotest.

Cloud

  • Fog: Ruby cloud services library (and RubyGem) to control many cloud services. It deals with both server cloud and storage based services and supports Amazon S3 and Rackspace Files, as well as servers and on Amazon EC2, Rackspace Servers, Terremark vCloud and Slicehost. Support is also available for Amazon ELB and SimpleDB -> [1], [2]

Versions

Software name Version number Version date
Ruby 1.9.3-p362
1.9.3-p286
1.9.3-p194
1.9.3-p125
1.9.3-p374
1.9.3-p385
1.9.3-p392
2.0.0-p0
2.0.0-p195
2.0.0-p247
26 December 2012
12 October 2012
20 April 2012
16 February 2012
15 January 2013
7 February 2013
22 February 2013
25 February 2013
18 May 2013
28 July 2013

Comments

blog comments powered by Disqus