Install, Inspect and Build Ruby Gems with gem3.2

Two Ruby versions on one box means two gem commands, and gem3.2 is the one that manages packages for Ruby 3.2 specifically. You will identify the installed RubyGems version, inspect the repositories in use, install a named gem, build a package from a gemspec, and remove a disposable installation without guessing where it went. The command is the gem3.2 frontend supplied by the ruby3.2 package.

Allow about 20 minutes. You need a shell, Ruby 3.2 and network access for a remote install. The examples use rake for inspection and sample-gem as a placeholder for a package you have deliberately chosen. Installing or removing system gems may require elevated privileges, so the workflow starts with read-only checks and prefers a user-owned repository for experiments.

1. Confirm the executable and version

Start with commands that only read local state:

$ command -v gem3.2
/usr/bin/gem3.2
$ gem3.2 --version
3.4.20
$ dpkg-query -W -f='${Package} ${Version}\n' ruby3.2 ruby-rubygems
ruby-rubygems 3.4.20-1
ruby3.2 3.2.3-1ubuntu0.24.04.8

Your package revision may differ. The installed command reports RubyGems 3.4.20 on this machine; do not assume that another host has the same defaults just because it also has Ruby 3.2.

Checkpoint: If command -v finds a different executable, stop and inspect that installation before comparing output with this guide.

2. Inspect the active gem environment

RubyGems has a system installation directory, a user installation directory and a search path. Ask it for the complete view before changing anything:

$ gem3.2 environment
RubyGems Environment:
  - RUBYGEMS VERSION: 3.4.20
  - RUBY VERSION: 3.2.3
  - INSTALLATION DIRECTORY: /var/lib/gems/3.2.0
  - USER INSTALLATION DIRECTORY: /home/alice/.local/share/gem/ruby/3.2.0
  - REMOTE SOURCES:
     - https://rubygems.org/

The full output also lists GEM PATHS, the executable directory and configuration. Paths are host-specific, so use your own output when deciding where a package will land. To query one value rather than print everything, use gem3.2 environment home or gem3.2 environment path.

Checkpoint: Record the installation directory and remote source. If a project or shell sets GEM_HOME, GEM_PATH or a custom gemrc, those settings can change the result.

3. List and inspect an installed gem

list --local searches only local repositories. This avoids a network lookup and is useful after an install:

$ gem3.2 list --local rake

*** LOCAL GEMS ***

rake (13.0.6)

The version is an example from this host. Use gem3.2 info rake for the installed location, homepage and summary. Replace rake with the exact gem name you need; a partial regular expression can match more than one package.

If the list is empty, that only means the selected local repositories have no matching gem. It does not prove that the package is unavailable remotely. Keep local and remote checks separate while diagnosing a problem.

4. Install into a user-owned repository

For a trial package, avoid changing the system repository. The installed help documents --user-install, which places the gem under the user installation directory:

$ gem3.2 install sample-gem --user-install --no-document
Successfully installed sample-gem-1.2.3
1 gem installed
$ gem3.2 list --local '^sample-gem$'

*** LOCAL GEMS ***

sample-gem (1.2.3)

sample-gem is a placeholder, not a package to paste blindly. Substitute a real name and, where reproducibility matters, add a version such as --version 1.2.3. --no-document omits generated documentation; it does not make the install safer or change the gem's code.

Installing from a remote source downloads and executes package installation hooks as part of the normal RubyGems process. Read the gem's provenance and dependencies before installing it, and do not use --force or --ignore-dependencies to silence an error you have not understood. If the package provides an executable, its location may not be on PATH; check gem3.2 environment and the package documentation.

Checkpoint: Confirm the exact installed version with gem3.2 list --local '^sample-gem$' before using it in a project.

5. Build a gem without publishing it

A gemspec describes the package. From the directory containing a reviewed gemspec, build a local artefact:

$ gem3.2 build sample_gem.gemspec --output sample-gem-1.2.3.gem
Successfully built RubyGem
  Name: sample-gem
  Version: 1.2.3
  File: sample-gem-1.2.3.gem

RubyGems validates the specification and writes the .gem file in the current directory unless you choose another output path. Check the result before distributing it:

$ gem3.2 specification sample-gem-1.2.3.gem name version
---
name: sample-gem
version: !ruby/object:Gem::Version
  version: 1.2.3

Exact formatting varies by RubyGems version. Building is not publishing: this workflow does not call gem push and changes only the output file you requested.

6. Remove a disposable installation

Uninstalling changes the gem repository. Treat it as destructive, especially on a shared system. First identify the version and installation path:

$ gem3.2 info sample-gem
sample-gem (1.2.3)
    Installed at: /home/alice/.local/share/gem/ruby/3.2.0
$ gem3.2 uninstall sample-gem --version 1.2.3
Successfully uninstalled sample-gem-1.2.3

RubyGems can ask for confirmation when another installed gem depends on the target. Do not add --ignore-dependencies merely to force the removal. If you removed the wrong package, reinstall the same version with gem3.2 install sample-gem --version 1.2.3 --user-install --no-document, subject to the package still being available.

Checkpoint: Verify the removal:

$ gem3.2 list --local '^sample-gem$'

*** LOCAL GEMS ***

Common traps

Done means