RVM - HVboom/HowTo-DigitalOcean GitHub Wiki

Description

Ruby Version Manager (RVM)

RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

:speech_balloon: copied from home page

Setup RVM on Ubuntu

  • Follow the instruction to setup RVM as suggested on the RVM Homepage

    • In addition the Rails developer need to be in the groups rvm and sudo to be able to install Ruby versions
  • Install the latest ruby version rvm install ruby-3.3.5

Integration with VSCode

  • Add the rvm group to the vscode user: sudo usermod -aG rvm vscode

  • Adjust the code-server to run with group rvm by modifying the configuration /usr/lib/systemd/system/[email protected]:

    sudo vi /usr/lib/systemd/system/[email protected]
    
    ===
    
    [Unit]
    Description=code-server
    After=network.target
    
    [Service]
    Type=exec
    ExecStart=/usr/bin/code-server
    Restart=always
    User=%i
    Group=rvm
    
    [Install]
    WantedBy=default.target
    
    ===
    
    sudo systemctl daemon-reload
    sudo systemctl restart code-server@vscode
    

Set correct file permissions for the RVM directory

This is necessary because otherwise VSCode extensions, like Ruby LSP or RuboCop cannot be installed correctly

```Bash
# RVM installation directory
cd /usr/share

# Access for User and Group only
sudo chmod -R o-rwx rvm
# Ensure write and execution rights for the group
sudo chmod -R g+rwX rvm
# All files belong to the group rvm
sudo chgrp -R rvm rvm
# Newly created files and directory automatically belong to group rvm as well
sudo chmod -R g+s rvm
```

Setup RVM on FreeBSD

  • Follow the instruction to setup RVM:

    • Install GnuPG to verify the signed applications

      GnuPG is a complete and free replacement for PGP. Because it does not use the patented IDEA algorithm, it can be used without any restrictions. GnuPG is an RFC2440 (OpenPGP) compliant application.

      :speech_balloon: copied from package description

      sudo pkg install gnupg
      
    • Import GPG for RVM (see RVM security)

      \curl -sSL https://rvm.io/mpapis.asc | gpg --import -
      
      > gpg: directory '/home/freebsd/.gnupg' created
      > gpg: new configuration file '/home/freebsd/.gnupg/gpg.conf' created
      > gpg: WARNING: options in '/home/freebsd/.gnupg/gpg.conf' are not yet active during this run
      > gpg: keybox '/home/freebsd/.gnupg/pubring.kbx' created
      > gpg: /home/freebsd/.gnupg/trustdb.gpg: trustdb created
      > gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <[email protected]>" imported
      > gpg: Total number processed: 1
      > gpg:               imported: 1
      
    • Install RVM installer (see RVM security)

      cd $HOME/bin
      \curl -O https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer
      chmod ug+x rvm-installer
      \curl -O https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer.asc
      
      gpg --verify rvm-installer.asc
      
      > gpg: assuming signed data in 'rvm-installer'
      > gpg: Signature made Tue Apr 14 02:05:41 2015 CEST using RSA key ID BF04FF17
      > gpg: Good signature from "Michal Papis (RVM signing) <[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: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
      >      Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
      
    • Install RVM

      I change following options in contrast to the tutorial:

      1. use the rvm-installer script
      2. do not pollute my $HOME directory with unnecessary dot-files - see next step for $HOME/.profile enhancement
      3. because I currently do not understand the necessity of a rvm group, I do not pass the option --add-to-rvm-group to the installer script
      cd $HOME
      rvm-installer --verify-downloads --ignore-dotfiles stable
      
      # source necessary RVM scripts into current shell environment
      source $HOME/.rvm/scripts/rvm
      
      # test installation
      type rvm | head -n 1
      
      > rvm is a function
      
    • Enhance your $HOME/.profile to enable RVM automatically

      if [ `echo "$PATH" | grep -c "/usr/local/bin"` == 0 ] 
      then
        export PATH="$PATH:/usr/local/bin" # Add standard commands to PATH
      fi
      
      if [ `echo "$PATH" | grep -c "/usr/local/share/bin"` == 0 ] 
      then
        export PATH="$PATH:/usr/local/share/bin" # Add shared commands to PATH
      fi
      
      if [ `echo "$PATH" | grep -c "$HOME/.rvm/bin"` == 0 ] 
      then
        export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
      fi
      
      if [ -z $FIRST_RUN ]
      then
        export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
      
        [ -s "$HOME/.rvm/scripts/rvm" ](/HVboom/HowTo-DigitalOcean/wiki/--s-"$HOME/.rvm/scripts/rvm"-) && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
        [ -r "$rvm_path/scripts/completion" ](/HVboom/HowTo-DigitalOcean/wiki/--r-"$rvm_path/scripts/completion"-) && source "$rvm_path/scripts/completion" # Enable completion of ram commands
      fi
      
      • Tip: I created a template file in /usr/local/share/bash/.profile which is automatically copied, if such a file does not exists in the users home directory (see /usr/local/share/bash/profile)
  • Prepare RVM to use project specific configurations (see .rvmrc)

    # Install the requested Ruby version automatically
    rvm_install_on_use_flag=1
    # Fallback to the default ruby version
    rvm_project_rvmrc_default=1
    # Automatically use bundler, if a Gemfile is found
    rvm_autoinstall_bundler_flag=1
    
    • Tip: I created a template file in /usr/local/share/bash/.rvmrc which is automatically copied, if such a file does not exists in the users home directory (see /usr/local/share/bash/profile)
  • Remove RVM warning, when using project specific Gemfiles rvm rvmrc warning ignore allGemfiles

Setup script to install RVM into a users home directory

  • Store the script in /usr/local/share/bin/setup_rvm

    #!/usr/bin/env bash
    
    # Setup script for RVM (Ruby Version Manager) into a user home
    
    ## Get signed version
    
    cd $HOME
    # Import public key used to sign RVM
    \curl -sSL https://rvm.io/mpapis.asc | gpg --import -
    
    cd $HOME/bin
    # Load the installer and the signature file
    \curl -O https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer
    chmod ug+x rvm-installer
    \curl -O https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer.asc
    
    # Verify the signature
    gpg --verify rvm-installer.asc
    
    
    ## Install latest stable version of RVM
    
    cd $HOME
    $HOME/bin/rvm-installer --verify-downloads 0 --ignore-dotfiles stable
    
    # source necessary RVM scripts into current shell environment
    source $HOME/.rvm/scripts/rvm
    
    # test installation
    type rvm | head -n 1 | grep -q "rvm is a function"
    success=$?
    if [ $success ]
    then
      echo "Successful installation of RVM"
      echo ''
      echo ''
    
      # amend .profile
      if ! [ -e "$HOME/.profile" ](/HVboom/HowTo-DigitalOcean/wiki/--e-"$HOME/.profile"-)
      then
        touch "$HOME/.profile" >/dev/null 2>&1
    
        echo 'if [ `echo "$PATH" | grep -c "/usr/local/bin"` == 0 ]'                    >> $HOME/.profile
        echo 'then'                                                                     >> $HOME/.profile
        echo '  export PATH="$PATH:/usr/local/bin" # Add standard commands to PATH'     >> $HOME/.profile
        echo 'fi'                                                                       >> $HOME/.profile
        echo ''                                                                         >> $HOME/.profile
        echo 'if [ `echo "$PATH" | grep -c "/usr/local/share/bin"` == 0 ]'              >> $HOME/.profile
        echo 'then'                                                                     >> $HOME/.profile
        echo '  export PATH="$PATH:/usr/local/share/bin" # Add shared commands to PATH' >> $HOME/.profile
        echo 'fi'                                                                       >> $HOME/.profile
        echo ''                                                                         >> $HOME/.profile
        echo 'if [ `echo "$PATH" | grep -c "$HOME/.rvm/bin"` == 0 ]'                    >> $HOME/.profile
        echo 'then'                                                                     >> $HOME/.profile
        echo '  export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting'     >> $HOME/.profile
        echo 'fi'                                                                       >> $HOME/.profile
        echo ''                                                                         >> $HOME/.profile
        echo [ -s "$HOME/.rvm/scripts/rvm" ](/HVboom/HowTo-DigitalOcean/wiki/--s-"$HOME/.rvm/scripts/rvm"-)        && source "$HOME/.rvm/scripts/rvm"        # Load RVM into a shell session *as a function*' >> $HOME/.profile
        echo [ -s "$HOME/.rvm/scripts/completion" ](/HVboom/HowTo-DigitalOcean/wiki/--s-"$HOME/.rvm/scripts/completion"-) && source "$HOME/.rvm/scripts/completion" # Enable completion of rvm commands'             >> $HOME/.profile
    
        echo 'Following lines added to your .profile:'
      else
        echo 'Add following lines to your .profile to use RVM automatically:'
      fi
      echo ''
      echo 'if [ `echo "$PATH" | grep -c "/usr/local/bin"` == 0 ]'                 
      echo 'then'                                                                  
      echo '  export PATH="$PATH:/usr/local/bin" # Add standard commands to PATH' 
      echo 'fi'                                                                    
      echo ''                                                                      
      echo 'if [ `echo "$PATH" | grep -c "/usr/local/share/bin"` == 0 ]'
      echo 'then'
      echo '  export PATH="$PATH:/usr/local/share/bin" # Add shared commands to PATH'
      echo 'fi'
      echo ''
      echo 'if [ `echo "$PATH" | grep -c "$HOME/.rvm/bin"` == 0 ]'                
      echo 'then'                                                                  
      echo '  export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting'  
      echo 'fi'                                                                    
      echo ''                                                                      
      echo [ -s "$HOME/.rvm/scripts/rvm" ](/HVboom/HowTo-DigitalOcean/wiki/--s-"$HOME/.rvm/scripts/rvm"-)        && source "$HOME/.rvm/scripts/rvm"        # Load RVM into a shell session *as a function*'
      echo [ -r "$HOME/.rvm/scripts/completion" ](/HVboom/HowTo-DigitalOcean/wiki/--r-"$HOME/.rvm/scripts/completion"-) && source "$HOME/.rvm/scripts/completion" # Enable completion of rvm commands'
      echo ''
      echo ''
    
      # amend .rvmrc - see https://rvm.io/workflow/projects#rvm-configuration
      if ! [ -e "$HOME/.rvmrc" ](/HVboom/HowTo-DigitalOcean/wiki/--e-"$HOME/.rvmrc"-)
      then
        touch "$HOME/.rvmrc" >/dev/null 2>&1
    
        echo 'rvm_install_on_use_flag=1      # Install the requested Ruby version automatically' >> $HOME/.rvmrc
        echo 'rvm_project_rvmrc_default=1    # Fallback to the default ruby version'             >> $HOME/.rvmrc
        echo 'rvm_autoinstall_bundler_flag=1 # Automatically use bundler, if a Gemfile is found' >> $HOME/.rvmrc
    
        echo 'Following lines added to your .rvmrc:'
      else
        echo 'Add following lines to your .rvmrc to use RVM efficiently:'
      fi
      echo ''
      echo 'rvm_install_on_use_flag=1      # Install the requested Ruby version automatically'
      echo 'rvm_project_rvmrc_default=1    # Fallback to the default ruby version'
      echo 'rvm_autoinstall_bundler_flag=1 # Automatically use bundler, if a Gemfile is found'
      echo ''
      echo ''
    else
      echo "Error during installation of RVM - $success"
      echo ''
      echo ''
    fi
    
  • Run the setup script: /usr/local/share/bin/setup_rvm