[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# The Ruby runtime\n\nYour Cloud Run function runs in an environment consisting of an\noperating system version with add-on packages, language support, and\nthe [Ruby Functions Framework](https://github.com/GoogleCloudPlatform/functions-framework-ruby)\nlibrary that supports and invokes your function. This\nenvironment is identified by the language version, and is known as the\nruntime ID.\n\nFunction preparation\n--------------------\n\nYou can prepare a function directly from the Google Cloud console or write it on\nyour local machine and upload it. To prepare your local machine for Ruby\ndevelopment, see [Set up a Ruby development environment](/ruby/docs/setup).\n\nSupported Ruby runtimes and base images\n---------------------------------------\n\nSelect your runtime\n-------------------\n\nYou can select one of the supported Ruby runtimes for your function during\ndeployment.\n\n\nYou can select a runtime version using the Google Cloud console, or the\ngcloud CLI. Click the tab for instructions on using the tool of\nyour choice: \n\n### gcloud\n\nSpecify the [Ruby base image](/run/docs/configuring/services/runtime-base-images#how_to_obtain_base_images) for your function using the `--base-image` flag,\nwhile deploying your function. For example: \n\n gcloud run deploy \u003cvar translate=\"no\"\u003eFUNCTION\u003c/var\u003e \\\n --source . \\\n --function \u003cvar translate=\"no\"\u003eFUNCTION_ENTRYPOINT\u003c/var\u003e \\\n --base-image ruby34\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eFUNCTION\u003c/var\u003e with the name of the function you are\n deploying. You can omit this parameter entirely,\n but you will be prompted for the name if you omit it.\n\n- \u003cvar translate=\"no\"\u003eFUNCTION_ENTRYPOINT\u003c/var\u003e with the entry point to your function in\n your source code. This is the code Cloud Run executes when your\n function runs. The value of this flag must be a function name or\n fully-qualified class name that exists in your source code.\n\nFor detailed instructions on deploying a function using the gcloud CLI, see [Deploy functions in Cloud Run](/run/docs/deploy-functions#gcloud).\n\n### Console\n\nYou can select a runtime version when you create or update a Cloud Run function in the Google Cloud console. For detailed\ninstructions on deploying a function, see [Deploy functions in Cloud Run](/run/docs/deploy-functions#deploy-functions).\n\nTo select a runtime in the Google Cloud console when you create a function, follow these steps:\n\n1. In the Google Cloud console, go to the Cloud Run page:\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n2. Click **Write a function**.\n\n3. In the **Runtime** list, select a Ruby runtime version.\n\n4. Click **Create**, and wait for Cloud Run to create the service\n using a placeholder revision.\n\n5. The console will redirect you to the **Source**\n tab where you can see the source code of your function. Click **Save and redeploy**.\n\nFor detailed instructions on updating the runtime version after your function is\ndeployed, see\n[Re-deploy new source code](/run/docs/deploy-functions#update-code-functions).\n\nSource code structure\n---------------------\n\nFor Cloud Run functions to find your function's definition, your\nsource code must follow a specific structure. See\n[Write Cloud Run functions](/run/docs/write-functions#ruby) for\nmore information.\n\nSpecify dependencies\n--------------------\n\nCloud Run functions written in Ruby use\n[bundler](https://bundler.io) to access dependencies.\n\nThe [Functions Framework](https://github.com/GoogleCloudPlatform/functions-framework-ruby)\nis a required dependency for all functions. Although\nCloud Run functions installs it on your behalf when the function\nis created, we recommend that you include it as an explicit dependency for\nclarity.\n\nIf your\nfunction relies on private dependencies, we recommend that you\nmirror `functions-framework` to your private registry. Include the mirrored\n`functions-framework` as a dependency to your function to avoid installing the\npackage from the public internet.\n\nEach function must provide a `Gemfile` that specifies the `functions_framework`\ngem, along with any additional gems needed by the function. `Gemfile` must be in\nthe same directory as the `app.rb` file that contains your function code. In\naddition, your function must provide a lockfile that specifies all the\ntransitive dependencies and their exact versions. This file, `Gemfile.lock`, is\nalso located in the same directory alongside the `Gemfile`.\n\nWhen you deploy your function, Cloud Run downloads and installs\nthe dependencies declared in the `Gemfile` and `Gemfile.lock` using `bundler`.\n\nThe `Gemfile` lists the packages required by your function, along with any\noptional version constraints. For more details, see the\n[Gemfile reference](https://bundler.io/gemfile.html).\n\nThe following is an example `Gemfile`: \n\n```\nsource \"https://rubygems.org\"\n\ngem \"functions_framework\", \"~\u003e 0.7\"\ngem \"google-cloud-storage\", \"~\u003e 1.29\"\n```\n\n### Packaging local dependencies\n\nYou can also package and deploy dependencies alongside alongside your function.\nThis approach is useful if your dependency is not available using the\n[rubygems package manager](https://rubygems.org/pages/download).\n\nTo package a gem locally, include it in a directory in your function's directory\nstructure, and provide the path in the dependency's `Gemfile` entry. The gem\ndirectory must include a valid `gemspec` file, and it must be located within the\nfunction's directory hierarchy so that its code is deployed along with your\nfunction. For example, you might use a directory structure such as the\nfollowing: \n\n```\nmyfunction/\n├── Gemfile\n├── Gemfile.lock\n├── app.rb\n└── my_private_gem/\n ├── lib/\n | └── my_private_gem.rb\n └── my_private_gem.gemspec\n```\n\nThe `Gemfile` entry might look like this: \n\n```\nsource \"https://rubygems.org\"\n\ngem \"functions_framework\", \"~\u003e 0.7\"\ngem \"my_private_gem\", path: \"./my_private_gem\"\n```\n\nSee the [Gemfile reference](https://bundler.io/gemfile.html) for more discussion\nabout referencing local gem paths."]]