[[["容易理解","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-04 (世界標準時間)。"],[[["\u003cp\u003eThe Ruby runtime on App Engine supports specific Ruby versions, with Ruby 3.3 using buildpacks, and older versions like 3.1 and earlier are no longer supported, requiring upgrades or custom runtimes.\u003c/p\u003e\n"],["\u003cp\u003eTo use a supported Ruby version, you must specify the version in your \u003ccode\u003eGemfile\u003c/code\u003e, install gcloud CLI version 420.0.0 or later, and define the \u003ccode\u003eoperating_system\u003c/code\u003e in your \u003ccode\u003eapp.yaml\u003c/code\u003e file, with an optional \u003ccode\u003e.ruby-version\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eThe runtime installs dependencies from the \u003ccode\u003eGemfile\u003c/code\u003e using Bundler and pre-installs several Ubuntu packages for C extensions, but custom runtimes are needed for additional operating-system level dependencies.\u003c/p\u003e\n"],["\u003cp\u003eApplication startup is managed via the \u003ccode\u003eentrypoint\u003c/code\u003e in \u003ccode\u003eapp.yaml\u003c/code\u003e, which should start a process that responds to HTTP requests on the specified port, and most web applications utilize a Rack-supported web server like Puma.\u003c/p\u003e\n"],["\u003cp\u003eThe environment provides variables like \u003ccode\u003eGAE_INSTANCE\u003c/code\u003e, \u003ccode\u003ePORT\u003c/code\u003e, and \u003ccode\u003eGOOGLE_CLOUD_PROJECT\u003c/code\u003e, and instances can access instance information through the Compute Engine metadata server.\u003c/p\u003e\n"]]],[],null,["# The Ruby runtime\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n| **Note:** Some [Ruby runtimes](/appengine/docs/flexible/lifecycle/support-schedule#ruby) have reached [end of support](/appengine/docs/flexible/lifecycle/runtime-lifecycle#end_of_support). You cannot re-deploy versions that use runtimes after their end of support date. We recommend that you [upgrade your app](/appengine/docs/flexible/ruby/runtime#newversions) to use the latest version of Ruby.\n\n\u003cbr /\u003e\n\nThe Ruby runtime is the software stack responsible for\ninstalling your application code and dependencies, and then running that\napplication in the flexible environment.\n\nRuby versions\n-------------\n\nRuby 3.4 uses\n[buildpacks](/docs/buildpacks/overview). For the full list of supported\nRuby versions, and their corresponding Ubuntu\nversion, see the [Runtime support schedule](/appengine/docs/flexible/lifecycle/support-schedule#ruby).\n\nTo use a supported Ruby version, you must:\n\n- Specify a Ruby version in your [`Gemfile`](https://bundler.io/v2.4/man/gemfile.5.html).\n\n RUBY VERSION\n ruby 3.4.x\n\n- Install gcloud CLI version **420.0.0 or later** . You can update\n your CLI tooling by running the [`gcloud components update`](/sdk/gcloud/reference/components/update) command. To view your installed version, you can run the [`gcloud version`](/sdk/gcloud/reference/version) command.\n\n- Specify the `operating_system` setting in your `app.yaml` file:\n\n runtime: ruby\n env: flex\n\n runtime_config:\n operating_system: \"ubuntu22\"\n\n- Optionally, you can specify a version of the Ruby interpreter\n using a `.ruby-version` file in your application directory. For example, `3.4.x`\n\n### Previous versions\n\n| **Warning:** Ruby **version 3.1 and earlier** have reached end of support. App Engine blocks you from deploying your applications using runtimes that have reached end of support. We recommend that you migrate your app to use a [supported version](/appengine/docs/flexible/lifecycle/support-schedule#ruby) of Ruby or use a [custom runtime](/appengine/docs/flexible/custom-runtimes/about-custom-runtimes).\n\nTo use Ruby runtime **version 3.1 and earlier** , specify a version of the Ruby\ninterpreter using a `.ruby-version` file in your application directory.\n\nWhen this file is present, the runtime installs the requested version of\nRuby when you deploy your application using\n[rbenv](https://github.com/rbenv/rbenv).\nIf the requested version cannot be installed, App Engine shows an error\nmessage during deployment.\n\nIf you don't provide a `.ruby-version` file, the Ruby runtime defaults to\nversion 2.7. Note that the default can change at any time, so\nit is recommended that your app specifies a Ruby version.\n\n### Support for other Ruby runtimes\n\nIf you need to use a Ruby version that isn't [supported](/appengine/docs/flexible/lifecycle/support-schedule#ruby), you can create a\n[custom runtime](/appengine/docs/flexible/custom-runtimes/build) and select a\nvalid base image with the Ruby version you need.\n\nFor Google-supplied base images or\n[Docker Ruby base images](https://hub.docker.com/_/ruby),\nsee [Building custom runtimes](/appengine/docs/flexible/custom-runtimes/build#base).\n\nDependencies\n------------\n\nThe runtime looks for a [`Gemfile`](https://bundler.io/v2.4/man/gemfile.5.html)\nfile in your application's source directory and uses\n[`Bundler`](http://bundler.io/) to install\nany dependencies before starting your application. For more information on\ndeclaring and managing packages, see [Using Ruby Libraries](/appengine/docs/flexible/ruby/specifying-dependencies).\n\n### Using C libraries with Ruby\n\nFor Ruby libraries that require C extensions, the headers for\nthe current Ruby version and the following\n[Ubuntu packages](https://packages.ubuntu.com/) are pre-installed on the system.\n\n- `autoconf`\n- `build-essential`\n- `ca-certificates`\n- `cmake`\n- `curl`\n- `file`\n- `git`\n- `imagemagick`\n- `libcurl3`\n- `libcurl3-gnutls`\n- `libcurl4-openssl-dev`\n- `libffi-dev`\n- `libgdbm-dev`\n- `libgit2-dev`\n- `libgmp-dev`\n- `libicu-dev`\n- `libjemalloc-dev`\n- `libjemalloc1`\n- `libmagickwand-dev`\n- `libmysqlclient-dev`\n- `libncurses5-dev`\n- `libpq-dev`\n- `libqdbm-dev`\n- `libreadline6-dev`\n- `libsqlite3-dev`\n- `libssl-dev`\n- `libxml2-dev`\n- `libxslt-dev`\n- `libyaml-dev`\n- `libz-dev`\n- `systemtap`\n- `tzdata`\n\nThese packages allow the installation of most popular Ruby libraries. If your application\nrequires additional operating-system level dependencies, you will need to use a\n[custom runtime](/appengine/docs/flexible/custom-runtimes) based on this runtime\nto install the appropriate packages.\n\nApplication startup\n-------------------\n\nThe runtime starts your application using the `entrypoint` defined in\n[`app.yaml`](/appengine/docs/flexible/reference/app-yaml#entrypoint). The entrypoint should start a process that\nresponds to HTTP requests on the port defined by the environment variable `PORT`.\nFor example: \n\n entrypoint: bundle exec rails server -p $PORT\n\nMost web applications use a [Rack](http://rack.github.io/)-supported web server\nsuch as [Puma](http://puma.io/), [Unicorn](http://unicorn.bogomips.org/) or\n[Thin](https://github.com/macournoyer/thin).\n\nYou must add the server as a dependency in your application's `Gemfile`\nconfiguration file. The runtime will install all dependencies before your\nentrypoint is called. \n\n source \"https://rubygems.org\"\n\n gem \"rack\"\n gem \"puma\"\n\nAn example entrypoint using puma for a Rails application: \n\n entrypoint: bundle exec rails server Puma -p $PORT\n\nAn example entrypoint using puma for any Rack application: \n\n entrypoint: bundle exec rackup -s Puma -p $PORT\n\nFor applications that can handle requests without a Rack server, you can just execute a ruby script: \n\n entrypoint: bundle exec ruby app.rb\n\n| **Note:** The entrypoint command will be executed by [bash's `exec` function](https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#Bourne-Shell-Builtins). Shell variables such as `$PORT` will be replaced normally, but shell syntax such as `if`, `for` and `while` embedded in the `entrypoint` command will not function.\n\nEnvironment variables\n---------------------\n\nThe following environment variables are set by the runtime environment:\n\nYou can set additional environment variables with [`app.yaml`](/appengine/docs/flexible/reference/app-yaml#defining_environment_variables).\n\nMetadata server\n---------------\n\nEach instance of your application can use the\n[Compute Engine metadata server](/compute/docs/storing-retrieving-metadata)\nto query information about the instance, including its hostname, external\nIP address, instance ID, custom metadata, and service account information.\nApp Engine doesn't allow you to set custom metadata for each instance, but you\ncan set [project-wide custom metadata](/compute/docs/storing-retrieving-metadata#projectwide)\nand read it from your App Engine and Compute Engine instances.\n\nThis example function uses the metadata server to get an external IP address of\nan instance. \n\n require \"sinatra\"\n require \"net/http\"\n\n get \"/\" do\n uri = URI.parse(\n \"http://metadata.google.internal/computeMetadata/v1\" +\n \"/instance/network-interfaces/0/access-configs/0/external-ip\"\n )\n\n request = Net::HTTP::Get.new uri.path\n request.add_field \"Metadata-Flavor\", \"Google\"\n\n http = Net::HTTP.new uri.host, uri.port\n\n response = http.request request\n\n \"External IP: #{response.body}\"\n end"]]