Difference between revisions of "Ruby"

From Ever changing code
Jump to navigation Jump to search
Line 1: Line 1:
Ruby adventures...
Ruby adventures...
= Install =
= Install =
== Using package manager ==
Install Ruby using OS package manager it's rarely making usable for projects.
<source lang=bash>
<source lang=bash>
#Pre requsites
sudo apt-get install ruby ruby-dev
sudo apt-get install -y curl gnupg build-essential
</source>


== RVM Ruby Version Manager ==
<source lang=bash>
# Install RVM - Ruby Version Manager
# Install RVM - Ruby Version Manager
sudo apt-get install -y curl gnupg2 build-essential
sudo apt-get install -y curl gnupg2 build-essential
Line 40: Line 44:




Optional install using OS package manager, rarely working
Install dependencies, uses project's Gemfile
<source lang=bash>
<source lang=bash>
sudo apt-get install ruby ruby-dev
bundler install        #installs gems and their dependencies
bundler install --path #installs gems in ./path dir, much easier to remove them if something is wrong
                      #creates .bundle/config file that contains path to gems
</source>
</source>




Install dependencies, uses project's Gemfile
Control your gem bundles and other ussefulness
<source lang=bash>
<source lang=bash>
bundler install        #installs gems and their dependencies
bundler install --path #installs gems in ./path dir, much easier to remove them if something is wrong
                      #creates .bundle/config file that contains path to gems
bundle info kwalify  #display where a gem got installed
bundle info kwalify  #display where a gem got installed
   * kwalify (0.7.2)
   * kwalify (0.7.2)
Line 56: Line 59:
         Homepage: http://www.kuwata-lab.com/kwalify/
         Homepage: http://www.kuwata-lab.com/kwalify/
         Path: /home/vagrant/.rvm/gems/ruby-2.6.0/gems/kwalify-0.7.2
         Path: /home/vagrant/.rvm/gems/ruby-2.6.0/gems/kwalify-0.7.2
ruby -S gem list --local  #list all gems
</source>
</source>



Revision as of 10:55, 1 March 2019

Ruby adventures...

Install

Using package manager

Install Ruby using OS package manager it's rarely making usable for projects.

sudo apt-get install ruby ruby-dev

RVM Ruby Version Manager

# Install RVM - Ruby Version Manager
sudo apt-get install -y curl gnupg2 build-essential
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

# Install RVM stable with ruby:
curl -sSL https://get.rvm.io | bash -s stable --ruby # can take ~10 min as it's compiling sources


To start using RVM you need to run source /home/vagrant/.rvm/scripts/rvm in all your open shell windows, in rare cases you need to reopen all shell windows.

source /home/vagrant/.rvm/scripts/rvm #this in U18 adds following to your env
export PATH=$PATH:/home/vagrant/.rvm/bin #adds local rvm bin to your user path
rvm_user_install_flag=1
rvm_stored_umask=0002
rvm_loaded_flag=1

# Optional: sudo usermod -a -G rvm `whoami`


Use RVM to install Ruby version you want ruby-X.X.X

  • this will search your package management for version you ask if not found
  • will download sources and get it compiled
  • will remove undesired packages, rg. U18 libssl-dev to install libssl1.0-dev instead
rvm install ruby-2.1.0
rvm --default use ruby-X.X.X
  1. Install Bundler

gem install bundler --no-rdoc --no-ri </source>


Install dependencies, uses project's Gemfile

bundler install        #installs gems and their dependencies
bundler install --path #installs gems in ./path dir, much easier to remove them if something is wrong
                       #creates .bundle/config file that contains path to gems


Control your gem bundles and other ussefulness

bundle info kwalify  #display where a gem got installed
  * kwalify (0.7.2)
        Summary: a parser, schema validator, and data-binding tool for YAML and JSON.
        Homepage: http://www.kuwata-lab.com/kwalify/
        Path: /home/vagrant/.rvm/gems/ruby-2.6.0/gems/kwalify-0.7.2

ruby -S gem list --local  #list all gems

Basic file structure

#!/usr/bin/env ruby

# require 'yaml'
require 'fileutils'

file_name="file.txt"

# #{file_name} -: string interpolation
FileUtils.touch("#{file_name}.OK")

The require dependencies need to be installed using

sudo apt  install ruby-bundler
bundle install       #default, but NEVER RUN AS SUDO
bundle install -path #installs gems into ~/.path/