Before installing Rails, you need to make sure that you have the required prerequisites installed on your system. These include:
ruby
SQLite3
Installing Ruby
Open command line applications. On macOS, open Terminal.app; on Windows select "Run" from the Start menu and write cmd.exe. Any commands that begin with a dollar sign $ must be run on the command line. Make sure you have the current version of Ruby installed:
$ ruby --version
ruby 2.7.0
Rails requires Ruby version 2.7.0 or later to be installed. It is preferable to use the latest version of Ruby. If the version number is less than this (such as 2.3.7 or 1.8.7), you will need to install a fresh copy of Ruby.
To install Ruby on Windows, you first need to install the Ruby Installer.
Additional installation methods for most operating systems can be seen