This page describes adding, viewing, and deleting Ruby gems and gem versions.
Before you begin
-
Install and initialize the Google Cloud CLI.
Google Cloud CLI version 354.0.0 or newer is required to run commands for Ruby repositories. You can check the version with the command:
gcloud version -
If the target repository doesn't exist, then create a Ruby package repository .
-
Verify that Ruby is installed. For installation instructions, see the Google Cloud tutorial for setting up Ruby .
-
(Optional) Set defaults for gcloud commands .
Required roles
To get the permissions that you need to manage gems, ask your administrator to grant you the following IAM roles on the repository:
- View gems or files in gems: Artifact Registry Reader
(
roles/artifactregistry.reader) - Download or install gems: Artifact Registry Reader
(
roles/artifactregistry.reader) - Add gems to a repository: Artifact Registry Writer
(
roles/artifactregistry.writer) - Delete gems: Artifact Registry Repository Administrator
(
roles/artifactregistry.repoAdmin)
For more information about granting roles, see Manage access to projects, folders, and organizations .
You might also be able to get the required permissions through custom roles or other predefined roles .
Add gems
Packages in Ruby are called gems , where each gem contains a name, version and platform. A Ruby project must also contain a gemfile , which is a configuration file that specifies required gem dependencies.
Repository modes :standard
When you build a Ruby project, distribution files are saved in a lib
subdirectory in your project. You can then use RubyGems to upload gems to a
standard repository.
To add a gem to your Artifact Registry repository:
gem
push
GEM_NAME
--host
https:// LOCATION
-ruby.pkg.dev/ PROJECT
/ REPOSITORY
Where:
- GEM_NAME is the name of the gem to push to your repository.
- LOCATION is the location of your repository.
- PROJECT is the project ID. If this flag is omitted, then the current or default project is used.
- REPOSITORY is the name of your repository in Artifact Registry.
View gems and versions
Repository modes :standard
To view packages and package versions using the Google Cloud console
or gcloud
:
Console
-
Open the Repositoriespage in the Google Cloud console.
-
In the repository list, click the appropriate repository.
The Packagespage lists the packages in the repository.
-
Click a package to view versions of the package.
gcloud
To list packages in a repository, run the following command:
gcloud
artifacts
packages
list
[
--repository =
REPOSITORY
]
[
--location =
LOCATION
]
Replace the following:
-
REPOSITORYis the name of the repository. If you configured a default repository, you can omit this flag to use the default. -
LOCATIONis the regional or multi-regional location of the repository. If you configured a default location, then you can omit this flag to use the default.
To view versions of a package, run the following command:
gcloud
artifacts
versions
list
--package =
PACKAGE
\
[
--repository =
REPOSITORY
]
[
--location =
LOCATION
]
Replace the following:
-
PACKAGEis the ID of the package or fully qualified identifier for the package. -
REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default. -
LOCATIONis the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.
For remote repositories, the returned list should include all direct and transitive dependencies.
List files
Repository modes :standard
You can list files in a repository, files in all versions of a specified package, or files in a specific version of a package.
For all the following commands, you can set a maximum number of files to return
by adding the --limit
flag to the command.
To list all files in the default project, repository, and location when the default values are configured :
gcloud
artifacts
files
list
To list files in a specified project, repository, and location, run the command:
gcloud
artifacts
files
list
\
--project =
PROJECT
\
--repository =
REPOSITORY
\
--location =
LOCATION
To list files for all versions of a specific package:
gcloud
artifacts
files
list
\
--project =
PROJECT
\
--repository =
REPOSITORY
\
--location =
LOCATION
\
--package =
PACKAGE
To list files for a specific package version:
gcloud
artifacts
files
list
\
--project =
PROJECT
\
--repository =
REPOSITORY
\
--location =
LOCATION
\
--package =
PACKAGE
\
--version =
VERSION
Replace the following values:
-
LOCATION: the regional or multi-regional location of the repository. -
PROJECT: your Google Cloud project ID . If your project ID contains a colon (:), see Domain-scoped projects . -
REPOSITORY: the name of the repository where the image is stored. -
PACKAGE: the name of the package. -
VERSION: the version of the package.
Examples
Consider the following package information:
- Project:
my-project - Repository:
my-repo - Repository location:
us-west1 - Package:
my-app
The following command lists all files in the repository my-repo
in the
location us-west1
within the default project
:
gcloud
artifacts
files
list
\
--location =
us-west1
\
--repository =
my-repo
1.0
of the package. gcloud
artifacts
files
list
\
--project =
my-project
\
--location =
us-west1
\
--repository =
my-repo
\
--package =
my-app
\
--version =
1
.0
Install gems
Repository modes :standard
To install the latest stable release of a package:
gem
install
GEM_NAME
For standard repositories, you download a package directly from the repository.
For a remote repository, you download a cached copy of the package and its dependencies. If a cached copy does not exist, the remote repository downloads the package from the upstream source and caches it before serving it to you. You can verify that the remote repository retrieved the packages from the upstream source by viewing the list of packages in the repository.
For a virtual repository, Artifact Registry searches upstream repositories for the requested package.
- Upstream remote repositories will download and cache the requested package if a cached copy does not exist. Virtual repositories only serve requested packages, they do not store them.
- If you request a version that is available in more than one upstream repository, Artifact Registry chooses an upstream repository to use based on the priority settings configured for the virtual repository.
For example, consider a virtual repository with the following priority settings for upstream repositories:
-
main-repo: Priority set to100 -
secondary-repo1: Priority set to80. -
secondary-repo2: Priority set to80. -
test-repo: Priority set to20.
main-repo
has the highest priority value, so the virtual repository
always searches it first.
Both secondary-repo1
and secondary-repo2
have priority set to 80
. If a
requested package is not available in main-repo
, Artifact Registry
searches these repositories next. Since they both have the same priority value,
Artifact Registry can choose to serve a package from either repository
if the version is available in both of them.
test-repo
has is lowest priority value and will serve a stored artifact if
none of the other upstream repositories has it.
Additional information
When you push gems to or pull gems from an Artifact Registry repository,
if the requested gem or
its dependencies aren't found in your specified repository, then your gem
client uses any other source that is defined in the gemfile for your gem.
If you want to only fetch and
install directly from Artifact Registry, then run the following command
to remove a non-Artifact Registry source from your gemfile:
gem
sources
--remove
SOURCE
To add rubygems.org back as a source:
gem
sources
--add
SOURCE
Where SOURCE
is the address of the source, such as https://rubygems.org
.
Delete packages and versions
Repository modes :standard
You can delete a package and all its versions, or delete a specific version.
- Once you delete a package, you cannot undo the action.
- For remote repositories, only the cached copy of the package is deleted. The upstream source is unaffected. If you delete a cached package, Artifact Registry will download and cache it again the next time the repository receives a request for the same package version.
Before you delete a package or package version, verify that any you have communicated or addressed any important dependencies on it.
To delete a package:
Console
-
Open the Repositoriespage in the Google Cloud console.
-
In the repository list, click the appropriate repository.
The Packagespage lists the packages in the repository.
-
Select the package that you want to delete.
-
Click DELETE.
-
In the confirmation dialog box, click DELETE.
gcloud
Run the following command:
gcloud
artifacts
packages
delete
PACKAGE
\
[
--repository =
REPOSITORY
]
[
--location =
LOCATION
]
[
--async ]
Replace the following:
-
PACKAGEis the name of the package in the repository. -
REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default. -
LOCATIONis the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.
The --async
flag causes the command to return immediately,
without waiting for the operation in progress to complete.
To delete versions of a package:
Console
-
Open the Repositoriespage in the Google Cloud console.
-
In the repository list, click the appropriate repository.
The Packagespage lists the packages in the repository.
-
Click a package to view versions of that package.
-
Select versions that you want to delete.
-
Click DELETE.
-
In the confirmation dialog box, click DELETE.
gcloud
Run the following command:
gcloud
artifacts
versions
delete
VERSION
\
--package =
PACKAGE
\
[
--repository =
REPOSITORY
]
[
--location =
LOCATION
]
\
[
--async ]
Replace the following:
-
VERSIONis the name of the version to delete. -
PACKAGEis the name of the package in the repository. -
REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default. -
LOCATIONis the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.
The --async
flag causes the command to return immediately,
without waiting for the operation in progress to complete.

