Quickstart for Debian

This quickstart shows you how to set up an Artifact Registry Apt repository, add a Debian package to the repository, and install the package.

You perform steps in this quickstart using Cloud Shell or a local shell that runs on a Debian-based operating system.

To learn more about managing Debian packages, see Working with Debian packages.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  4. Enable the Artifact Registry API.

    Enable the API

  5. Install and initialize the Cloud SDK.
  6. Create a new VM where you'll install the sample package. Run the following command, replacing VM_NAME with a name for the VM.
      gcloud compute instances create VM_NAME \
          --image-family=debian-10 \
          --image-project=debian-cloud \
          --scopes=cloud-platform
  7. Grant repository access permissions to your VM's service account.

Create a repository

Create the repository for your artifacts.

  1. Create the repository:

    Console

    1. Open the Repositories page in the Cloud Console.

      Open the Repositories page

    2. Click Create Repository.

    3. Specify quickstart-apt-repo as the repository name.

    4. Select Apt as the format.

    5. Under Location Type, select Region and then choose the location us-central1.

    6. Click Create.

    The repository is added to the repository list.

    gcloud

    1. Run the following command to create a new Apt repository in the current project named quickstart-apt-repo in the location us-central1.

      gcloud artifacts repositories create quickstart-apt-repo \
          --repository-format=apt \
          --location=us-central1 \
          --description="Apt repository"
      
    2. Run the following command to verify that your repository was created:

      gcloud artifacts repositories list
      
    3. To simplify gcloud commands, set the default repository to quickstart-apt-repo and the default location to us-central1. After the values are set, you do not need to specify them in gcloud commands that require a repository or a location.

      To set the repository, run the command:

      gcloud config set artifacts/repository quickstart-apt-repo
      

      To set the location, run the command:

      gcloud config set artifacts/location us-central1
      

      For more information about these commands, see the gcloud config set documentation.

Configure the package manager

To install a package on a VM, add the repository you created to the Apt file that defines package repositories.

  1. Go to the VM instances page.

    Open the VM instances page

  2. In the row with your VM, click SSH. A new window opens with a terminal session on the VM.

  3. Run gcloud init to initialize the Cloud SDK on your VM.

  4. Update Apt:

    sudo apt update
    
  5. Install the Apt credential helper on the VM to enable Apt to perform authentication:

    sudo apt install apt-transport-artifact-registry
    
  6. Configure your VM to access Artifact Registry packages using the following command:

    echo 'deb ar+https://us-central1-apt.pkg.dev/projects/PROJECT quickstart-apt-repo main' | sudo tee -a  /etc/apt/sources.list.d/artifact-registry.list
    

    Replace PROJECT with your Google Cloud project ID.

Add a package to the repository

You can upload a package to a repository using the gcloud command-line tool, or you can import a package that is stored in Cloud Storage. If you build packages using Cloud Build, the build can store the packages in Cloud Storage for you to import.

For this quickstart, you upload a sample file using the gcloud beta artifacts apt upload command.

  1. Download the Apt quick reference sheet with the command:

    sudo apt download apt-dpkg-ref
    

    Apt downloads the latest version of the package that is available from your configured Debian repositories.

    Get:1 http://deb.debian.org/debian buster/main amd64 apt-dpkg-ref all 5.3.1+nmu2 [113 kB]
    Fetched 113 kB in 0s (428 kB/s)
    

    Run ls to get the filename of the Apt quick reference sheet. The filename is similar to apt-dpkg-ref_5.3.1+nmu2_all.deb.

  2. Run the gcloud beta artifacts apt upload to upload the package to the repository:

    gcloud beta artifacts apt upload quickstart-apt-repo \
        --location=us-central1 \
        --source=FILE_NAME
    

    Replace FILE_NAME with the path to the Apt quick reference sheet.

View the package in the repository

Verify that your package was added to the repository.

Console

  1. Open the Repositories page in the Cloud Console.

    Open the Repositories page

  2. In the repository list, click the quickstart-apt-repo repository.

    The Packages page lists the packages in the repository.

gcloud

To list the packages in the quickstart-apt-repo repository, run the command:

 gcloud artifacts packages list --repository=quickstart-apt-repo

To view versions for a package in quickstart-apt-repo, run the command:

gcloud artifacts versions list --package=apt-dpkg-ref

Install the package

Install the package that you added to the repository.

  1. Update the list of available packages:

    sudo apt update
    
  2. Install the package in your repository.

    sudo apt install apt-dpkg-ref/quickstart-apt-repo
    

    The returned installation information looks like the following example:

    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Selected version '5.3.1+nmu2' (Debian:10.7/stable, namespaces/my-repo/repositories/quickstart-apt-repo:quickstart
    -apt-repo [all]) for 'apt-dpkg-ref'
    The following NEW packages will be installed:
      apt-dpkg-ref
    0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
    Need to get 113 kB of archives.
    After this operation, 128 kB of additional disk space will be used.
    Get:1 http://deb.debian.org/debian buster/main amd64 apt-dpkg-ref all 5.3.1+nmu2 [113 kB]
    Fetched 113 kB in 0s (693 kB/s)
    Selecting previously unselected package apt-dpkg-ref.
    (Reading database ... 39506 files and directories currently installed.)
    Preparing to unpack .../apt-dpkg-ref_5.3.1+nmu2_all.deb ...
    Unpacking apt-dpkg-ref (5.3.1+nmu2) ...
    Setting up apt-dpkg-ref (5.3.1+nmu2) ...
    

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.

Before you remove the repository, ensure that any packages you want to keep are available in another location.

To delete the repository:

Console

  1. Open the Repositories page in the Cloud Console.

    Open the Repositories page

  2. In the repository list, select the quickstart-apt-repo repository.

  3. Click Delete.

gcloud

  1. To delete the quickstart-apt-repo repository, run the following command:

    gcloud artifacts repositories delete quickstart-apt-repo
    
  2. If you want to remove the default repository and location settings that you configured for the active gcloud configuration, run the following commands:

    gcloud config unset artifacts/repository
    gcloud config unset artifacts/location
    

To delete the VM you created, run the following command. Replace VM_NAME with the name of the VM.

gcloud compute instances delete VM_NAME

What's next