# File src/ruby_supportlib/phusion_passenger/platform_info/ruby.rb, line 60
    def self.ruby_command
      # Detect usage of gem-wrappers: https://github.com/rvm/gem-wrappers
      # This is currently used by RVM >= 1.25, although it's not exclusive to RVM.
      if GEM_HOME && File.exist?("#{GEM_HOME}/wrappers/ruby")
        return "#{GEM_HOME}/wrappers/ruby"
      end

      if in_rvm?
        # Detect old-school RVM wrapper script location.
        name = rvm_ruby_string
        dirs = rvm_paths
        if name && dirs
          dirs.each do |dir|
            filename = "#{dir}/wrappers/#{name}/ruby"
            if File.exist?(filename)
              contents = File.open(filename, 'rb') do |f|
                f.read
              end
              # Old wrapper scripts reference $HOME which causes
              # things to blow up when run by a different user.
              if contents.include?("$HOME")
                filename = nil
              end
            else
              filename = nil
            end
            if filename
              return filename
            end
          end

          # Correctness of these commands are confirmed by mpapis.
          # If we ever encounter a case for which this logic is not sufficient,
          # try mpapis' pseudo code:
          #
          #   rvm_update_prefix  = write_to rvm_path ? "" : "rvmsudo"
          #   rvm_gemhome_prefix  = write_to GEM_HOME ? "" : "rvmsudo"
          #   repair_command  = "#{rvm_update_prefix} rvm get stable && rvm reload && #{rvm_gemhome_prefix} rvm repair all"
          #   wrapper_command = "#{rvm_gemhome_prefix} rvm wrapper #{rvm_ruby_string} --no-prefix --all"
          case rvm_installation_mode
          when :single
            repair_command  = "rvm get stable && rvm reload && rvm repair all"
            wrapper_command = "rvm wrapper #{rvm_ruby_string} --no-prefix --all"
          when :multi
            repair_command  = "rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all"
            wrapper_command = "rvmsudo rvm wrapper #{rvm_ruby_string} --no-prefix --all"
          when :mixed
            repair_command  = "rvmsudo rvm get stable && rvm reload && rvm repair all"
            wrapper_command = "rvm wrapper #{rvm_ruby_string} --no-prefix --all"
          end

          STDERR.puts "Your RVM wrapper scripts are too old, or some " +
            "wrapper scripts are missing. Please update/regenerate " +
            "them first by running:\n\n" +
            "  #{repair_command}\n\n" +
            "If that doesn't seem to work, please run:\n\n" +
            "  #{wrapper_command}"
          exit 1
        else
          # Something's wrong with the user's RVM installation.
          # Raise an error so that the user knows this instead of
          # having things fail randomly later on.
          # 'name' is guaranteed to be non-nil because rvm_ruby_string
          # already raises an exception on error.
          STDERR.puts "Your RVM installation appears to be broken: the RVM " +
            "path cannot be found. Please fix your RVM installation " +
            "or contact the RVM developers for support."
          exit 1
        end
      else
        return ruby_executable
      end
    end