> This page is for SDKs, version Current (default).
> For other versions, use one of these documentation indexes:
> - Current (default): https://buildwithfern.com/learn/sdks/current/llms.txt
> - Legacy: https://buildwithfern.com/learn/sdks/legacy/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

# Publishing to RubyGems

> Publish Ruby SDKs to RubyGems with Fern. Complete setup guide for package configuration, API key authentication, and versioned releases.

> **Enterprise feature**
>
> This feature is available only for the [Enterprise plan](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com).

Publish your public-facing Fern Ruby SDK to the [RubyGems registry](https://rubygems.org/). After following the steps on this page,
you'll have a versioned package published on RubyGems. To distribute the SDK
internally instead, generate to the local file system (optionally
[self-hosted](/learn/sdks/deep-dives/self-hosted)) and build a gem with
[`fern generate --package`](/learn/cli-api-reference/cli-reference/sdk-commands#package).

> **Info**
>
> This page assumes that you have:
>
> * An initialized `fern` folder, a GitHub repository for your Ruby SDK, and a Ruby target in `sdk-config.yml`. See [Generating an SDK (Ruby)](/learn/sdks/generators/ruby/quickstart).

## Configure `sdk-config.yml`

Update the Ruby target in `sdk-config.yml` to configure the gem name, client name, and publishing destination. Your `sdk-config.yml` [should live in your source repository](/learn/sdks/overview/project-structure) (or on your local machine), not the repository that contains your Ruby SDK code.

#### Add a unique package name

Your package name must be unique in the RubyGems repository, otherwise publishing your SDK to RubyGems will fail.

**`sdk-config.yml`**

```yaml title="sdk-config.yml" {3-4}
targets:
  - language: ruby
    package:
      packageName: your-package-name
```

#### Configure the client name

The `generation.naming.clientName` option controls the name of the generated client module.

**`sdk-config.yml`**

```yaml title="sdk-config.yml" {5-7}
targets:
  - language: ruby
    package:
      packageName: your-package-name
    generation:
      naming:
        clientName: YourClientName
```

#### Configure GitHub delivery and RubyGems publishing

Set `output.delivery` to `github`, add the path to your GitHub repository, and set `output.publish.registry` to `rubygems`:

**`sdk-config.yml`**

```yaml title="sdk-config.yml" {8-13}
targets:
  - language: ruby
    package:
      packageName: your-package-name
    generation:
      naming:
        clientName: YourClientName
    output:
      delivery: github
      github:
        repository: your-org/company-ruby
      publish:
        registry: rubygems
```

## Set up RubyGems publishing authentication

#### Log into RubyGems

Log into [RubyGems](https://rubygems.org/) or create a new account.

#### Navigate to Account settings

1. Click on your profile picture
2. Select **Settings**.
3. Scroll down and click on **API Keys**.

#### Add New Key

When prompted to [create a new API key](https://rubygems.org/profile/api_keys/new):

1. Name your key.
2. Under **Scopes**, select **Push rubygem**
3. Select `All Gems` under **Gem Scope**.

> **Replacing an existing gem**
>
> If you are overriding an existing gem, you can select the relevant package instead of entering `All Gems`.

1. Set an expiration date.
2. Click **Create API Key**.

> **Warning**
>
> Save your new key –  it won’t be displayed after you leave the page.

![Creating a New API Key](/learn/_fern-files/_img/96a4e05d925b8e47bc26b72e876d40841a734e771c72d6e24b2f41a7a1a1088f.webp)

## Release your SDK to RubyGems

At this point, you're ready to generate a release for your SDK.

#### Set RubyGems environment variable

On your local machine, set the `RUBYGEMS_API_KEY` environment variable to the new API key you generated earlier:

```bash
export RUBYGEMS_API_KEY=your-actual-rubygems-token
```

#### Generate your release

Regenerate your SDK and publish it on RubyGems:

```bash
fern generate --target ruby --version <version>
```

Local machine output will verify that the release is pushed to your
repository and tagged with the version you specified. Log back into RubyGems and
navigate to **Releases** to see your new release.