Last active
March 25, 2022 06:36
-
-
Save githubfoam/e56de7745f1e8096b0d4a7abeb6de6d2 to your computer and use it in GitHub Desktop.
ruby cheat sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ============================================================================ | |
| # https://www.ruby-lang.org/en/documentation/installation/ | |
| ============================================================================ | |
| $ sudo snap install ruby --classic | |
| $ sudo apt-get install ruby-full | |
| $ sudo yum install ruby | |
| $ sudo pacman -S ruby | |
| $ pkg install ruby | |
| $ brew install ruby | |
| > choco install ruby | |
| > winget install Ruby | |
| ============================================================================ | |
| # Building from Source Operating System: Ubuntu 16.04.5 LTS | |
| $ whoami | |
| vagrant | |
| wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz | |
| tar xvfz ruby-2.5.1.tar.gz | |
| sudo ./configure | |
| sudo make | |
| sudo make install | |
| $ ruby -v | |
| ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] | |
| ============================================================================ | |
| # Building from Source Operating System: Ubuntu 16.04.5 LTS | |
| wget -q https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.gz | |
| tar xvfz ruby-2.7.0.tar.gz | |
| cd ruby-2.7.0 && sudo ./configure && sudo make && sudo make install | |
| ============================================================================ | |
| # Install Ruby Version Manager (RVM) Operating System: CentOS Linux 7 (Core) | |
| gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB | |
| $ gpg2 -k | |
| /home/vagrant/.gnupg/pubring.gpg | |
| -------------------------------- | |
| pub 4096R/D39DC0E3 2014-10-28 | |
| uid Michal Papis (RVM signing) <[email protected]> | |
| uid Michal Papis <[email protected]> | |
| uid [jpeg image of size 5015] | |
| sub 2048R/C71866D7 2015-11-02 | |
| sub 4096R/BF04FF17 2014-10-28 [expires: 2022-03-12] | |
| pub 4096R/39499BDB 2016-11-11 | |
| uid Piotr Kuczynski <[email protected]> | |
| sub 4096R/6521FF17 2016-11- | |
| ============================================================================ | |
| # Install Ruby Version Manager (RVM) Operating System: Ubuntu 16.04.5 LTS | |
| $ sudo apt-get install gnupg2 -y | |
| $ sudo gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB | |
| gpg: directory '/home/vagrant/.gnupg' created | |
| gpg: new configuration file '/home/vagrant/.gnupg/dirmngr.conf' created | |
| gpg: new configuration file '/home/vagrant/.gnupg/gpg.conf' created | |
| gpg: keybox '/home/vagrant/.gnupg/pubring.kbx' created | |
| gpg: /home/vagrant/.gnupg/trustdb.gpg: trustdb created | |
| gpg: key 39499BDB: public key "Piotr Kuczynski <[email protected]>" imported | |
| gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <[email protected]>" imported | |
| gpg: no ultimately trusted keys found | |
| gpg: Total number processed: 2 | |
| gpg: imported: 2 | |
| $ sudo gpg2 -k | |
| /home/vagrant/.gnupg/pubring.kbx | |
| -------------------------------- | |
| pub rsa4096/39499BDB 2016-11-11 [SC] | |
| uid [ unknown] Piotr Kuczynski <[email protected]> | |
| sub rsa4096/6521FF17 2016-11-11 [E] | |
| pub rsa4096/D39DC0E3 2014-10-28 [SC] | |
| uid [ unknown] Michal Papis (RVM signing) <[email protected]> | |
| uid [ unknown] Michal Papis <[email protected]> | |
| uid [ unknown] [jpeg image of size 5015] | |
| sub rsa2048/C71866D7 2015-11-02 [E] | |
| sub rsa4096/BF04FF17 2014-10-28 [S] [expires: 2022-03-12] | |
| $ \curl -sSL https://get.rvm.io | sudo bash -s stable #The Multi-User install instructions must be prefixed with the sudo command | |
| Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz | |
| Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc | |
| gpg: Signature made Wed 10 Jul 2019 08:31:02 AM UTC using RSA key ID 39499BDB | |
| gpg: Good signature from "Piotr Kuczynski <[email protected]>" [unknown] | |
| gpg: WARNING: This key is not certified with a trusted signature! | |
| gpg: There is no indication that the signature belongs to the owner. | |
| Primary key fingerprint: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB | |
| GPG verified '/usr/local/rvm/archives/rvm-1.29.9.tgz' | |
| Creating group 'rvm' | |
| Installing RVM to /usr/local/rvm/ | |
| Installation of RVM in /usr/local/rvm/ is almost complete: | |
| * First you need to add all users that will be using rvm to 'rvm' group, | |
| and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`. | |
| * To start using RVM you need to run `source /etc/profile.d/rvm.sh` | |
| in all your open shell windows, in rare cases you need to reopen all shell windows. | |
| * Please do NOT forget to add your users to the rvm group. | |
| The installer no longer auto-adds root or users to the rvm group. Admins must do this. | |
| Also, please note that group memberships are ONLY evaluated at login time. | |
| This means that users must log out then back in before group membership takes effect! | |
| Thanks for installing RVM ๐ | |
| Please consider donating to our open collective to help us maintain RVM. | |
| ๐ Donate: https://opencollective.com/rvm/donate | |
| \curl -sSL https://get.rvm.io | bash -s -- --version latest #Installing a specific version | |
| \curl -sSL https://get.rvm.io | bash -s -- --branch [owner/][repo] | |
| \curl -sSL https://get.rvm.io | bash -s -- --trace #Debugging installation process | |
| ============================================================================ | |
| $ irb | |
| irb(main):001:0> exit | |
| ============================================================================ | |
| (shell logout necessary) | |
| $ type rvm | head -1 | |
| $ rvm list known #List known rubies | |
| $ rvm get stable #Update RVM | |
| $ rvm get head #Update RVM In case of problems try first with development version | |
| $ rvm requirements #Install Ruby dependencies | |
| $ rvm install 1.9.3 #Install Ruby | |
| $ sudo rvm list # List rubies only | |
| $ sudo rvm list gemsets # List rubies and gemsets | |
| $ sudo rvm gemset list # List gemsets for current ruby | |
| $ sudo gem list --local | |
| rvm system # For system ruby, with fallback to default | |
| rvm use jruby # For current session only | |
| rvm use --default 1.9.3 # For current and new sessions | |
| rvm use --ruby-version rbx # For current session and this project | |
| rvm 1.8.7 do gem install rspec # Temporarily selecting another Ruby or gemset in the given ruby | |
| rvm 1.8.7,1.9.2 do gem install haml # Temporarily selecting another Ruby or gemset in this two rubies | |
| rvm @global do gem install gist # Temporarily selecting another Ruby or gemset in @global gemset of current ruby | |
| gem install rspec | |
| Working with gemsets: | |
| rvm use 1.8.7 # use the ruby to manage gemsets for | |
| rvm gemset create project_name # create a gemset | |
| rvm gemset use project_name # use a gemset in this ruby | |
| rvm gemset list # list gemsets in this ruby | |
| rvm gemset delete project_name # delete a gemset | |
| rvm 1.9.1@other_project_name # use another ruby and gemset | |
| rvm 1.9.3@_project --create --rvmrc # use and create gemset & .rvmrc | |
| ============================================================================ | |
| #Install ruby from source | |
| sudo zypper install gcc make | |
| wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz | |
| tar xvfz rubygems-2.7.6.tgz | |
| cd rubygems-2.7.6/ | |
| ./configure | |
| make | |
| sudo make install | |
| ruby -v | |
| ============================================================================ | |
| # Install ruby on ubuntu 18.04 (via rbenv package manager) | |
| # Install rbenv and Dependencies | |
| sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev -y | |
| git clone https://github.com/rbenv/rbenv.git ~/.rbenv | |
| #add ~/.rbenv/bin to your $PATH so that you can use rbenv's command line utility. | |
| echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc | |
| # adding ~/.rbenv/bin/rbenv init to your ~/.basrc file will let you load rbenv automatically | |
| echo 'eval "$(rbenv init -)"' >> ~/.bashrc | |
| exec $SHELL (or source ~/.bashrc) | |
| type rbenv | |
| # ruby-build is a command-line utility that makes it easy to install virtually any version of Ruby, from source | |
| # It is available as a plugin for rbenv that provides the rbenv install command, or as a standalone program | |
| # As an rbenv plugin | |
| mkdir -p "$(rbenv root)"/plugins | |
| git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build | |
| rbenv version | |
| rbenv versions | |
| # Installing Ruby with ruby-build | |
| rbenv install 2.5.3 | |
| # set it as default version of Ruby | |
| rbenv global 2.5.3 | |
| ruby -v | |
| #turn off local documentation generation by creating a file called ~/.gemrc | |
| echo "gem: --no-document" > ~/.gemrc | |
| # Bundler is a tool that manages gem dependencies for projects. | |
| gem install bundler | |
| gem env home | |
| # Updating rbenv | |
| cd ~/.rbenv | |
| git pull | |
| # Uninstalling Ruby versions | |
| rbenv uninstall 2.5.3 | |
| # Uninstalling rbenv | |
| vi ~/.bashrc | |
| # remove the following two lines | |
| export PATH="$HOME/.rbenv/bin:$PATH" | |
| eval "$(rbenv init -)" | |
| # remove rbenv and all installed Ruby versions with this command: | |
| rm -rf `rbenv root` | |
| ========================================================================================================== | |
| #Install rubygems | |
| wget https://rubygems.org/rubygems/rubygems-2.7.6.tgz | |
| tar xvfz rubygems-2.7.6.tgz | |
| cd rubygems-2.7.6/ | |
| ========================================================================================================== | |
| # Make your own gem, https://rubygems.org | |
| git clone https://github.com/qrush/hola.git | |
| rake -T | |
| rake test | |
| rake | |
| ========================================================================================================== | |
| gem --version | |
| bundler version | |
| ========================================================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment