This page describes how to enable, disable, and check the status of Object
Versioning on a bucket. See Using versioned objects to learn how
to list, restore, and delete the objects that are retained by Object Versioning.
Required roles
To get the permissions that you need to set and manage Object Versioning
on a bucket, ask your administrator to grant you the Storage Admin
(roles/storage.admin) IAM role on the bucket or the project
that contains the bucket. This predefined role contains the permissions
required to set and manage Object Versioning for a bucket. To see the exact
permissions that are required, expand the Required permissions section:
Required permissions
storage.buckets.get
storage.buckets.update
storage.buckets.list
This permission is only required if you plan on using the
Google Cloud console to perform the instructions on this page.
You might also be able to get these permissions with custom roles.
You enable or disable Object Versioning by setting the feature on a bucket.
After Object Versioning is enabled, each time a live object version is replaced
or deleted, that version becomes a noncurrent version.
Console
In the Google Cloud console, go to the Cloud Storage Buckets page.
In the list of buckets, click the name of the bucket for which you want
to enable or disable Object Versioning.
Select the Protection tab near the top of the page.
The current status of Object versioning is found in the Object
versioning section.
In the Object versioning section, click the current status to make
changes to it.
The Object versioning dialog appears.
If you're enabling Object Versioning and you want to minimize storage
costs, select the Add recommended lifecycle rules to manage
version costs checkbox.
The following sample enables Object Versioning on a bucket:
usingGoogle.Apis.Storage.v1.Data;usingGoogle.Cloud.Storage.V1;usingSystem;publicclassBucketEnableVersioningSample{publicBucketBucketEnableVersioning(stringbucketName="your-bucket-name"){varstorage=StorageClient.Create();varbucket=storage.GetBucket(bucketName);if(bucket.Versioning==null){bucket.Versioning=newBucket.VersioningData();}bucket.Versioning.Enabled=true;bucket=storage.UpdateBucket(bucket);Console.WriteLine($"Versioning is now enabled for bucket {bucketName}.");returnbucket;}}
The following sample disables Object Versioning on a bucket:
usingGoogle.Apis.Storage.v1.Data;usingGoogle.Cloud.Storage.V1;usingSystem;publicclassBucketDisableVersioningSample{publicBucketBucketDisableVersioning(stringbucketName="your-bucket-name"){varstorage=StorageClient.Create();varbucket=storage.GetBucket(bucketName);if(bucket.Versioning?.Enabled!=true){Console.WriteLine($"Versioning already disabled for bucket {bucketName}.");}else{bucket.Versioning.Enabled=false;bucket=storage.UpdateBucket(bucket);Console.WriteLine($"Versioning is now disabled for bucket {bucketName}.");}returnbucket;}}
The following sample enables Object Versioning on a bucket:
import("context""fmt""io""time""cloud.google.com/go/storage")// enableVersioning enables object versioning on a bucket.funcenableVersioning(wio.Writer,bucketNamestring)error{// bucketName := "bucket-name"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()ctx,cancel:=context.WithTimeout(ctx,time.Second*10)defercancel()bucket:=client.Bucket(bucketName)bucketAttrsToUpdate:=storage.BucketAttrsToUpdate{VersioningEnabled:true,}if_,err:=bucket.Update(ctx,bucketAttrsToUpdate);err!=nil{returnfmt.Errorf("Bucket(%q).Update: %w",bucketName,err)}fmt.Fprintf(w,"Versioning was enabled for %v\n",bucketName)returnnil}
The following sample disables Object Versioning on a bucket:
import("context""fmt""io""time""cloud.google.com/go/storage")// disableVersioning disables object versioning on a bucket.funcdisableVersioning(wio.Writer,bucketNamestring)error{// bucketName := "bucket-name"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()ctx,cancel:=context.WithTimeout(ctx,time.Second*10)defercancel()bucket:=client.Bucket(bucketName)bucketAttrsToUpdate:=storage.BucketAttrsToUpdate{VersioningEnabled:false,}if_,err:=bucket.Update(ctx,bucketAttrsToUpdate);err!=nil{returnfmt.Errorf("Bucket(%q).Update: %w",bucketName,err)}fmt.Fprintf(w,"Versioning was disabled for %v\n",bucketName)returnnil}
The following sample enables Object Versioning on a bucket:
importcom.google.cloud.storage.Bucket;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.StorageOptions;publicclassEnableBucketVersioning{publicstaticvoidenableBucketVersioning(StringprojectId,StringbucketName){// The ID of your GCP project// String projectId = "your-project-id";// The ID of your GCS bucket// String bucketName = "your-unique-bucket-name";Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService();Bucketbucket=storage.get(bucketName);bucket.toBuilder().setVersioningEnabled(true).build().update();System.out.println("Versioning is now enabled for bucket "+bucketName);}}
The following sample disables Object Versioning on a bucket:
importcom.google.cloud.storage.Bucket;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.StorageOptions;publicclassDisableBucketVersioning{publicstaticvoiddisableBucketVersioning(StringprojectId,StringbucketName){// The ID of your GCP project// String projectId = "your-project-id";// The ID of your GCS bucket// String bucketName = "your-unique-bucket-name";Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService();Bucketbucket=storage.get(bucketName);bucket.toBuilder().setVersioningEnabled(false).build().update();System.out.println("Versioning is now disabled for bucket "+bucketName);}}
The following sample enables Object Versioning on a bucket:
/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();asyncfunctionenableBucketVersioning(){awaitstorage.bucket(bucketName).setMetadata({versioning:{enabled:true,},});console.log(`Versioning is enabled for bucket ${bucketName}`);}enableBucketVersioning().catch(console.error);
The following sample disables Object Versioning on a bucket:
/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();asyncfunctiondisableBucketVersioning(){awaitstorage.bucket(bucketName).setMetadata({versioning:{enabled:false,},});console.log(`Versioning is disabled for bucket ${bucketName}`);}disableBucketVersioning().catch(console.error);
The following sample enables Object Versioning on a bucket:
use Google\Cloud\Storage\StorageClient;/** * Enable versioning on the specified bucket. * * @param string $bucketName The name of your Cloud Storage bucket. * (e.g. 'my-bucket') */function enable_versioning(string $bucketName): void{ $storage = new StorageClient(); $bucket = $storage->bucket($bucketName); $bucket->update([ 'versioning' => [ 'enabled' => true, ] ]); printf('Versioning is now enabled for bucket %s', $bucketName);}
The following sample disables Object Versioning on a bucket:
use Google\Cloud\Storage\StorageClient;/** * Disable versioning of the given bucket. * * @param string $bucketName The name of your Cloud Storage bucket. * (e.g. 'my-bucket') */function disable_versioning(string $bucketName): void{ $storage = new StorageClient(); $bucket = $storage->bucket($bucketName); $bucket->update([ 'versioning' => [ 'enabled' => false, ] ]); printf('Versioning is now disabled for bucket %s', $bucketName);}
The following sample enables Object Versioning on a bucket:
fromgoogle.cloudimportstoragedefenable_versioning(bucket_name):"""Enable versioning for this bucket."""# bucket_name = "my-bucket"storage_client=storage.Client()bucket=storage_client.get_bucket(bucket_name)bucket.versioning_enabled=Truebucket.patch()print(f"Versioning was enabled for bucket {bucket.name}")returnbucket
The following sample disables Object Versioning on a bucket:
fromgoogle.cloudimportstoragedefdisable_versioning(bucket_name):"""Disable versioning for this bucket."""# bucket_name = "my-bucket"storage_client=storage.Client()bucket=storage_client.get_bucket(bucket_name)bucket.versioning_enabled=Falsebucket.patch()print(f"Versioning was disabled for bucket {bucket}")returnbucket
The following sample enables Object Versioning on a bucket:
defenable_versioningbucket_name:# The ID of your GCS bucket# bucket_name = "your-unique-bucket-name"require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucketbucket_namebucket.versioning=trueputs"Versioning was enabled for bucket #{bucket_name}"end
The following sample disables Object Versioning on a bucket:
defdisable_versioningbucket_name:# The ID of your GCS bucket# bucket_name = "your-unique-bucket-name"require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucketbucket_namebucket.versioning=falseputs"Versioning was disabled for bucket #{bucket_name}"end
Rust
The following sample enables Object Versioning on a bucket:
usegoogle_cloud_storage::client::StorageControl;usegoogle_cloud_storage::model::bucket::Versioning;usegoogle_cloud_wkt::FieldMask;pubasyncfnsample(client:&StorageControl,bucket_id:&str)->anyhow::Result<()>{letbucket=client.get_bucket().set_name(format!("projects/_/buckets/{bucket_id}")).send().await?;letmetageneration=bucket.metageneration;letbucket=client.update_bucket().set_bucket(bucket.set_versioning(Versioning::new().set_enabled(true))).set_if_metageneration_match(metageneration).set_update_mask(FieldMask::default().set_paths(["versioning"])).send().await?;println!("Versioning enabled for bucket {bucket_id}: {bucket:?}");Ok(())}
The following sample disables Object Versioning on a bucket:
usegoogle_cloud_storage::client::StorageControl;usegoogle_cloud_storage::model::bucket::Versioning;usegoogle_cloud_wkt::FieldMask;pubasyncfnsample(client:&StorageControl,bucket_id:&str)->anyhow::Result<()>{letbucket=client.get_bucket().set_name(format!("projects/_/buckets/{bucket_id}")).send().await?;letmetageneration=bucket.metageneration;letbucket=client.update_bucket().set_bucket(bucket.set_versioning(Versioning::new().set_enabled(false))).set_if_metageneration_match(metageneration).set_update_mask(FieldMask::default().set_paths(["versioning"])).send().await?;println!("Versioning disabled for bucket {bucket_id}: {bucket:?}");Ok(())}
REST APIs
JSON API
Have gcloud CLI installed and initialized, which lets
you generate an access token for the Authorization header.
Create a JSON file that contains the following information:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-06-09 UTC."],[],[]]