

Google Cloud Shell allows you to install software. You may want to download new tools or upgrade existing tools, e.g. upgrade the version of Terraform that runs in Cloud Shell.
By default software changes do not persist in Cloud Shell. When you return to Cloud Shell after the session ends (due to inactivity for a period of time), the installed software / upgrades are no longer there. In this way Cloud Shell is ephemeral. From Cloud Shell Quotas and limits > Non-interactive usage:
“Cloud Shell is intended for interactive use only. Non-interactive sessions are ended automatically after 40 minutes. Cloud Shell sessions are capped at 12 hours, after which sessions automatically terminate. You can start a new session immediately after.”
How can you get the change to persist beyond 40 minutes of Cloud Shell inactivity? There is a file you can edit to make changes “persistent” — $HOME/.customize_environment. What really happens is that the commands in .customize_environment run each time there is a new Cloud Shell session.
In Cloud Shell enter:
nano $HOME/.customize_environment
You can use whatever Linux text editor is loaded in Cloud Shell, e.g. vi.
As an example, to upgrade to the latest version of Terraform, in nano copy and paste the following into .customize_environment (for more on contents, see https://www.tecmint.com/install-terraform-in-linux/.):
#!/bin/sh# 1. Add HashiCorp GPG key
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg - dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg - yes
# 2. Add the official HashiCorp repository
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
# 3. Update package list to include HashiCorp repo
sudo apt update
# 4. Install Terraform
sudo apt install terraform
Save the changes to .customize_environment in nano with the following:
- Ctrl-X to exit
- Y to save
to save .customize_environment in place
Note: If you used another text editor, follow the instructions for that text editor to save the changes.
If you want to install a specific version of Terraform, change the last command to the following…
# 4. Install a specific version of Terraform
sudo apt install -y terraform=1.10.5–1
…or instead of 1.10.5–1 to whatever Terraform version you need. Choose versions from here: https://releases.hashicorp.com/terraform/. Note that it seems you need the -1 on the end of the version for this command.
It can take 5–10+ seconds in a new Cloud Shell session (one that has timed out and ended) for the commands in .customize_environment to run. Here’s an example related to Terraform (the next section shows how to upgrade Terraform for each session):
admin_@cloudshell:~ (prj-test)$ terraform version && date
Terraform v1.5.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v4.64.0
Your version of Terraform is out of date! The latest version
is 1.12.2. You can update by downloading from https://www.terraform.io/downloads.html
Thu Jul 31 01:47:35 PM UTC 2025
admin_@cloudshell:~ (prj-test)$ terraform version && date
Terraform v1.5.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v4.64.0
Your version of Terraform is out of date! The latest version
is 1.12.2. You can update by downloading from https://www.terraform.io/downloads.html
Thu Jul 31 01:47:37 PM UTC 2025admin_@cloudshell:~ (prj-test)$ terraform version && date
Terraform v1.12.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v4.64.0
Thu Jul 31 01:47:40 PM UTC 2025admin_@cloudshell:~ (prj-test)$
Notice that the first 2 times running the terraform version command, the the older version is still loaded, v1.5.7. By the 3rd time the terraform version command is run, the latest version of Terraform (as of when this blog was written, v1.12.2) is loaded.
I hope this helps!
Source Credit: https://medium.com/google-cloud/how-to-make-persistent-changes-to-software-in-google-cloud-shell-84081f7bbc61?source=rss—-e52cf94d98af—4