A Simple Example: Hello World!

You can subscribe and publish a message like so:
 require 'pubnub'
 pubnub =
   :publish_key   => 'demo',
   :subscribe_key => 'demo'
    :channel  => 'demo'
 ) { |envelope| puts("\nchannel: #{}: \nmsg: #{envelope.message}")}
   :channel  => 'demo',
   :message => 'Hello PubNub, love the Ruby SDK!',
 ) { |data| puts data.response }
More Fun Awaits:

Look at the Quick Start.
Try out a Tutorial.
Find out more about PubNub Features.

Where do I get the code?

The simplest way to get started is to install PubNub Ruby SDK as a gem:

 gem install pubnub


Or you can git clone the Ruby SDK repository with the following command:

git clone

How do I get started?

The Ruby SDK has the following dependencies:

  • ruby >= 1.9.3

  • activesupport >= 0

  • em-http-request >= 0

  • httparty

  • json >= 0

  • persistent_httparty

  • uuid ~> 2.3.5

Upgrading from PubNub 3.3.x and Earlier

PubNub 3.5.0 is NOT compatible with earlier than 3.4 versions of Pubnub Ruby Client.

Upgrading from PubNub 3.4

PubNub 3.5.0 is compatible with 3.4 version

Can I see a demo?

We offer the following to help you get started building applications with Ruby SDK:

Table 1. Ruby SDK demos.
Demo Description

Do you enjoy seeking out the possibilites? This demo console app shows how to use just about every PubNub Ruby call, in just about every possible way!

Time for a chat? This is a chat room demo with real-time translation! This is using PubNub for the real-time chat, and Bing translation services for babel.

Its a demo on Rails. It has also been tested with Heroku.

Do can do it your way with this Sinatra demo.

To Pub or Sub? That is the question. This demo mixes up some async pubs and subs, using blocks and callbacks.

Are you a serial publisher? This demo is definitely for you; you’ll publish 10000 times with an explicit 0.05s delay between publishes.