This tutorial aims to guide you through the process of setting up a Ruby on Rails (RoR) development environment. Ruby on Rails is a popular web development framework that uses the Ruby programming language. By the end of this tutorial, you will have installed Ruby, Rails, and other necessary tools on your system. You will also learn how to configure them for optimal development.
You will learn:
Prerequisites:
Ruby can be installed using a version management tool like rbenv
or rvm
. For simplicity, we will use rbenv
.
rbenv
and ruby-build
On macOS, you can use Homebrew:
brew install rbenv ruby-build
On Ubuntu, you can use apt:
sudo apt-get install rbenv ruby-build
rbenv
to bash so that it loads every time you open a Terminalecho 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
rbenv install 2.7.2
rbenv global 2.7.2
ruby -v
After installing Ruby, you can install Rails.
gem install rails -v 6.1.0
rails -v
Let's create a new Rails application.
rails new my_app
This will create a new Rails application called my_app
. You can replace my_app
with the name of your choice.
Then, navigate into your new application's directory:
cd my_app
Start the Rails server:
rails server
You should see output indicating the server is running. You can visit http://localhost:3000
in your web browser to view your application.
In this tutorial, you've installed Ruby and Rails, set up a simple Rails application, and got it running on your local server.
Next steps for learning:
Additional resources:
Solution: Replace my_app
in rails new my_app
with your desired application name.
Start the Rails server for your new application.
Solution: Navigate to your application's directory with cd your_app_name
, then start the server with rails server
.
Visit your application in the web browser.
http://localhost:3000
in your web browser. You should see a default Rails page.Keep practicing by reading and writing more Ruby code, and building Rails applications. The more you practice, the more comfortable you'll become!