Difference between revisions of "Ruby"

From Ever changing code
Jump to navigation Jump to search
Line 6: Line 6:


# Install RVM - Ruby Version Manager
# Install RVM - Ruby Version Manager
sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
sudo apt-get install -y curl gnupg2 build-essential
curl -sSL https://get.rvm.io | sudo bash -s stable
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
sudo usermod -a -G rvm `whoami`


# Install
# Install RVM stable with ruby:
curl -sSL https://get.rvm.io | bash -s stable --ruby # can take ~10 min as it's compiling sources
</source>
 
 
To start using RVM you need to run <code>source /home/vagrant/.rvm/scripts/rvm</code> in all your open shell windows, in rare cases you need to reopen all shell windows.
<source lang=bash>
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`
</source>
 
 
Use RVM to install Ruby version you want <code>ruby-X.X.X</code>
*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
<source lang=bash>
rvm install ruby-2.1.0
rvm --default use ruby-X.X.X
</source>
 
# Install Bundler
gem install bundler --no-rdoc --no-ri
</source>
 
 
Optional install using OS package manager, rarely working
<source lang=bash>
sudo apt-get install ruby ruby-dev
sudo apt-get install ruby ruby-dev
</source>
# Install dependencies
 
bundler install  
 
Install dependencies, uses project's Gemfile
<source lang=bash>
bundler install     #installs gems and their dependencies
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
</source>
</source>



Revision as of 22:23, 28 February 2019

Ruby adventures...

Install

#Pre requsites
sudo apt-get install -y curl gnupg build-essential

# 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>


Optional install using OS package manager, rarely working

sudo apt-get install ruby ruby-dev


Install dependencies, uses project's Gemfile

bundler install      #installs gems and their dependencies
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

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/