Guide-Ruby

Introduction

This guide will walk you through the process of creating a RubyGem, building it, pushing it to Gemfury, and then installing it. Before you get started, be sure you have the following: Gemfury account Local Ruby installation Bundler installed locally

Creating a gem

To create a gem, minimally, you only need a .gemspec specification file. However, most gems are a combination of libraries, tests, documentation, and more. To quickly create a scaffold that includes those, we recommend using Bundler’s generator: bundle gem GEM_NAME This will create a directory GEM_NAME with the initial gem structure including the GEM_NAME.gemspec specification. Take a look inside – it’s just a Ruby file. Before you can build this gem, you will need to fill out the specification fields marked with TODO. 

Upload your gem

Now that you have the structure of the RubyGem in place, you have a number of ways to upload it to your Gemfury account. You can use the Dashboard, cURL, the Gemfury CLI, or Git. Pushing from terminal You already have a prebuilt gem from the previous step, so let’s upload it directly from a terminal: gem build GEM_NAME.gemspec curl -F package=@GEM_NAME-0.1.0.gem https://TOKEN@push.fury.io/USERNAME/ If you’ve installed the Gemfury CLI, you can also push with: 

Install gems with Bundler

Using Gemfury with Bundler is easy, just add a source block with a Repo-URL to your Gemfile and enclose your private package requirements: source 'https://gem.fury.io/USERNAME/' do gem 'private-gem', '~> 1.0' end You can also configure the source for individual packages with: gem 'private-gem', source: 'https://gem.fury.io/USERNAME/' Authenticating for private gems To access private gems, you will need to authenticate using a deploy token. You can do this with Bundler configuration or through an environment variable. 

Install gems via RubyGems CLI

Occasionally you will need to install a single gem with the RubyGems CLI: gem install my-gem --source https://TOKEN@gem.fury.io/USERNAME/ Or you may want to permanently add your Gemfury account as source: gem sources -a https://TOKEN@gem.fury.io/USERNAME/ This will append your repository URL to your ~/.gemrc file. It is important to include a trailing slash in the repository URL, otherwise gem may have trouble connecting to your Gemfury repository.