Skip to main content
Frecuentemente publicamos actualizaciones de nuestra documentación. Es posible que la traducción de esta página esté en curso. Para conocer la información más actual, visita la documentación en inglés. Si existe un problema con las traducciones en esta página, por favor infórmanos.

Esta versión de GitHub Enterprise se discontinuó el 2022-06-03. No se realizarán lanzamientos de patch, ni siquiera para problemas de seguridad críticos. Para obtener un mejor desempeño, más seguridad y nuevas características, actualiza a la última versión de GitHub Enterprise. Para obtener ayuda con la actualización, contacta al soporte de GitHub Enterprise.

Working with the RubyGems registry

You can configure RubyGems to publish a package to Registro del paquete de GitHub and to use packages stored on Registro del paquete de GitHub as dependencies in a Ruby project with Bundler.

El Registro del paquete de GitHub se encuentra disponible con GitHub Free, GitHub Pro, GitHub Free para organizaciones, GitHub Team, Nube de GitHub Enterprise, GitHub Enterprise Server 3.0 o superior y GitHub AE. Para obtener más información sobre cómo mejorar tu instancia de GitHub Enterprise Server, consulta la sección "Acerca de las mejoras a los lanzamientos nuevos" y refiérete al Asistente de mejora para encontrar la ruta de mejora desde tu versión de lanzamiento actual.

Nota: Este tipo de paquete podría no estar disponible para tu instancia, ya que los administradores de sitio pueden habilitar o inhabilitar cada tipo de paquete compatible. Para obtener más información, consulta la sección "Configurar el soporte de los paquetes para tu empresa".

Prerequisites

  • You must have RubyGems 2.4.1 or higher. To find your RubyGems version:

    $ gem --version
  • You must have bundler 1.6.4 or higher. To find your Bundler version:

    $ bundle --version
    Bundler version 1.13.7
  • Install keycutter to manage multiple credentials. To install keycutter:

    $ gem install keycutter

Authenticating to Registro del paquete de GitHub

You need an access token to publish, install, and delete packages.

You can use a personal access token (PAT) to authenticate to Registro del paquete de GitHub or the GitHub Enterprise Server API. When you create a personal access token, you can assign the token different scopes depending on your needs. For more information about packages-related scopes for a PAT, see "About permissions for GitHub Packages."

To authenticate to a Registro del paquete de GitHub registry within a GitHub Actions workflow, you can use:

  • GITHUB_TOKEN to publish packages associated with the workflow repository.
  • a PAT to install packages associated with other private repositories (which GITHUB_TOKEN can't access).

Para obtener más información sobre el GITHUB_TOKEN que se utiliza en los flujos de trabajo de GitHub Actions, consulta la sección "Autenticarse en un flujo de trabajo".

Authenticating with a personal access token

Debes utilizar un token de acceso personal con los alcances adecuados para publicar e instalar paquetes en Registro del paquete de GitHub. Para obtener más información, consulta "Acerca de Registro del paquete de GitHub".

You can authenticate to Registro del paquete de GitHub with RubyGems by editing the ~/.gem/credentials file for publishing gems, editing the ~/.gemrc file for installing a single gem, or using Bundler for tracking and installing one or more gems.

To publish new gems, you need to authenticate to Registro del paquete de GitHub with RubyGems by editing your ~/.gem/credentials file to include your personal access token. Create a new ~/.gem/credentials file if this file doesn't exist.

For example, you would create or edit a ~/.gem/credentials to include the following, replacing TOKEN with your personal access token.

---
:github: Bearer TOKEN

To install gems, you need to authenticate to Registro del paquete de GitHub by editing the ~/.gemrc file for your project to include https://USERNAME:TOKEN@REGISTRY-URL/OWNER/. You must replace:

  • USERNAME with your GitHub username.
  • TOKEN with your personal access token.
  • OWNER with the name of the user or organization account that owns the repository containing your project.
  • REGISTRY-URL with the URL for your instance's Rubygems registry. If your instance has subdomain isolation enabled, use rubygems.HOSTNAME. If your instance has subdomain isolation disabled, use HOSTNAME/_registry/rubygems. In either case, replace HOSTNAME with the hostname of your GitHub Enterprise Server instance.

If you don't have a ~/.gemrc file, create a new ~/.gemrc file using this example.

---
:backtrace: false
:bulk_threshold: 1000
:sources:
- https://rubygems.org/
- https://USERNAME:TOKEN@REGISTRY-URL/OWNER/
:update_sources: true
:verbose: true  

To authenticate with Bundler, configure Bundler to use your personal access token, replacing USERNAME with your GitHub username, TOKEN with your personal access token, and OWNER with the name of the user or organization account that owns the repository containing your project. Replace REGISTRY-URL with the URL for your instance's RubyGems registry. If your instance has subdomain isolation enabled, use rubygems.HOSTNAME. If your instance has subdomain isolation disabled, use HOSTNAME/_registry/rubygems. In either case, replace HOSTNAME with the hostname of your GitHub Enterprise Server instance.

$ bundle config https://REGISTRY-URL/OWNER USERNAME:TOKEN

Publishing a package

Predeterminadamente, GitHub publica el paquete en un repositorio existente con el mismo nombre que éste. For example, when you publish octo-gem to the octo-org organization, Registro del paquete de GitHub publishes the gem to the octo-org/octo-gem repository. For more information on creating your gem, see "Make your own gem" in the RubyGems documentation.

Después de que publiques un paquete, puedes verlo en GitHub. Para obtener más información, consulta "Visualizar paquetes".

  1. Autentícate en Registro del paquete de GitHub. Para obtener más información, consulta "Autenticar a Registro del paquete de GitHub."

  2. Build the package from the gemspec to create the .gem package.

    gem build OCTO-GEM.gemspec
  3. Publish a package to Registro del paquete de GitHub, replacing OWNER with the name of the user or organization account that owns the repository containing your project and OCTO-GEM with the name of your gem package. Replace REGISTRY-URL with the URL for your instance's Rubygems registry. If your instance has subdomain isolation enabled, use rubygems.HOSTNAME. If your instance has subdomain isolation disabled, use HOSTNAME/_registry/rubygems. In either case, replace HOSTNAME with the host name of your GitHub Enterprise Server instance.

    $ gem push --key github \
    --host https://REGISTRY-URL/OWNER \
    OCTO-GEM-0.0.1.gem

Publishing multiple packages to the same repository

To publish multiple gems to the same repository, you can include the URL to the GitHub repository in the github_repo field in gem.metadata. If you include this field, GitHub matches the repository based on this value, instead of using the gem name. Replace HOSTNAME with the host name of tu instancia de GitHub Enterprise Server.

gem.metadata = { "github_repo" => "ssh://HOSTNAME/OWNER/REPOSITORY" }

Installing a package

You can use gems from Registro del paquete de GitHub much like you use gems from rubygems.org. You need to authenticate to Registro del paquete de GitHub by adding your GitHub user or organization as a source in the ~/.gemrc file or by using Bundler and editing your Gemfile.

  1. Autentícate en Registro del paquete de GitHub. Para obtener más información, consulta "Autenticar a Registro del paquete de GitHub."

  2. For Bundler, add your GitHub user or organization as a source in your Gemfile to fetch gems from this new source. For example, you can add a new source block to your Gemfile that uses Registro del paquete de GitHub only for the packages you specify, replacing GEM NAME with the package you want to install from Registro del paquete de GitHub and OWNER with the user or organization that owns the repository containing the gem you want to install. Replace REGISTRY-URL with the URL for your instance's Rubygems registry. If your instance has subdomain isolation enabled, use rubygems.HOSTNAME. If your instance has subdomain isolation disabled, use HOSTNAME/_registry/rubygems. In either case, replace HOSTNAME with the host name of your GitHub Enterprise Server instance.

    source "https://rubygems.org"
    
    gem "rails"
    
    source "https://REGISTRY-URL/OWNER" do
      gem "GEM NAME"
    end
    
  3. For Bundler versions earlier than 1.7.0, you need to add a new global source. For more information on using Bundler, see the bundler.io documentation.

    source "https://REGISTRY-URL/OWNER"
    source "https://rubygems.org"
    
    gem "rails"
    gem "GEM NAME"
    
  4. Install the package:

    $ gem install octo-gem --version "0.1.1"