    # File lib/rubygems/installer.rb, line 231
      def generate_bin
        return if @spec.executables.nil? or @spec.executables.empty?

        # If the user has asked for the gem to be installed in a directory that is
        # the system gem directory, then use the system bin directory, else create
        # (or use) a new bin dir under the gem_home.
        bindir = @bin_dir ? @bin_dir : Gem.bindir(@gem_home)

        Dir.mkdir bindir unless File.exist? bindir
        raise Gem::FilePermissionError.new(bindir) unless File.writable? bindir

        @spec.executables.each do |filename|
          filename.untaint
          bin_path = File.expand_path File.join(@gem_dir, @spec.bindir, filename)
          mode = File.stat(bin_path).mode | 0111
          File.chmod mode, bin_path

          if @wrappers then
            generate_bin_script filename, bindir
          else
            generate_bin_symlink filename, bindir
          end
        end
      end