Table of contents
1.
Introduction 
2.
Installation and Setup process of Sinatra
2.1.
Installing Ruby
2.2.
Installing RubyGems 
2.3.
Installing Sinatra
2.4.
Additional Installation (Optional)
3.
Frequently Asked Questions
3.1.
What is Sinatra?
3.2.
How is Sinatra different from Ruby on Rails?
3.3.
What is thin?
3.4.
What is RubyGems in Ruby?
3.5.
What are the requirements for installing Sinatra?
4.
Conclusion
Last Updated: Jun 28, 2024
Easy

Getting started with Sinatra

Author Teesha Goyal
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 

Sinatra is an open-source web application framework of Ruby. It is an alternative to Ruby on Rails among the other web application frameworks based on Ruby. It is more robust and hence requires more work and time for development.

This article will demonstrate how to get started with Sinatra. We will discuss the installation steps and set up to start working with Sinatra.

getting started with Sinatra

Installation and Setup process of Sinatra

As Sinatra is written in Ruby, before installing Sinatra, you will need two more things installed. They are - Ruby and Rubygems. If you have Ruby and RubyGems installed in your system, you can skip the following two topics on installing Ruby and RubyGems.

Installing Ruby

To learn more about how to install Ruby, you can follow our other detailed articles mentioned below: 

 

Installing RubyGems 

To install RubyGems, you have to follow the below steps:

  • Visit Download RubyGems v3.3.19 and download the files needed to install RubyGems.
     
  • Unpack or unzip the downloaded file.
     
  • Move your current directory to where you have unpacked the files downloaded above.
     
  • Install with ruby setup.rb command.

 

Installing Sinatra

Now we can move ahead and install Sinatra and begin our journey of building amazing web applications with Ruby. 

Once you have installed RubyGems, there isn’t much left for you to do to install Sinatra. You just have to run a single install command, and you are done.

Sinatra

To interact with RubyGems, we will be working on the command line on Mac or the command prompt application(Windows Powershell) on Windows.

Let’s get started! 😀

Step 1: Check for the Ruby Version you are working with by running the following command:

ruby -v

ruby version

Step 2: Check on RubyGems by listing out all the gems available to use currently in your environment. Run the following command:

gem list

 

gem list

I have only shown a few of the top gems installed in my system. Currently, the list doesn’t contain Sinatra. 

Step 3: Now, just run a command to install Sinatra. 

gem install Sinatra

 

install sinatra

Voila! 🥳

You have successfully installed Sinatra and are ready to build your web applications with Ruby. To verify, you can run the gem list command and see that the list now contains Sinatra.

gem list

 

Gem list

Additional Installation (Optional)

Now that you have installed Sinatra, what you can do more is, install thin. Thin is a lightweight web server perfect for your lightweight Sinatra web framework. Sinatra has a feature that detects that thin is installed and starts using it automatically. 
So it is good if you have it installed already in your system. 

To install thin, just run the following command in your command line. 

gem install thin

 

thin install

Frequently Asked Questions

What is Sinatra?

Sinatra is an open-source web application framework of Ruby. It is an alternative to Ruby on Rails among the other web application frameworks based on Ruby. It is more robust and hence requires more work and time for development.

How is Sinatra different from Ruby on Rails?

Sinatra is more robust; you can build more customized web applications with Sinatra compared to Ruby on Rails. Hence with Sinatra, you have to work more, requiring more development time. 

What is thin?

Thin is a lightweight web server perfect for your lightweight Sinatra web framework. Sinatra has a feature that detects that thin is installed and starts using it automatically. 

What is RubyGems in Ruby?

RubyGems is a standard distribution mechanism for Ruby applications and libraries. It's a Ruby programming language package manager. Since Ruby version 1.9.c, RubyGems has been included in the standard library.

What are the requirements for installing Sinatra?

Before you can install Sinatra, you have to install Ruby and RubyGems. Sinatra is a Ruby-based web application framework and a Gem in Ruby. Hence both are necessary to install Sinatra. 

Conclusion

This article demonstrated how to get started with Sinatra. We have discussed the steps of installation and the setup process to start working with Sinatra.

I hope you would have gained a better understanding of these topics now!

Are you planning to ace the interviews of reputed product-based companies like AmazonGoogleMicrosoft, and more? 

Attempt our Online Mock Test Series on Coding Ninjas Studio now!

Thank You

Happy Coding!

Live masterclass