### Install Bundler 2 Source: https://guides.rubygems.org/bundler_2_upgrade Install the latest version of Bundler by running the standard installation command. ```bash gem install bundler ``` -------------------------------- ### Install Gems with bundle install Source: https://guides.rubygems.org/getting_started Use `bundle install` to install all gems specified in your Gemfile. After installation, add both `Gemfile` and `Gemfile.lock` to your version control to ensure consistency. ```bash $ bundle install $ git add Gemfile Gemfile.lock ``` -------------------------------- ### Install Gemirro Source: https://guides.rubygems.org/run-your-own-gem-server Install the Gemirro gem to get started with creating your RubyGems mirror. ```bash $ gem install gemirro ``` -------------------------------- ### Running the Hola Gem Executable Source: https://guides.rubygems.org/make-your-own-gem Examples of how to run the 'hola' executable from the command line, both with and without arguments, to get greetings in different languages. ```bash $ ruby -Ilib ./bin/hola hello world $ ruby -Ilib ./bin/hola spanish hola mundo ``` -------------------------------- ### Install a Gem and Dependencies Source: https://guides.rubygems.org/rubygems-basics The `gem install` command downloads, installs, and builds documentation for a gem and its dependencies. It automatically handles building native extensions for dependencies. ```bash $ gem install drip ``` -------------------------------- ### Install Rails Source: https://guides.rubygems.org/rails Install the Rails gem using the standard gem install command. Use sudo if your system requires it for global gem installations. ```bash $ gem install rails ``` -------------------------------- ### Install Gemstash Source: https://guides.rubygems.org/run-your-own-gem-server Install the Gemstash gem to get started with running your own private gem server and cache. ```bash $ gem install gemstash ``` -------------------------------- ### Install Executables with --binstubs Source: https://guides.rubygems.org/getting_started Use `bundle install --binstubs` to install executables into a `bin` directory. These executables are scoped to your bundle and will always work correctly. ```bash $ bundle install --binstubs $ bin/rspec spec/models ``` -------------------------------- ### RubyGems Plugin with Pre-Install Hook Source: https://guides.rubygems.org/plugins Implement a 'pre_install' hook to control gem installations. This example uses a whitelist to confirm installations interactively. ```ruby WHITELIST_PATH = "#{ENV['HOME']}/.gem/install_audit/whitelist" Gem.pre_install do |installer| gem_name = installer.spec.name whitelist = if File.exist? WHITELIST_PATH File.read(WHITELIST_PATH).split else [] end unless whitelist.include? gem_name print "`#{gem_name}' is not whitelisted, install? (y/n): " case choice = $stdin.gets.chomp when /\Ay/i when /\An/i then next false else fail "cannot understand `#{choice}'" end end end ``` -------------------------------- ### Basic Bundler Setup Source: https://guides.rubygems.org/bundler_setup Configure the load path to include all dependencies from your Gemfile. This is the most common setup for Ruby applications. ```ruby require 'bundler/setup' require 'nokogiri' ``` -------------------------------- ### Build and Install Gem Source: https://guides.rubygems.org/make-your-own-gem Commands to build a gem from its gemspec and then install it locally for testing. ```shell $ gem build hola.gemspec Successfully built RubyGem Name: hola Version: 0.0.0 File: hola-0.0.0.gem $ gem install ./hola-0.0.0.gem Successfully installed hola-0.0.0 Parsing documentation for hola-0.0.0 Installing ri documentation for hola-0.0.0 Done installing documentation for hola after 0 seconds 1 gem installed ``` -------------------------------- ### Installing and Using Nokogiri Gem Source: https://guides.rubygems.org/make-your-own-gem Demonstrates installing the Nokogiri gem and using its executable to parse a webpage and access its title. ```bash $ gem install -N nokogiri [...] $ nokogiri https://www.ruby-lang.org/ Your document is stored in @doc... 3.1.2 :001 > @doc.title => "Ruby Programming Language" ``` -------------------------------- ### Install Gems for Development Source: https://guides.rubygems.org/using_bundler_in_applications Run `bundle install` to install gems specified in the Gemfile. This command also generates or updates the Gemfile.lock file. ```text Fetching gem metadata from https://rubygems.org/ Fetching version metadata from https://rubygems.org/ Fetching dependency metadata from https://rubygems.org/ Resolving dependencies... Using mini_portile2 2.1.0 Using pkg-config 1.1.7 Using bundler 1.12.5 Using nokogiri 1.6.8 Bundle complete! 1 Gemfile dependency, 4 gems now installed. Use `bundle show [gemname]` to see where a bundled gem is installed. ``` ```ruby GEM remote: https://rubygems.org/ specs: mini_portile2 (2.1.0) nokogiri (1.6.8) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) pkg-config (1.1.7) PLATFORMS ruby DEPENDENCIES nokogiri (>= 1.4.0) BUNDLED WITH 1.12.5 ``` -------------------------------- ### Install a Gem Without Documentation Source: https://guides.rubygems.org/rubygems-basics To speed up installation or reduce disk space, use the `--no-document` argument with `gem install` to skip the generation of documentation. ```bash $ gem install --no-document drip ``` -------------------------------- ### Install Prerelease Gems with `--pre` Flag Source: https://guides.rubygems.org/patterns Use the `gem install --pre` command to install prerelease versions of gems. This flag is necessary to bypass the default behavior of only installing stable releases. ```bash % gem list factory_bot -r --pre *** REMOTE GEMS *** factory_bot (2.0.0.beta2, 2.0.0.beta1) factory_bot_rails (1.1.beta1) % gem install factory_bot --pre Successfully installed factory_bot-2.0.0.beta2 1 gem installed ``` -------------------------------- ### Install Gem from RubyGems.org Source: https://guides.rubygems.org/make-your-own-gem Install your published gem on any machine by using this command. It fetches the gem from RubyGems.org and installs it locally. ```bash $ gem install hola Fetching hola-0.1.3.gem Successfully installed hola-0.1.3 Parsing documentation for hola-0.1.3 Installing ri documentation for hola-0.1.3 Done installing documentation for hola after 0 seconds 1 gem installed ``` -------------------------------- ### Start Sinatra Development Server with Bundler Source: https://guides.rubygems.org/sinatra Use `bundle exec rackup` to start your Sinatra development server. This command ensures that Sinatra and its dependencies are loaded through Bundler. ```bash $ bundle exec rackup ``` -------------------------------- ### Install bundle to vendor/bundle for deployment Source: https://guides.rubygems.org/deploying Use the `--deployment` flag with `bundle install` to install gems into the `vendor/bundle` directory. This ensures that all dependencies are met and available in a self-contained environment for your application. ```bash $ bundle install --deployment ``` -------------------------------- ### Speed Up Gem Installation with Bundler Source: https://guides.rubygems.org/faqs Employ the `--full-index` flag during `bundle install` to download all gem information at once, potentially speeding up installations over high-latency connections. Ensure you are using the latest version of Bundler for performance improvements. ```bash $ bundle install --full-index ``` -------------------------------- ### Install Gem using Alias Source: https://guides.rubygems.org/command-reference The 'i' command is an alias for 'gem install'. Use it to install a gem by specifying its name. ```bash $ gem i GEMNAME ``` -------------------------------- ### RDoc Documentation Example for Hola Class Source: https://guides.rubygems.org/make-your-own-gem An example of documenting a Ruby class and its method using RDoc syntax, including descriptions, examples, and argument types. ```ruby # The main Hola driver class Hola # Say hi to the world! # # Example: # >> Hola.hi("spanish") # => hola mundo # # Arguments: # language: (String) def self.hi(language = "english") translator = Translator.new(language) puts translator.hi end end ``` -------------------------------- ### Build and Install Signed Gem Source: https://guides.rubygems.org/security Build your gem from its gemspec and then install it using a high security policy to test the signing process. ```bash gem build gemname.gemspec ``` ```bash gem install gemname-version.gem -P HighSecurity ``` -------------------------------- ### Install Gem Dependencies Source: https://guides.rubygems.org/bundler_workflow Install all gems specified in the Gemfile and their dependencies. Bundler resolves versions and installs them, creating a Gemfile.lock to record the exact versions. ```bash $ bundle install ``` ```bash $ bundle install Fetching gem metadata from https://rubygems.org/.......... Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Resolving dependencies... Installing rake 11.3.0 Using concurrent-ruby 1.0.2 Using i18n 0.7.0 Installing minitest 5.9.1 Using thread_safe 0.3.5 Using builder 3.2.2 Using erubis 2.7.0 Using mini_portile2 2.1.0 Using rack 2.2.4 Using nio4r 1.2.1 Using websocket-extensions 0.1.2 Installing mime-types-data 3.2016.0521 Installing arel 7.1.4 Using bundler 1.13.1 Using method_source 0.8.2 Using thor 0.19.1 Using tzinfo 1.2.2 Installing nokogiri 1.6.8.1 with native extensions Using rack-test 0.6.3 Using sprockets 3.7.0 Installing websocket-driver 0.6.4 with native extensions Installing mime-types 3.1 Using activesupport 5.0.0.1 Using loofah 2.0.3 Using mail 2.6.4 Using rails-dom-testing 2.0.1 Using globalid 0.3.7 Using activemodel 5.0.0.1 Using rails-html-sanitizer 1.0.3 Using activejob 5.0.0.1 Using activerecord 5.0.0.1 Using actionview 5.0.0.1 Using actionpack 5.0.0.1 Using actioncable 5.0.0.1 Using actionmailer 5.0.0.1 Using railties 5.0.0.1 Installing sprockets-rails 3.2.0 Using rails 5.0.0.1 Bundle complete! 1 Gemfile dependency, 38 gems now installed. Use `bundle show [gemname]` to see where a bundled gem is installed. ``` -------------------------------- ### Check Bundler Version in Application (Bundler 2) Source: https://guides.rubygems.org/bundler_2_upgrade When a Gemfile.lock has been created or upgraded for Bundler 2, commands will be run by the latest installed Bundler 2. This example shows how to verify the Bundler version. ```bash $ grep -A 1 "BUNDLED WITH" Gemfile.lock BUNDLED WITH 2.0.0 $ bundle version Bundler version 2.0.0 ``` -------------------------------- ### Install Gem from Custom Server Source: https://guides.rubygems.org/run-your-own-gem-server Install a gem as you normally would after configuring your custom gem server. RubyGems will now be able to find and install gems from your specified source. ```bash [~] gem install secretgem Successfully installed secretgem-0.0.1 1 gem installed ``` -------------------------------- ### Install Bundler Source: https://guides.rubygems.org/bundler_workflow Install the Bundler gem globally to manage project dependencies. ```bash $ gem install bundler ``` -------------------------------- ### Install Dependencies with Bundler Source: https://guides.rubygems.org/dependency_management Run this command in your project's root directory to install all gems specified in the Gemfile and create a Gemfile.lock. ```bash $ bundle install ``` -------------------------------- ### Install Ruby with apt-get on Debian/Ubuntu Source: https://guides.rubygems.org/rubygems_tls_ssl_troubleshooting_guide Commands to uninstall and then reinstall Ruby using apt-get. This installs Ruby v2.3.1. ```bash $ sudo apt-get install ruby ``` -------------------------------- ### Install Bundler Dependencies for Deployment Source: https://guides.rubygems.org/bundler_workflow Use the --deployment flag when installing gems on a production or deployment server. This ensures that gems are installed in a system-wide location and that only gems specified in the Gemfile.lock are used. ```bash $ bundle install --deployment ``` -------------------------------- ### Run Rails Server Source: https://guides.rubygems.org/rails Start the Rails development server. Bundler transparently handles all application dependencies. ```bash $ rails server ``` -------------------------------- ### Install and Use gem-release Gem Source: https://guides.rubygems.org/make-your-own-gem Install the `gem-release` gem to simplify version bumping and releasing. Use `gem bump` with options like `minor`, `major`, or a specific version number. ```bash $ gem install gem-release $ gem bump --version minor # bumps to the next minor version $ gem bump --version major # bumps to the next major version $ gem bump --version 1.1.1 # bumps to the specified version ``` -------------------------------- ### Display Gem Installation Path Source: https://guides.rubygems.org/command-reference Query the path where gems are installed using `gem environment gemhome` or its aliases. ```bash gem environment gemhome ``` -------------------------------- ### Display User Gem Installation Path Source: https://guides.rubygems.org/command-reference Query the path where gems are installed when the `--user-install` flag is used, via `gem environment user_gemhome`. ```bash gem environment user_gemhome ``` -------------------------------- ### Install Bundler Dependencies Source: https://guides.rubygems.org/bundler_workflow Run this command after creating or modifying your Gemfile to install all application dependencies. It generates or updates the Gemfile.lock. ```bash $ bundle install ``` -------------------------------- ### Whitelisting a Gem for Installation Source: https://guides.rubygems.org/plugins Add a gem name to the whitelist file to allow its installation without interactive confirmation. ```bash echo rake > ~/.gem/install_audit/whitelist ``` -------------------------------- ### Install Gem from S3 Source Source: https://guides.rubygems.org/using-s3-source Install a specific gem version from your S3 source using the --source flag. ```bash $ gem install rake -v 12.3.2 --source s3://:@bucket1 ``` -------------------------------- ### Install Executable Stubs with Bundler Source: https://guides.rubygems.org/bundler_workflow Install executable stubs for gems in your bundle. This creates executables in the 'bin' directory that are scoped to your bundle, ensuring they always work correctly. ```bash $ bundle install --binstubs $ bin/rspec spec/models ``` -------------------------------- ### List Installed Gems Source: https://guides.rubygems.org/rubygems-basics Command to display all gems currently installed on the system, including their versions and whether they are default or bundled gems. ```bash $ gem list *** LOCAL GEMS *** abbrev (default: 0.1.0) awesome_print (1.9.2) base64 (default: 0.1.1) benchmark (default: 0.2.0) bigdecimal (default: 3.1.1) bundler (default: 2.3.7) cgi (default: 0.3.1) csv (default: 3.2.2) date (default: 3.2.2) debug (1.4.0) delegate (default: 0.2.0) did_you_mean (default: 1.6.1) digest (default: 3.1.0) drb (default: 2.1.0) drip (0.1.1) english (default: 0.7.1) [...] ``` -------------------------------- ### Install Gem from Git Repository with .gemspec Source: https://guides.rubygems.org/git Specify a gem to be installed from a Git repository that has a .gemspec file at its root. ```ruby gem 'rack', git: 'https://github.com/rack/rack' ``` -------------------------------- ### Example: Unpack and Modify Gem Source: https://guides.rubygems.org/command-reference Demonstrates unpacking a gem, editing its contents, and then using it by adding its directory to the RUBYLIB environment variable. ```bash $ gem unpack my_gem Unpacked gem: '.../my_gem-1.0' [edit my_gem-1.0/lib/my_gem.rb] $ ruby -Imy_gem-1.0/lib -S other_program ``` -------------------------------- ### Install Gem with Extension Build Options Source: https://guides.rubygems.org/command-reference Use the '--' separator to pass build options to extension compilation when installing a gem. This is useful if the extension fails to compile initially. ```bash $ gem install some_extension_gem -- --with-extension-lib=/path/to/lib ``` -------------------------------- ### Install Gem in a Box Source: https://guides.rubygems.org/run-your-own-gem-server Install the Gem in a Box gem, a more feature-rich option for a private gem server that supports pushing gems. ```bash [~/dev/geminabox] gem install geminabox ``` -------------------------------- ### Install a Bundler plugin from the Gemfile Source: https://guides.rubygems.org/bundler_plugins Specify plugins in your Gemfile to manage their installation. Plugins can be sourced from RubyGems, a local path, or a Git repository. ```ruby plugin 'my_plugin' # Installs from Rubygems plugin 'my_plugin', path: '/path/to/plugin' # Installs from a path plugin 'my_plugin', git: 'https://github.com/repo/my_plugin.git' # Installs from Git ``` -------------------------------- ### Install RubyGems API Client Library Source: https://guides.rubygems.org/rubygems-org-api Install the official Ruby gems client library to interact with RubyGems.org using Ruby. This command uses the gem command-line tool. ```bash gem install gems ``` -------------------------------- ### Setup Bundled Environment Source: https://guides.rubygems.org/bundler_workflow Require 'bundler/setup' at the beginning of your application to load the gems specified in your Gemfile. This makes your bundled gems available for use. ```ruby require 'bundler/setup' # require your gems as usual require 'nokogiri' ``` -------------------------------- ### API Authorization Example Source: https://guides.rubygems.org/rubygems-org-api Demonstrates how to authenticate API calls using an API key, with an option to include a one-time passcode for MFA. ```APIDOC ## API Authorization Some API calls require an Authorization header. To create or view existing API keys, click on your username when logged in to RubyGems.org, ‘Settings’, and then ‘API Keys’. Here’s an example of using an API key: ``` $ curl -H 'Authorization:YOUR_API_KEY' \ https://rubygems.org/api/v1/some_api_call.json ``` If you are using Multi-factor authentication, you will need to provide one-time passcode in the `OTP` header. Here’s an example of using your API key with a OTP: ``` $ curl -H 'Authorization:YOUR_API_KEY' \ -H 'OTP:YOUR_ONE_TIME_PASSCODE' \ https://rubygems.org/api/v1/some_api_call.json ``` ``` -------------------------------- ### Set Post-Installation Message Source: https://guides.rubygems.org/specification-reference Define a custom message to be displayed to the user immediately after the gem is successfully installed. ```ruby spec.post_install_message = "Thanks for installing!" ``` -------------------------------- ### Example of calling a reusable workflow Source: https://guides.rubygems.org/trusted-publishing This example shows how a gem's repository workflow calls a reusable workflow from a different repository. The `uses` directive specifies the path to the reusable workflow. ```yaml # In my-org/my-gem/.github/workflows/release.yml jobs: release: uses: shared-org/shared-workflows/.github/workflows/ruby-gem-release.yml@main ``` -------------------------------- ### Show Gem Dependencies Source: https://guides.rubygems.org/command-reference Display the dependencies of an installed gem. This command helps in understanding the relationships between gems. ```bash gem dependency REGEXP [options] ``` -------------------------------- ### Get Gem Information Source: https://guides.rubygems.org/default-gems-and-bundled-gems This command retrieves detailed information about an installed gem, including its version. This can be used to check specific default or bundled gems. ```bash $ gem info json ``` -------------------------------- ### Create a Global Webhook Source: https://guides.rubygems.org/rubygems-org-api Set up a webhook that applies to all gems. Use '*' for the gem name. Requires an Authorization header and the webhook URL. ```bash $ curl -X POST -H 'Authorization:rubygems_b9ce70c306b3a2e248679fbbbd66722d408d3c8c4f00566c' \ -F 'gem_name=*' -F 'url=http://example.com' \ https://rubygems.org/api/v1/web_hooks Successfully created webhook for all gems to http://example.com ``` -------------------------------- ### Add Public Key and Install Gem with MediumSecurity Source: https://guides.rubygems.org/security Add a public key to trust signed gems and install a gem using the MediumSecurity profile. This profile verifies signed gems but allows unsigned dependencies. ```bash gem cert --add <(curl -Ls https://raw.github.com/metricfu/metric_fu/master/certs/bf4.pem) ``` ```bash gem install metric_fu -P MediumSecurity ``` -------------------------------- ### Run Gem in a Box Server Source: https://guides.rubygems.org/run-your-own-gem-server Start the Gem in a Box server using `rackup`. It will run on port 9292 by default. ```bash [~/dev/geminabox] rackup [2011-05-19 12:09:40] INFO WEBrick 1.3.1 [2011-05-19 12:09:40] INFO ruby 1.9.2 (2011-02-18) [x86_64-darwin10.5.0] [2011-05-19 12:09:40] INFO WEBrick::HTTPServer#start: pid=60941 port=9292 ``` -------------------------------- ### Initialize a Gemfile Source: https://guides.rubygems.org/bundler_workflow Create a new Gemfile in your project directory for specifying dependencies. This is useful for projects that do not automatically include one, like Sinatra applications. ```bash $ bundle init ``` -------------------------------- ### Initialize Gemirro Mirror Source: https://guides.rubygems.org/run-your-own-gem-server Initialize a new, empty directory for your Gemirro mirror. This sets up the basic structure for your gem repository. ```bash $ gemirro init /srv/http/mirror.com/ ``` -------------------------------- ### Display Supported Gem Platforms Source: https://guides.rubygems.org/command-reference Query the gem platforms that the current RubyGems installation supports using `gem environment platform`. ```bash gem environment platform ``` -------------------------------- ### Install Ruby with Homebrew on macOS Source: https://guides.rubygems.org/rubygems_tls_ssl_troubleshooting_guide Commands to update Homebrew and install or upgrade Ruby. Ensure Homebrew is installed before running these commands. ```bash brew update brew install ruby ``` ```bash brew upgrade ruby ``` -------------------------------- ### Specify Gem Extension Build File Source: https://guides.rubygems.org/specification-reference Add paths to `extconf.rb`-style files for compiling extensions when the gem is installed. ```ruby spec.extensions << 'ext/rmagic/extconf.rb' ``` -------------------------------- ### Define Gemfile Dependencies Source: https://guides.rubygems.org/rubymotion Create a Gemfile to specify your project's gem dependencies. This example includes the 'bubble-wrap' gem. ```ruby gem 'bubble-wrap' ``` -------------------------------- ### Creating and Making Executable a Gem Binary Source: https://guides.rubygems.org/make-your-own-gem Steps to create a 'bin' directory, a new executable file named 'hola', and set its execute permissions. ```bash $ mkdir bin $ touch bin/hola $ chmod a+x bin/hola ``` -------------------------------- ### Setup Bundler for Specific Groups Source: https://guides.rubygems.org/groups Use `Bundler.setup` to load gems from specified groups into the load path. Note that `Bundler.setup` can only be called once. ```ruby require 'bundler' Bundler.setup(:default, :ci) require 'nokogiri' ``` -------------------------------- ### Initialize Bundler in a Project Source: https://guides.rubygems.org/using_bundler_in_applications Create a new directory for your application and initialize Bundler within it. This creates a Gemfile. ```bash mkdir bundler_example && cd bundler_example $ bundle init ``` -------------------------------- ### Install Gem from Git Repository with Bundler Source: https://guides.rubygems.org/publishing Use this in your Gemfile to install a gem directly from its Git repository. This is a Bundler feature and gems installed this way won't appear in `gem list`. ```ruby gem "wicked_pdf", :git => "https://github.com/mileszs/wicked_pdf.git" ``` -------------------------------- ### Start Gemstash Server Source: https://guides.rubygems.org/run-your-own-gem-server Start the Gemstash server. It runs on port 9292 by default. ```bash $ gemstash start ``` -------------------------------- ### Create a RubyMotion App Source: https://guides.rubygems.org/rubymotion Use the `motion create` command to generate a new RubyMotion application. Navigate into the application directory. ```bash $ motion create myapp $ cd myapp ``` -------------------------------- ### Update Installed Gems Source: https://guides.rubygems.org/command-reference Updates installed gems to their latest versions. Use --system to update RubyGems itself. ```bash gem update GEMNAME [GEMNAME ...] [options] ``` -------------------------------- ### Generate Gem Index and Upload to S3 Source: https://guides.rubygems.org/using-s3-source Steps to create a local repository with gem index files and sync it to an S3 bucket. ```bash $ mkdir ~/repo && cd ~/repo # .gem must exist in a directory named `gems` $ mkdir gems && wget -P gems/ https://rubygems.org/downloads/rake-12.3.2.gem $ gem generate_index --directory . # replace bucket1 with name of the bucket you created $ aws s3 sync . s3://bucket1 ``` -------------------------------- ### Bundler plugin entry point Source: https://guides.rubygems.org/bundler_plugins The `plugins.rb` file at the root of your plugin gem serves as the entry point for Bundler. It typically requires the main library file of your gem. ```ruby require 'my_plugin' ``` -------------------------------- ### Supported Git Protocols for Gem Installation Source: https://guides.rubygems.org/git Bundler supports installing gems using HTTP(S), SSH, or git protocols. ```ruby gem 'rack', git: 'https://github.com/rack/rack.git' gem 'rack', git: 'git@github.com:rack/rack.git' gem 'rack', git: 'git://github.com/rack/rack.git' ``` -------------------------------- ### Basic RubyGems Plugin Source: https://guides.rubygems.org/plugins Create a simple plugin by placing a 'rubygems_plugin.rb' file in your gem's root. This example prints a message when loaded. ```ruby puts 'hello from my plugin!' ``` -------------------------------- ### Configure Extension Build with extconf.rb Source: https://guides.rubygems.org/gems-with-extensions Use `extconf.rb` to check for required C functions and generate a Makefile for building the extension. The script must exit if dependencies are missing. This example checks for `malloc` and `free`. ```ruby require "mkmf" abort "missing malloc()" unless have_func "malloc" abort "missing free()" unless have_func "free" create_makefile "my_malloc/my_malloc" ``` -------------------------------- ### Get User Profile by Handle Source: https://guides.rubygems.org/rubygems-org-api Retrieve basic user information using their handle. This is a GET request to the profiles endpoint. ```bash $ curl https://rubygems.org/api/v1/profiles/qrush [ { "id": 1, "handle": "qrush" } ] ``` -------------------------------- ### Generate Gemirro Index Source: https://guides.rubygems.org/run-your-own-gem-server Create an index of all installed gem files. This is necessary for RubyGems to be able to find and install gems from your mirror. ```bash $ gemirro index ``` -------------------------------- ### Create API Key with Scopes using gem CLI Source: https://guides.rubygems.org/api-key-scopes Use the `gem signin` command to interactively create a new API key. You will be prompted to enter your credentials, a name for the key, and select specific scopes to enable. ```bash $ gem signin Enter your RubyGems.org credentials. Don't have an account yet? Create one at https://rubygems.org/sign_up Email: john@doe.com Password: API Key name [4458ffe32b0c-unknown-user-20201231104303]: docker-push-key Please select scopes you want to enable for the API key (y/n) index_rubygems [y/N]: push_rubygem [y/N]: Y yank_rubygem [y/N]: add_owner [y/N]: remove_owner [y/N]: access_webhooks [y/N]: show_dashboard [y/N]: Signed in with API key: docker-push-key. ``` -------------------------------- ### Specify Configuration File Source: https://guides.rubygems.org/command-reference Use the `--config-file` option to specify an alternative configuration file instead of the default ~/.gemrc. ```bash gem --config-file FILE ``` -------------------------------- ### Build and Push Gem to Gem in a Box Source: https://guides.rubygems.org/run-your-own-gem-server Build a gem from its gemspec file and then push it to your Gem in a Box server. You will be prompted for the server URL on the first push. ```bash [~/dev/secretgem] gem build secretgem.gemspec Successfully built RubyGem Name: secretgem Version: 0.0.1 File: secretgem-0.0.1.gem [~/dev/secretgem] gem inabox ./secretgem-0.0.1.gem Enter the root url for your personal geminabox instance. (E.g. http://gems/) Host: http://localhost:9292 Pushing secretgem-0.0.1.gem to http://localhost:9292/... ``` -------------------------------- ### Configure Gem in a Box Server Source: https://guides.rubygems.org/run-your-own-gem-server Set up the `config.ru` file for Gem in a Box, specifying the data directory and running the server. ```ruby require "rubygems" require "geminabox" Geminabox.data = "./data" run Geminabox::Server ``` -------------------------------- ### Display Contents of Installed Gems Source: https://guides.rubygems.org/command-reference List the files contained within an installed gem. You can specify gem names or view contents for all gems. ```bash gem contents GEMNAME [GEMNAME ...] [options] ``` -------------------------------- ### Locate RubyGems Directory on macOS Source: https://guides.rubygems.org/rubygems_tls_ssl_troubleshooting_guide Use this command in the Terminal to find the directory where RubyGems is installed on macOS. This is required for manual certificate installation. ```bash $ gem which rubygems ``` -------------------------------- ### View Gem Documentation with 'ri' Source: https://guides.rubygems.org/rubygems-basics Uses the 'ri' command to display documentation for an installed gem. This provides a quick way to access API information. ```bash $ ri RBTree = RBTree < MultiRBTree (from gem rbtree-0.4.5) ------------------------------------------------------------------------ A sorted associative collection that cannot contain duplicate keys. RBTree is a subclass of MultiRBTree. ------------------------------------------------------------------------ ``` -------------------------------- ### Configure Bundler to Exclude Groups Source: https://guides.rubygems.org/groups Configure Bundler to exclude specific groups during `bundle install`. Gems in at least one non-excluded group will still be installed. ```bash $ bundle config set --local without test development ``` -------------------------------- ### Install Ruby with dnf on Fedora Source: https://guides.rubygems.org/rubygems_tls_ssl_troubleshooting_guide Commands to remove and then reinstall Ruby using dnf. This installs Ruby 2.3. Use 'yum' instead of 'dnf' if 'dnf' is not found. ```bash $ dnf remove ruby ``` ```bash $ dnf install ruby ``` -------------------------------- ### Install RubyGems Locally Source: https://guides.rubygems.org/rubygems_tls_ssl_troubleshooting_guide Install a downloaded RubyGems version manually. Replace '2.7.6' with the actual downloaded version number. This is a fallback if `gem update --system` fails. ```shell gem install --local rubygems-update-2.7.6.gem ``` ```shell update_rubygems ``` -------------------------------- ### Building C Extension with extconf.rb and make Source: https://guides.rubygems.org/gems-with-extensions Commands to build a C extension for a Ruby gem. This involves running `extconf.rb` to generate a Makefile and then `make` to compile the extension. ```bash $ cd ext/my_malloc $ ruby extconf.rb checking for malloc()... yes checking for free()... yes creating Makefile $ make compiling my_malloc.c linking shared-object my_malloc.bundle $ cd ../.. $ ruby -Ilib:ext -r my_malloc -e "p MyMalloc.new(5).free" # ``` -------------------------------- ### Define a Bundler Command using a Class Source: https://guides.rubygems.org/bundler_plugins Create a class that inherits from Bundler::Plugin::API and registers a command. The `exec` method handles the command's logic and arguments. Use `BundlerError` for error handling. ```ruby class MyCommand < Bundler::Plugin::API # Register this class as a handler for the `my_command` command command "my_command" # The exec method will be called with the `command` and the `args`. # This is where you should handle all logic and functionality def exec(command, args) if args.empty? # Using BundlerError in plugins is recommended. See below. raise BundlerError, 'My plugin requires arguments' end puts "You called " + command + " with args: " + args.inspect end end ``` -------------------------------- ### Get Gem Version Details Source: https://guides.rubygems.org/rubygems-org-api-v2 Retrieves detailed information about a specific version of a gem. You can also specify a platform to get version details for a particular operating system or Ruby implementation. ```APIDOC ## GET /api/v2/rubygems/[GEM NAME]/versions/[VERSION NUMBER].(json|yaml) ### Description Returns a dictionary with versions details for a specific gem version. To return the version for a specific platform (e.g. “ruby”, “java”, “x86_64-linux”), use the `platform` query parameter. ### Method GET ### Endpoint `/api/v2/rubygems/[GEM NAME]/versions/[VERSION NUMBER].(json|yaml)` ### Parameters #### Query Parameters - **platform** (string) - Optional - Specifies the platform for which to retrieve version details (e.g., "ruby", "java", "x86_64-linux"). ### Response #### Success Response (200) - **name** (string) - The name of the gem. - **downloads** (integer) - The total number of downloads for the gem. - **version** (string) - The specific version number of the gem. - **version_created_at** (string) - The timestamp when this version was created. - **version_downloads** (integer) - The number of downloads for this specific version. - **platform** (string) - The platform this version is built for. - **authors** (string) - The author(s) of the gem. - **info** (string) - A short description of the gem. - **licenses** (string or null) - The license(s) under which the gem is distributed. - **metadata** (object) - Additional metadata about the gem. - **homepage_uri** (string) - The URI of the gem's homepage. - **yanked** (boolean) - Indicates if the gem version has been yanked. - **sha** (string) - The SHA checksum of the gem file. - **spec_sha** (string) - The SHA checksum of the gem specification file. - **project_uri** (string) - The URI of the gem's project page on RubyGems.org. - **gem_uri** (string) - The URI to download the gem file. - **homepage_uri** (string) - The URI of the gem's homepage. - **wiki_uri** (string or null) - The URI of the gem's wiki. - **documentation_uri** (string or null) - The URI of the gem's documentation. - **mailing_list_uri** (string or null) - The URI of the gem's mailing list. - **source_code_uri** (string or null) - The URI of the gem's source code repository. - **bug_tracker_uri** (string or null) - The URI of the gem's bug tracker. - **changelog_uri** (string or null) - The URI of the gem's changelog. - **funding_uri** (string or null) - The URI for funding the gem's development. - **dependencies** (object) - Information about the gem's dependencies. - **development** (array) - List of development dependencies. - **runtime** (array) - List of runtime dependencies. - **name** (string) - The name of the dependency. - **requirements** (string) - The version requirements for the dependency. - **built_at** (string) - The timestamp when the gem was built. - **created_at** (string) - The timestamp when the gem version was created. - **description** (string) - A detailed description of the gem. - **downloads_count** (integer) - The number of downloads for this specific version. - **number** (string) - The version number of the gem. - **summary** (string) - A short summary of the gem. - **rubygems_version** (string) - The RubyGems version compatibility. - **ruby_version** (string or null) - The Ruby version compatibility. - **prerelease** (boolean) - Indicates if the version is a prerelease. - **requirements** (string or null) - Specific requirements for the gem version. ### Request Example ```bash $ curl https://rubygems.org/api/v2/rubygems/coulda/versions/0.7.1.json ``` ### Response Example ```json { "name": "coulda", "downloads": 86573, "version": "0.7.1", "version_created_at": "2011-08-08T21:23:40.254Z", "version_downloads": 5754, "platform": "ruby", "authors": "Evan David Light", "info": "Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse", "licenses": null, "metadata": { "homepage_uri": "http://coulda.tiggerpalace.com" }, "yanked": false, "sha": "777c3a7ed83e44198b0a624976ec99822eb6f4a44bf1513eafbc7c13997cd86c", "spec_sha": "57b863cff56029a0085eaf1b3416b701ed4fa75418d062358b45753e270c9ffa", "project_uri": "https://rubygems.org/gems/coulda", "gem_uri": "https://rubygems.org/gems/coulda-0.7.1.gem", "homepage_uri": "http://coulda.tiggerpalace.com", "wiki_uri": null, "documentation_uri": null, "mailing_list_uri": null, "source_code_uri": null, "bug_tracker_uri": null, "changelog_uri": null, "funding_uri": null, "dependencies": { "development": [], "runtime": [ { "name": "yourdsl", "requirements": "~> 0.7" } ] }, "built_at": "2011-08-08T04:00:00.000Z", "created_at": "2011-08-08T21:23:40.254Z", "description": "Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse", "downloads_count": 5754, "number": "0.7.1", "summary": "Test::Unit-based acceptance testing DSL", "rubygems_version": ">= 0", "ruby_version": null, "prerelease": false, "requirements": null } ``` ``` -------------------------------- ### Info File Version Entry Format Source: https://guides.rubygems.org/rubygems-org-compact-index-api Each line after the header in the `info` file describes a single gem version, including platform, dependencies, and requirements. ```text VERSION[-PLATFORM] [DEPENDENCY[,DEPENDENCY,...]]|REQUIREMENT[,REQUIREMENT,...] ``` -------------------------------- ### Get Specific Gem Version Details Source: https://guides.rubygems.org/rubygems-org-api-v2 Use this endpoint to retrieve detailed information about a specific version of a gem. You can optionally specify a platform to get version details for that particular platform. ```bash $ curl https://rubygems.org/api/v2/rubygems/coulda/versions/0.7.1.json ``` -------------------------------- ### Install Gems with Trust Policies Source: https://guides.rubygems.org/security Use the `-P` flag with `gem install` to enforce security policies. Bundler uses the `--trust-policy` flag. Note that gem certificates are trusted globally. ```bash gem install gemname -P HighSecurity ``` ```bash gem install gemname -P MediumSecurity ``` ```bash bundle --trust-policy MediumSecurity ``` -------------------------------- ### Install Gems Locally with Bundler Source: https://guides.rubygems.org/faqs Use the `--local` flag with `bundle install` to force Bundler to use only locally cached gems and avoid connecting to the gem server. This is useful when you do not have an internet connection. ```bash $ bundle install --local ``` -------------------------------- ### Get Info for a Specific Rubygem Source: https://guides.rubygems.org/rubygems-org-compact-index-api Retrieves a custom text-based format for a single rubygem, providing a line for each version of that rubygem. This is useful for getting detailed version history and associated information for a particular gem. ```APIDOC ## GET /info/ ### Description Returns a custom text based format for the single rubygem named by `` with a line for each version of the rubygem. ### Method GET ### Endpoint /info/ ### Parameters #### Path Parameters - **RUBYGEM** (string) - Required - The name of the rubygem to retrieve information for. ### Response #### Success Response (200) - **Format**: Custom text-based format. - Each line represents a version of the rubygem with the format: `VERSION VERSION_PLATFORM[,VERSION_PLATFORM],...] MD5` - `VERSION`: The version of the rubygem. - `VERSION_PLATFORM`: Dependency information and platform. - `MD5`: MD5 hash of the rubygem "info" file. ### Response Example ``` --- 2.2.2 actionmailer:= 2.2.2,actionpack:= 2.2.2,activerecord:= 2.2.2,activeresource:= 2.2.2,activesupport:= 2.2.2,rake:>= 0.8.3|checksum:84fd0ee92f92088cff81d1a4bcb61306bd4b7440b8634d7ac3d1396571a2133f 2.3.2 actionmailer:= 2.3.2,actionpack:= 2.3.2,activerecord:= 2.3.2,activeresource:= 2.3.2,activesupport:= 2.3.2,rake:>= 0.8.3|checksum:ac61e0356987df34dbbafb803b98f153a663d3878a31f1db7333b7cd987fd044 [...SNIP...] 7.1.3.2 actioncable:= 7.1.3.2,actionmailbox:= 7.1.3.2,actionmailer:= 7.1.3.2,actionpack:= 7.1.3.2,actiontext:= 7.1.3.2,actionview:= 7.1.3.2,activejob:= 7.1.3.2,activemodel:= 7.1.3.2,activerecord:= 7.1.3.2,activestorage:= 7.1.3.2,activesupport:= 7.1.3.2,bundler:>= 1.15.0,railties:= 7.1.3.2|checksum:2d787a65e87b70ee65f9d1cb644aaa5bb80eea12298982f474da949772c1bfa0,ruby:>= 2.7.0,rubygems:>= 1.8.11 ``` ``` -------------------------------- ### Display RubyGems Environment Information Source: https://guides.rubygems.org/command-reference Use `gem environment` to display information about the RubyGems installation, configuration, and paths. It can display specific details like gem installation paths, search paths, or remote sources. ```bash gem environment [arg] [options] ```