# File lib/rubygems/installer.rb, line 143
  def install
    current_home = Gem.dir
    current_path = Gem.paths.path

    verify_gem_home(options[:unpack])
    Gem.use_paths gem_home, current_path # HACK: shouldn't need Gem.paths.path

    # If we're forcing the install then disable security unless the security
    # policy says that we only install signed gems.
    @security_policy = nil if @force and @security_policy and
                              not @security_policy.only_signed

    unless @force
      ensure_required_ruby_version_met
      ensure_required_rubygems_version_met
      ensure_dependencies_met unless @ignore_dependencies
    end

    Gem.pre_install_hooks.each do |hook|
      result = hook.call self

      if result == false then
        location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/

        message = "pre-install hook#{location} failed for #{spec.full_name}"
        raise Gem::InstallError, message
      end
    end

    Gem.ensure_gem_subdirectories gem_home

    # Completely remove any previous gem files
    FileUtils.rm_rf(gem_dir) if File.exist? gem_dir

    FileUtils.mkdir_p gem_dir

    extract_files
    build_extensions

    Gem.post_build_hooks.each do |hook|
      result = hook.call self

      if result == false then
        FileUtils.rm_rf gem_dir

        location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/

        message = "post-build hook#{location} failed for #{spec.full_name}"
        raise Gem::InstallError, message
      end
    end

    generate_bin
    write_spec

    write_require_paths_file_if_needed if Gem::QUICKLOADER_SUCKAGE

    cache_file = spec.cache_file
    FileUtils.cp gem, cache_file unless File.exist? cache_file

    say spec.post_install_message unless spec.post_install_message.nil?

    spec.loaded_from = spec.spec_file

    Gem::Specification.add_spec spec unless Gem::Specification.include? spec

    Gem.post_install_hooks.each do |hook|
      hook.call self
    end

    return spec
  rescue Zlib::GzipFile::Error
    raise Gem::InstallError, "gzip error installing #{gem}"
  ensure
    # conditional since we might be here because we're erroring out early.
    if current_path
      Gem.use_paths current_home, current_path
    end
  end