    # File lib/rubygems/commands/update_command.rb, line 47
      def execute
        if options[:system] then
          say "Updating RubyGems"

          unless options[:args].empty? then
            fail "No gem names are allowed with the --system option"
          end

          options[:args] = ["rubygems-update"]
        else
          say "Updating installed gems"
        end

        hig = {} # highest installed gems

        Gem.source_index.each do |name, spec|
          if hig[spec.name].nil? or hig[spec.name].version < spec.version then
            hig[spec.name] = spec
          end
        end

        gems_to_update = which_to_update hig, options[:args]

        updated = []

        installer = Gem::DependencyInstaller.new options

        gems_to_update.uniq.sort.each do |name|
          next if updated.any? { |spec| spec.name == name }

          say "Updating #{name}"
          installer.install name

          installer.installed_gems.each do |spec|
            updated << spec
            say "Successfully installed #{spec.full_name}"
          end
        end

        if gems_to_update.include? "rubygems-update" then
          latest_ruby_gem = remote_gemspecs.select do |s|
            s.name == 'rubygems-update'
          end

          latest_ruby_gem = latest_ruby_gem.sort_by { |s| s.version }.last

          say "Updating version of RubyGems to #{latest_ruby_gem.version}"
          installed = do_rubygems_update latest_ruby_gem.version

          say "RubyGems system software updated" if installed
        else
          if updated.empty? then
            say "Nothing to update"
          else
            say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
          end
        end
      end