{"id":30059,"date":"2026-12-05T22:05:14","date_gmt":"2026-12-05T22:05:14","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=30059"},"modified":"2026-12-05T22:05:14","modified_gmt":"2026-12-05T22:05:14","slug":"google-cloud-tutorial-gcloud-cli-install-and-initialize","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/google-cloud-tutorial-gcloud-cli-install-and-initialize\/","title":{"rendered":"Google Cloud Tutorial &#8211; gcloud CLI Install and initialize"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This page shows how to install the Google Cloud CLI (<code>gcloud<\/code>) on Linux from the official archive, then run <code>gcloud init<\/code> to sign in and pick a default project, region and zone. Below the original steps you will find a corrected script, package-manager installs for Debian\/Ubuntu, RHEL and macOS, a way to check the setup, and fixes for the errors people hit most often.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/20d8e18d31fe69d7f02c9ce01acbca05.js\"><\/script>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What the steps above do<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Google Cloud CLI is a set of command-line tools for creating and managing Google Cloud resources. It includes <code>gcloud<\/code>, <code>gsutil<\/code> and <code>bq<\/code>. The steps above download a tarball, extract it to a <code>google-cloud-sdk<\/code> directory, run <code>install.sh<\/code> to add the tools to your <code>PATH<\/code> and turn on shell completion, and then run <code>gcloud init<\/code> to authenticate and save default settings.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Prerequisites:<\/strong> a 64-bit Linux machine, <code>curl<\/code> and <code>tar<\/code>, and a Google account that can access at least one Google Cloud project.<\/li>\n\n\n<li><strong>Python:<\/strong> <code>gcloud<\/code> runs on Python 3. Recent Linux archives ship with a bundled Python. If your system has an unsupported Python version, point the CLI at a supported one with the <code>CLOUDSDK_PYTHON<\/code> environment variable.<\/li>\n\n\n<li><strong>No install needed in Cloud Shell:<\/strong> Google Cloud Shell in the console comes with <code>gcloud<\/code> already installed and authenticated.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Corrected Linux install script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The gist above can&#039;t run as written. It downloads the <code>x86_64<\/code> archive and then tries to extract a file named <code>...-linux-x86.tar.gz<\/code>, so <code>tar<\/code> stops with a &#039;No such file&#039; error. Several lines of instructions are also not commented out, so the file fails if you run it as a shell script. It also pins version 386.0.0, which is now very old. Google publishes an unversioned download that always points to the current release. Use that instead.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">#!\/usr\/bin\/env bash<\/span>\nset -euo pipefail\ncd <span class=\"hljs-string\">\"$HOME\"<\/span>\n\n<span class=\"hljs-comment\"># Pick the archive for your CPU (check with: uname -m)<\/span>\n<span class=\"hljs-comment\">#   x86_64  -&gt; google-cloud-cli-linux-x86_64.tar.gz<\/span>\n<span class=\"hljs-comment\">#   aarch64 -&gt; google-cloud-cli-linux-arm.tar.gz<\/span>\nARCHIVE=google-cloud-cli-linux-x86_64.tar.gz\n\ncurl -O <span class=\"hljs-string\">\"https:\/\/dl.google.com\/dl\/cloudsdk\/channels\/rapid\/downloads\/${ARCHIVE}\"<\/span>\n\n<span class=\"hljs-comment\"># To replace an existing install, remove the old directory first<\/span>\n<span class=\"hljs-comment\"># rm -rf \"$HOME\/google-cloud-sdk\"<\/span>\ntar -xf <span class=\"hljs-string\">\"${ARCHIVE}\"<\/span>\n\n<span class=\"hljs-comment\"># Interactive install: answers prompts for usage stats, PATH and completion<\/span>\n.\/google-cloud-sdk\/install.sh\n\n<span class=\"hljs-comment\"># Load the PATH change into the current shell (or open a new terminal)<\/span>\nsource <span class=\"hljs-string\">\"$HOME\/.bashrc\"<\/span>\n\ngcloud init<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">For automated builds, golden images or Dockerfiles, skip the prompts and give the answers as flags:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">.\/google-cloud-sdk\/install.sh --quiet \\\n  --usage-reporting=<span class=\"hljs-literal\">false<\/span> \\\n  --path-update=<span class=\"hljs-literal\">true<\/span> \\\n  --command-completion=<span class=\"hljs-literal\">true<\/span> \\\n  --rc-path=<span class=\"hljs-string\">\"$HOME\/.bashrc\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> If you use zsh, <code>install.sh<\/code> updates <code>~\/.zshrc<\/code>. Run <code>source ~\/.zshrc<\/code> instead of <code>~\/.bashrc<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install with a package manager instead<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On servers, package-manager installs are usually easier to maintain because <code>gcloud<\/code> updates along with the rest of the system. The commands below follow Google&#039;s documented repository setup.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Debian \/ Ubuntu<\/span>\nsudo apt-get update\nsudo apt-get install -y apt-transport-https ca-certificates gnupg curl\ncurl https:<span class=\"hljs-comment\">\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg | \\<\/span>\n  sudo gpg --dearmor -o \/usr\/share\/keyrings\/cloud.google.gpg\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"deb &#91;signed-by=\/usr\/share\/keyrings\/cloud.google.gpg] https:\/\/packages.cloud.google.com\/apt cloud-sdk main\"<\/span> | \\\n  sudo tee \/etc\/apt\/sources.<span class=\"hljs-keyword\">list<\/span>.d\/google-cloud-sdk.<span class=\"hljs-keyword\">list<\/span>\nsudo apt-get update &amp;&amp; sudo apt-get install -y google-cloud-cli<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># RHEL \/ Rocky \/ AlmaLinux 9 (x86_64)<\/span>\nsudo tee \/etc\/yum.repos.d\/google-cloud-sdk.repo &lt;&lt; <span class=\"hljs-string\">'EOM'<\/span>\n&#91;google-cloud-cli]\nname=Google Cloud CLI\nbaseurl=https:<span class=\"hljs-comment\">\/\/packages.cloud.google.com\/yum\/repos\/cloud-sdk-el9-x86_64<\/span>\nenabled=<span class=\"hljs-number\">1<\/span>\ngpgcheck=<span class=\"hljs-number\">1<\/span>\nrepo_gpgcheck=<span class=\"hljs-number\">0<\/span>\ngpgkey=https:<span class=\"hljs-comment\">\/\/packages.cloud.google.com\/yum\/doc\/rpm-package-key.gpg<\/span>\nEOM\nsudo dnf install -y google-cloud-cli\n\n<span class=\"hljs-comment\"># macOS (Homebrew)<\/span>\nbrew install --cask google-cloud-sdk<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">On Windows, download and run the Google Cloud CLI installer from the official install page. It adds <code>gcloud<\/code> to <code>PATH<\/code> and can start <code>gcloud init<\/code> when it finishes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What gcloud init asks and how to answer<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Choose to sign in. A browser opens for Google login. On a machine with no browser (SSH, a VM), run <code>gcloud init --no-launch-browser<\/code> and paste the URL into a browser on another machine.<\/li>\n\n\n<li>Pick a cloud project from the list, or create a new one.<\/li>\n\n\n<li>If the Compute Engine API is enabled, choose a default region and zone. This saves you from passing <code>--region<\/code> and <code>--zone<\/code> on every command.<\/li>\n\n\n<li>The answers are saved in a named configuration called <code>default<\/code>, under <code>~\/.config\/gcloud<\/code>.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">You can change any of these defaults later without running <code>gcloud init<\/code> again:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">gcloud config <span class=\"hljs-keyword\">set<\/span> project my-project-id\ngcloud config <span class=\"hljs-keyword\">set<\/span> compute\/region us-central1\ngcloud config <span class=\"hljs-keyword\">set<\/span> compute\/zone us-central1-a<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Verify the installation<\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">gcloud version            <span class=\"hljs-comment\"># CLI and component versions<\/span>\ngcloud auth <span class=\"hljs-keyword\">list<\/span>          <span class=\"hljs-comment\"># active account is marked with *<\/span>\ngcloud config <span class=\"hljs-keyword\">list<\/span>        <span class=\"hljs-comment\"># account, project, region, zone<\/span>\ngcloud projects <span class=\"hljs-keyword\">list<\/span>      <span class=\"hljs-comment\"># confirms the credentials actually work<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><code>gcloud config list<\/code> should print something like the output below. If <code>gcloud projects list<\/code> returns your projects, authentication and network access are both working.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&#91;compute]\nregion = us-central1\nzone = us-central1-a\n&#91;core]\naccount = you@example.com\nproject = my-project-id\n\nYour active configuration is: &#91;<span class=\"hljs-keyword\">default<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Useful next steps after init<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Task<\/th><th>Command<\/th><\/tr><\/thead><tbody><tr><td>Update an archive install<\/td><td><code>gcloud components update<\/code><\/td><\/tr><tr><td>Add kubectl and the GKE auth plugin<\/td><td><code>gcloud components install kubectl gke-gcloud-auth-plugin<\/code><\/td><\/tr><tr><td>Credentials for Terraform and client libraries<\/td><td><code>gcloud auth application-default login<\/code><\/td><\/tr><tr><td>Separate dev and prod settings<\/td><td><code>gcloud config configurations create prod<\/code> then <code>gcloud config configurations activate prod<\/code><\/td><\/tr><tr><td>Authenticate a CI job with a key file<\/td><td><code>gcloud auth activate-service-account --key-file=key.json<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> <code>gcloud auth login<\/code> and <code>gcloud auth application-default login<\/code> save different credentials. Tools such as Terraform and the client libraries read Application Default Credentials, not the credentials <code>gcloud<\/code> itself uses. Run both if you use both.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the CLI is working, you can deploy services with it. See <a href=\"https:\/\/www.devopsschool.com\/blog\/google-cloud-google-cloud-run-complete-tutorials\/\">Google Cloud Run Complete Tutorials<\/a> or browse <a href=\"https:\/\/www.devopsschool.com\/blog\/category\/cloud-computing\/google-cloud\/\">more Google Cloud tutorials<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common errors and fixes<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error<\/th><th>Cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td><code>tar: ...linux-x86.tar.gz: Cannot open: No such file<\/code><\/td><td>The file name passed to <code>tar<\/code> doesn&#039;t match the downloaded file<\/td><td>Run <code>ls *.tar.gz<\/code> and extract the exact file name<\/td><\/tr><tr><td><code>gcloud: command not found<\/code><\/td><td>The shell hasn&#039;t reloaded <code>PATH<\/code>, or you said No to the PATH prompt<\/td><td>Open a new terminal or <code>source ~\/.bashrc<\/code>. You can also re-run <code>install.sh<\/code> or call <code>~\/google-cloud-sdk\/bin\/gcloud<\/code> directly<\/td><\/tr><tr><td><code>The component manager is disabled for this installation<\/code><\/td><td><code>gcloud<\/code> was installed with apt, dnf or another package manager<\/td><td>Update with the package manager, for example <code>sudo apt-get install --only-upgrade google-cloud-cli<\/code><\/td><\/tr><tr><td><code>The required property [project] is not currently set<\/code><\/td><td>No default project is set in the active configuration<\/td><td><code>gcloud config set project PROJECT_ID<\/code> or pass <code>--project<\/code><\/td><\/tr><tr><td>Python version errors at startup<\/td><td>The system Python isn&#039;t supported and no bundled Python was found<\/td><td>Install a supported Python 3 and <code>export CLOUDSDK_PYTHON=\/usr\/bin\/python3.x<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Security and housekeeping<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Don&#039;t log in with a personal account on shared servers or CI runners. Use a service account with the fewest roles needed. Where possible, use workload identity federation instead of key files.<\/li>\n\n\n<li>Credentials live in <code>~\/.config\/gcloud<\/code>. Protect that directory, and run <code>gcloud auth revoke<\/code> on machines you no longer use.<\/li>\n\n\n<li>To uninstall an archive install, delete the <code>google-cloud-sdk<\/code> directory and <code>~\/.config\/gcloud<\/code>, then remove the lines <code>install.sh<\/code> added to your shell rc file.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Is gcloud CLI the same as Google Cloud SDK?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Google renamed the Google Cloud SDK to the Google Cloud CLI. The install directory is still called <code>google-cloud-sdk<\/code>, and the Homebrew cask still uses the old name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I run gcloud init on a server without a browser?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run <code>gcloud init --no-launch-browser<\/code>. It prints a URL. Open the URL on any machine with a browser, sign in, and paste the code it gives you back into the terminal.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I check which gcloud version is installed?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run <code>gcloud version<\/code>. It lists the CLI version and every installed component. To upgrade an archive install, run <code>gcloud components update<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I switch between multiple Google Cloud projects or accounts?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a named configuration for each environment with <code>gcloud config configurations create NAME<\/code>, then switch with <code>gcloud config configurations activate NAME<\/code>. For a single command, you can use <code>--project<\/code> instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need to run gcloud init again after changing my project?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>gcloud config set project PROJECT_ID<\/code> changes the default project in the active configuration. Only run <code>gcloud init<\/code> again if you want to go through the full setup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/cloud-computing\/google-cloud\/\">More Google Cloud tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/google-cloud-google-cloud-run-complete-tutorials\/\">Google Cloud: Google Cloud Run Complete Tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/google-cloud-professional-devops-engineer-skills-and-career-guide\/\">Google Cloud Professional DevOps Engineer: Skills and Career Guide<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-google-cloud-storage-and-use-cases-of-google-cloud-storage\/\">What is Google Cloud Storage and use cases of Google Cloud Storage?<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This page shows how to install the Google Cloud CLI (gcloud) on Linux from the official archive, then run gcloud init to sign in and pick a&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[26149],"tags":[],"class_list":["post-30059","post","type-post","status-publish","format-standard","hentry","category-google-cloud"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30059","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=30059"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30059\/revisions"}],"predecessor-version":[{"id":80674,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30059\/revisions\/80674"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=30059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=30059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=30059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}