Rails is a web development framework written in Ruby programming language. It allows you to write less code but Rails is more of an opinionated language, so use it to accomplish whatever task you are trying to build. Rails believe in the principle of DRY, that is do not repeat yourself by all means
Installing Rails
Before installing Rails, you need to meet some prerequisites first, that is, have Ruby, nodejs, and Sqlite3 installed first before running Rails.
Most of the Linux-based OSes come preinstalled with Sqlite3, so we don’t need to install it. Check the version you have with your system.
sqlite3 --version
3.39.4 2022-09-29 15:55:41 a29f9949895322123f7c38fbe94c649a9d6e6c9cd0c3b41c96d694552f26alt1
Check Ruby version also
ruby -v
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
#gem
gem -v
3.3.25
Now we can go ahead and install Rails
gem install rails
You will be in a position to see the following as an output
Fetching concurrent-ruby-1.1.10.gem
Fetching tzinfo-2.0.5.gem
Fetching i18n-1.12.0.gem
Fetching zeitwerk-2.6.6.gem
Fetching thor-1.2.1.gem
Fetching method_source-1.0.0.gem
Fetching activesupport-7.0.4.gem
Fetching nokogiri-1.13.9-x86_64-linux.gem
Fetching crass-1.0.6.gem
Fetching loofah-2.19.0.gem
Fetching rails-html-sanitizer-1.4.3.gem
Fetching rails-dom-testing-2.0.3.gem
Fetching rack-2.2.4.gem
Fetching rack-test-2.0.2.gem
Fetching erubi-1.11.0.gem
Fetching builder-3.2.4.gem
Fetching actionview-7.0.4.gem
Fetching actionpack-7.0.4.gem
Fetching railties-7.0.4.gem
Fetching mini_mime-1.1.2.gem
.....
If you happen to get the following error,
WARNING: You don't have /home/sang-pc/.local/share/gem/ruby/3.0.0/bin in your PATH,
gem executables will not run.
Successfully installed rails-7.0.4
Parsing documentation for rails-7.0.4
Done installing documentation for rails after 0 seconds
1 gem installed
Do the following on your terminal:
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$PATH:$GEM_HOME/bin"
gem list
gem update
Go back and install rails again gem install rails
. This round you will get a success message.
Successfully installed rails-7.0.4
Parsing documentation for rails-7.0.4
Done installing documentation for rails after 0 seconds
1 gem installed
If you check the rails version this time round you will be in a position to see the version without any error.
rails --version
Rails 7.0.4
Congratulations, you have successfully installed rails 7. Next, we will tackle how to scaffold your first application in rails