[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-03 (世界標準時間)。"],[[["\u003cp\u003eRuby functions in Cloud Run utilize Bundler to manage dependencies, which can be downloaded during deployment or packaged locally with the function.\u003c/p\u003e\n"],["\u003cp\u003eEach function requires both a \u003ccode\u003eGemfile\u003c/code\u003e listing dependencies, including the \u003ccode\u003efunctions_framework\u003c/code\u003e gem, and a \u003ccode\u003eGemfile.lock\u003c/code\u003e file specifying the exact versions of all transitive dependencies, located in the same directory as the function code.\u003c/p\u003e\n"],["\u003cp\u003eTo install dependencies locally, the \u003ccode\u003ebundle install\u003c/code\u003e command is used, generating a \u003ccode\u003eGemfile.lock\u003c/code\u003e if one does not exist, or the \u003ccode\u003ebundle lock\u003c/code\u003e command to generate one if it does not exist.\u003c/p\u003e\n"],["\u003cp\u003eLocal gems can be packaged by including them in a subdirectory within the function's directory structure, specifying their path in the \u003ccode\u003eGemfile\u003c/code\u003e, useful for private or unavailable dependencies through the public rubygems package manager.\u003c/p\u003e\n"],["\u003cp\u003eWhile Cloud Run installs the \u003ccode\u003efunctions_framework\u003c/code\u003e, it's recommended to include it as an explicit dependency in the \u003ccode\u003eGemfile\u003c/code\u003e for clarity, especially when mirroring \u003ccode\u003efunctions-framework\u003c/code\u003e to a private registry for private dependencies.\u003c/p\u003e\n"]]],[],null,["# Specify dependencies in Ruby\n============================\n\nCloud Run functions written in Ruby use\n[bundler](https://bundler.io) to access\ndependencies. Dependencies can be downloaded when your function is deployed, or\npackaged locally alongside your function.\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 functions 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\nYou run the following command to install the `functions_framework` gem and other\ndependencies: \n\n bundle install\n\nThe `Gemfile.lock` is generated by bundler when it analyzes your dependencies,\nand freezes the exact versions of each gem to be installed. This ensures, for\nexample, that your function is deployed with the same dependency versions as\nthose used in your local tests. The exact format of the `Gemfile.lock` is\nprivate to bundler and is not meant to be edited by hand.\n\nIf you have already used bundler to install your dependencies and run tests\nlocally, you probably already have a `Gemfile.lock` file present. If not, you\ncan generate one by running: \n\n bundle lock\n\nThe [Functions Framework](/functions/docs/functions-framework) is a\nrequired dependency for all functions. Although Cloud Run functions\ninstalls it on your behalf when the function is created, we recommend\nthat you include it as an explicit dependency for clarity.\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\nPackaging local dependencies\n----------------------------\n\nYou can also package and deploy dependencies alongside alongside your function.\nThis approach is useful if your dependency is not available via 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\n[Gemfile reference](https://bundler.io/gemfile.html)\nfor more discussion about referencing local gem paths."]]