How to run a ruby web server on your android device (without root).

haseebeqx

Haseeb Annadamban

Posted on June 20, 2022

How to run a ruby web server on your android device (without root).

Here is how you can quickly run a ruby based web server in your android device. There are many development activities you can do in your android device. This is an easy one. So, I will be quick without going into details. I expect you know basics of linux terminal.

Step 1 : Termux

Termux is a linux terminal for your android. It also includes a package manager using which you can install many packages including ruby. The first step is to download and install termux. Do not download from play store. The play store version is pretty outdated. Get it from FDroid or github

Step 2 : Packages

pkg is the package manager available in your Termux. We need to install ruby and openssl
open termux and type

pkg install ruby openssl
Enter fullscreen mode Exit fullscreen mode

It will install ruby and all required packages like clang.

Step 3 : Editor

I prefer vi editor. If you are new to vi editor, Please make sure you know the basics and especially how to exit vim 😀

pkg install vim
Enter fullscreen mode Exit fullscreen mode

Step 4 : Gems

First we will install thin web server

gem install thin
Enter fullscreen mode Exit fullscreen mode

Then we will install sinatra framework. Sinatra will help us to quickly create a hello world example website.

gem install sinatra
Enter fullscreen mode Exit fullscreen mode

Step 5 the server.rb

First create a directory for convenience.

mkdir ruby-example
Enter fullscreen mode Exit fullscreen mode

Then go there,

cd ruby-example
Enter fullscreen mode Exit fullscreen mode

Now create server.rb with the following content

vi server.rb
Enter fullscreen mode Exit fullscreen mode
require 'sinatra'

get '/' do
  'hello '*300
end
Enter fullscreen mode Exit fullscreen mode

Now exit vim using the esc key provided in the UI and then :wq - Save and exit.

Step 6 : Visit the website

in your chrome web browser go to http://localhost:4567
It. You will see 300 hellos in your browser.

Step 7 Stopping the server

Press the CTRL button in the UI and then c to exit

Now what

This is not limited to ruby. Using termux you can do a lot more developmental activities in your android device. This is very powerful.

💖 💪 🙅 🚩
haseebeqx
Haseeb Annadamban

Posted on June 20, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related