Ruby Runtime Environment

The Ruby runtime allows you to run your app in App Engine in asandbox environment. This document explains the details of the Rubyruntime environment, including what headers are provided to your code and otherinformation to successfully deploy your application on App Engine.

Specify the Ruby runtime for App Engine in the standardenvironment in theapp.yaml file:

runtime:rubyVERSION

WhereVERSION is the RubyMAJOR andMINOR version numbers. For example,to use the latest Ruby version, Ruby 3.4, specify34.

For other supported Ruby versions, and the corresponding Ubuntu version for yourRuby version, see theRuntime support schedule.

Ruby version

The latest supported Ruby version is 3.4. The Ruby runtime uses the latest stable release of the versionthat is specified in yourapp.yaml file. App Engine automaticallyupdates to new patch release versions, but it will not automatically update theminor version.

For example, your application might be deployed at Ruby 2.6.0 andautomatically updated to version 2.6.1 at a later deployment, but it will notbe automatically updated to Ruby 2.7.

Dependencies

For more information on declaring and managing dependencies, seeSpecifying dependencies.

Application startup

The runtime starts your application using theentrypoint defined inapp.yaml. The entrypoint should start a process thatresponds to HTTP requests on the port defined by the environment variablePORT.For example:

entrypoint:bundleexecrailsserver-p$PORT

Most web applications use aRack-supported web serversuch asPuma,Unicorn orThin.

You must add the server as a dependency in your application'sGemfileconfiguration file. The runtime will install all dependencies before yourentrypoint is called.

source"https://rubygems.org"gem"rack"gem"puma"

An example entrypoint using puma for a Rails application:

entrypoint:bundleexecrailsserverPuma-p$PORT

An example entrypoint using puma for any Rack application:

entrypoint:bundleexecrackup-sPuma-p$PORT

For applications that can handle requests without a Rack server, you can just execute a ruby script:

entrypoint:bundleexecrubyapp.rb
Note: The entrypoint command will be executed bybash'sexec function.Shell variables such as$PORT will be replaced normally, but shell syntax suchasif,for andwhile embedded in theentrypoint command will notfunction.

Environment variables

The following environment variables are set by the runtime:

Environment variableDescription
GAE_APPLICATIONThe ID of your App Engine application.This ID is prefixed with 'region code~'such as 'e~' for applications deployed in Europe.
GAE_DEPLOYMENT_IDThe ID of the current deployment.
GAE_ENVThe App Engine environment. Set tostandard.
GAE_INSTANCEThe ID of the instance on which your service is currently running.
GAE_MEMORY_MBThe amount of memory available to the application process, in MB.
GAE_RUNTIMEThe runtime specified in yourapp.yaml file.
GAE_SERVICEThe service name specified in yourapp.yaml file. If no service name is specified, it is set todefault.
GAE_VERSIONThe current version label of your service.
GOOGLE_CLOUD_PROJECTThe Google Cloud project ID associated with your application.
PORTThe port that receives HTTP requests.
NODE_ENV (Only available in the Node.js runtime)Set toproduction when your service is deployed.

You candefine additional environment variables in yourapp.yaml file,but the above values cannot be overridden, except forNODE_ENV.

HTTPS and forwarding proxies

App Engine terminates HTTPS connections at the load balancer andforwards requests to your application. Some applications need to determinethe original request IP and protocol. The user's IP address is available inthe standardX-Forwarded-For header. Applications that require thisinformation should configure their web framework to trust the proxy.

Filesystem

The runtime includes a writable/tmp directory, with all other directorieshaving read-only access. Writing to/tmp takes up system memory. For moreinformation, see theTempDir andTempFile documentation.

Metadata server

Each instance of your application can use the App Engine metadata serverto query information about the instance and your project.

Note: Custom metadata is not supported in the standard environment.

You can access the metadata server through the following endpoints:

  • http://metadata
  • http://metadata.google.internal

Requests sent to the metadata server must include the request headerMetadata-Flavor: Google. This header indicates that the request was sent withthe intention of retrieving metadata values.

The following table lists the endpoints where you can make HTTP requests forspecific metadata:

Metadata endpointDescription
/computeMetadata/v1/project/numeric-project-idThe project number assigned to your project.
/computeMetadata/v1/project/project-idThe project ID assigned to your project.
/computeMetadata/v1/instance/regionThe region the instance is running in.
/computeMetadata/v1/instance/service-accounts/default/aliases
/computeMetadata/v1/instance/service-accounts/default/emailThe default service account email assigned to your project.
/computeMetadata/v1/instance/service-accounts/default/Lists all the default service accounts for your project.
/computeMetadata/v1/instance/service-accounts/default/scopesLists all the supported scopes for the default service accounts.
/computeMetadata/v1/instance/service-accounts/default/tokenReturns the auth token that can be used to authenticate your application to other Google Cloud APIs.

For example, to retrieve your project ID, send a request tohttp://metadata.google.internal/computeMetadata/v1/project/project-id.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.