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
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
Step 4 : Gems
First we will install thin web server
gem install thin
Then we will install
sinatra framework. Sinatra will help us to quickly create a hello world example website.
gem install sinatra
Step 5 the server.rb
First create a directory for convenience.
Then go there,
Now create server.rb with the following content
require 'sinatra' get '/' do 'hello '*300 end
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
CTRL button in the UI and then
c to exit
This is not limited to ruby. Using termux you can do a lot more developmental activities in your android device. This is very powerful.
Top comments (0)