Skip to content

The Ruby runtime is available in Beta on all plans

The Ruby Runtime is used by Vercel to compile Ruby Serverless Functions that define a singular HTTP handler from .rb files within an /api directory at your project's root.

Ruby files must have one of the following variables defined:

  • Handler proc that matches the do |req, res| signature.
  • Handler class that inherits from the WEBrick::HTTPServlet::AbstractServlet class.

For example, define a index.rb file inside a /api directory as follows:

api/index.rb
require 'cowsay'

Handler = Proc.new do |req, res|
  name = req.query['name'] || 'World'

  res.status = 200
  res['Content-Type'] = 'text/text; charset=utf-8'
  res.body = Cowsay.say("Hello #{name}", 'cow')
end

An example index.rb file inside an /api directory.

Inside a Gemfile define:

Gemfile
source "https://rubygems.org"

gem "cowsay", "~> 0.3.0"

An example Gemfile file that defines cowsay as a dependency.

New deployments use Ruby 2.7.x as the default version.

You can specify the version of Ruby by defining ruby in a Gemfile, like so:

Gemfile
source "https://rubygems.org"
ruby "~> 2.7.x"

When defining a Ruby version, the following Ruby versions can be selected:

  • 2.7.x (default)
  • 2.5.x (disabled since November 30th 2021)
Note: If the patch part of the version is defined, like 2.7.1 it will be ignored and assume the latest 2.7.x.

This Runtime supports installing dependencies defined in the Gemfile. Alternatively, dependencies can be vendored with the bundler install --deployment command (useful for gems that require native extensions). In this case, dependencies are not built on deployment.