meta_package_manager.managers.gem module¶

class meta_package_manager.managers.gem.Gem[source]¶

Bases: PackageManager

The RubyGems package manager.

gem emits no machine-readable format, so installed, outdated and search listings are parsed from its text output. A gem can keep several versions installed side by side (molinillo (0.5.4, 0.4.5, 0.2.3)); mpm reports the highest as the installed version.

Note

All operations target the default gem scope (controlled by GEM_HOME). On system Ruby this means system-level gems, which may require elevated privileges for write operations: those carry dormant privileged markers, so mpm --sudo or a [mpm.managers.gem] sudo = true override escalates them, while nothing escalates by default. On recent macOS that default scope lives on the sealed, read-only system volume, so the gems Ruby bundles there surface as outdated yet cannot be upgraded in place, not even with sudo: point mpm at a writable, user-controlled Ruby earlier on your PATH instead. Per-scope targeting (system vs user gems) is tracked in #1725.

Tip

Installs require sudo on system ruby. I (@tresni) recommend doing something like:

$ sudo dseditgroup -o edit -a -t user wheel

And then do visudo to make it so the wheel group does not require a password. There is a line already there for it, you just need to uncomment it and save.

Initialize cli_errors list.

name: str = 'RubyGems'¶

Return package manager’s common name.

Default value is based on class name.

homepage_url: str | None = 'https://rubygems.org'¶

Home page of the project, only used in documentation for reference.

Slug of the brand mark standing for this manager in the documentation.

Names an SVG vendored under docs/assets/managers/, whose provenance and license are recorded in docs/assets/managers/logos.yaml. Inlined at the top of the manager’s page by meta_package_manager._docs; a manager leaving it unset keeps the page’s default package glyph.

Several managers legitimately share one slug, either because they wrap the same upstream (brew and cask) or because the tool has no mark of its own and its ecosystem’s stands in (apt under Debian’s swirl, cargo under Rust’s gear). Documentation-only, like homepage_url: no CLI output reads it.

platforms: frozenset[Platform] | Group | Platform | Iterable[Platform | Group] = frozenset({Platform(id='aix', name='IBM AIX'), Platform(id='almalinux', name='AlmaLinux'), Platform(id='alpine', name='Alpine Linux'), Platform(id='altlinux', name='ALT Linux'), Platform(id='amzn', name='Amazon Linux'), Platform(id='android', name='Android'), Platform(id='arch', name='Arch Linux'), Platform(id='buildroot', name='Buildroot'), Platform(id='cachyos', name='CachyOS'), Platform(id='centos', name='CentOS'), Platform(id='chromeos', name='ChromeOS'), Platform(id='clearlinux', name='Clear Linux OS'), Platform(id='cloudlinux', name='CloudLinux OS'), Platform(id='cygwin', name='Cygwin'), Platform(id='debian', name='Debian'), Platform(id='dragonfly_bsd', name='DragonFly BSD'), Platform(id='endeavouros', name='EndeavourOS'), Platform(id='exherbo', name='Exherbo Linux'), Platform(id='fedora', name='Fedora'), Platform(id='freebsd', name='FreeBSD'), Platform(id='generic_linux', name='Generic Linux'), Platform(id='gentoo', name='Gentoo Linux'), Platform(id='guix', name='Guix System'), Platform(id='haiku', name='Haiku'), Platform(id='hurd', name='GNU/Hurd'), Platform(id='ibm_powerkvm', name='IBM PowerKVM'), Platform(id='illumos', name='illumos'), Platform(id='kali', name='Kali Linux'), Platform(id='kvmibm', name='KVM for IBM z Systems'), Platform(id='linuxmint', name='Linux Mint'), Platform(id='macos', name='macOS'), Platform(id='mageia', name='Mageia'), Platform(id='mandriva', name='Mandriva Linux'), Platform(id='manjaro', name='Manjaro Linux'), Platform(id='midnightbsd', name='MidnightBSD'), Platform(id='netbsd', name='NetBSD'), Platform(id='nixos', name='NixOS'), Platform(id='nobara', name='Nobara'), Platform(id='openbsd', name='OpenBSD'), Platform(id='opensuse', name='openSUSE'), Platform(id='openwrt', name='OpenWrt'), Platform(id='oracle', name='Oracle Linux'), Platform(id='os400', name='IBM i'), Platform(id='parallels', name='Parallels'), Platform(id='pidora', name='Pidora'), Platform(id='pikaos', name='PikaOS'), Platform(id='raspbian', name='Raspbian'), Platform(id='rhel', name='RedHat Enterprise Linux'), Platform(id='rocky', name='Rocky Linux'), Platform(id='scientific', name='Scientific Linux'), Platform(id='slackware', name='Slackware'), Platform(id='sles', name='SUSE Linux Enterprise Server'), Platform(id='slitaz', name='SliTaz GNU/Linux'), Platform(id='solaris', name='Solaris'), Platform(id='sourcemage', name='Source Mage GNU/Linux'), Platform(id='sunos', name='SunOS'), Platform(id='tuxedo', name='Tuxedo OS'), Platform(id='ubuntu', name='Ubuntu'), Platform(id='ultramarine', name='Ultramarine'), Platform(id='void', name='Void Linux'), Platform(id='windows', name='Windows'), Platform(id='wsl1', name='Windows Subsystem for Linux v1'), Platform(id='wsl2', name='Windows Subsystem for Linux v2'), Platform(id='xenserver', name='XenServer')})¶

List of platforms supported by the manager.

Allows for a mishmash of platforms and groups of platforms. Will be normalized into a frozenset of Platform instances at instantiation.

requirement: str | None = '>=2.5.0'¶
$ gem --version
3.0.3
post_args: tuple[str, ...] = ('--quiet',)¶

Global list of options used before and after the invoked package manager CLI.

Automatically added to each meta_package_manager.execution.CLIExecutor.run_cli() call.

Essentially used to force silencing, low verbosity or no-color output.

property installed: Iterator[Package]¶

Fetch installed packages.

$ gem list --quiet
bigdecimal (default: 1.4.1)
bundler (default: 1.17.2)
CFPropertyList (2.3.6)
cmath (default: 1.0.0)
csv (default: 3.0.9)
date (default: 2.0.0)
fileutils (1.4.1, default: 1.1.0)
io-console (0.5.6, default: 0.4.7)
ipaddr (default: 1.2.2)
molinillo (0.5.4, 0.4.5, 0.2.3)
nokogiri (1.5.6)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
sqlite3 (1.3.7)
test-unit (2.0.0.0)
property outdated: Iterator[Package]¶

Fetch outdated packages.

$ gem outdated --quiet
did_you_mean (1.0.0 < 1.0.2)
io-console (0.4.5 < 0.4.6)
json (1.8.3 < 2.0.1)
minitest (5.8.3 < 5.9.0)
power_assert (0.2.6 < 0.3.0)
psych (2.0.17 < 2.1.0)
search(query, extended, exact)[source]¶

Fetch matching packages.

Caution

Search does not supports extended mode.

$ gem search python --versions --quiet
at_coder_friends-generator-python_ref (0.2.0)
bee_python (0.2.3)
dependabot-python (0.117.5)
logstash-filter-python (0.0.1 java)
python (0.0.1)
python-generator (1.1.0)
python_with_git_test (2.499.8)
rabbit-slide-niku-erlangvm-for-pythonista (2015.09.12)
RubyToPython (0.0)
$ gem search python --versions --exact --quiet
python (0.0.1)
Return type:

Iterator[Package]

install(package_id, version=None)[source]¶

Install one package.

$ gem install --quiet markdown
Fetching kramdown-2.3.1.gem
Fetching concurrent-ruby-1.1.9.gem
(...)
Fetching rubyzip-2.3.2.gem
Fetching logutils-0.6.1.gem
Fetching markdown-1.2.0.gem
Successfully installed kramdown-2.3.1
Successfully installed rubyzip-2.3.2
(...)
Successfully installed markdown-1.2.0
(...)
Parsing documentation for markdown-1.2.0
Installing ri documentation for markdown-1.2.0
Done installing documentation for (...) markdown after 19 seconds
12 gems installed
Return type:

str

upgrade_all_cli()[source]¶

Generates the CLI to upgrade all outdated packages.

$ gem update --quiet
Return type:

tuple[str, ...]

upgrade_one_cli(package_id, version=None)[source]¶

Generates the CLI to upgrade the provided package.

$ gem update --quiet markdown
Return type:

tuple[str, ...]

remove(package_id)[source]¶

Remove one package.

$ gem uninstall left-pad --quiet
Successfully uninstalled left-pad-1.1.0
Return type:

str

sync()[source]¶

Sync package metadata.

$ gem sources --update --quiet
Return type:

None

cleanup_cache()[source]¶

Removes things we don’t need anymore.

$ gem cleanup --quiet
Cleaning up installed gems...
Attempting to uninstall test-unit-3.2.9
Unable to uninstall test-unit-3.2.9:
    Gem::FilePermissionError: You don't have write permissions             for the /Library/Ruby/Gems/2.6.0 directory.
Attempting to uninstall did_you_mean-1.3.0
Unable to uninstall did_you_mean-1.3.0:
    Gem::FilePermissionError: You don't have write permissions             for the /Library/Ruby/Gems/2.6.0 directory.
Clean up complete
Return type:

None

cli_names: tuple[str, ...] = ('gem',)¶

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

doctor_cli()[source]¶

Generates the CLI running the native self-diagnosis.

check verifies the integrity of every installed gem, exiting non-zero on problems.

$ gem check --quiet
Return type:

tuple[str, ...]

id: str = 'gem'¶

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

virtual: bool = False¶

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.