Now that ruby is installed, you will be able to install Rails on your server and then run your application. Except, there is still, a major piece remaining for our deployment to work.
Rails requires bundler to be installed so that when you deploy, the Gemfile in your project is automatically read and new Gems installed (if had added them, and you probably will)! To install bundler, make sure you have selected the right ruby in your terminal using
rbenv shell <version_number> and then run:
gem install bundler
A couple of times, I have encountered an error which said
can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException) and I found that the reason that was happening was because my version of bundler on server was different from the one on my development machine. To be on the safe side (or if you encounter errors later,) you can install the same version of bundler using the command
gem install bundler -v 2.0.1 and replace
2.0.1 with the version you have on your development machine.
Once the installation succeeds, you should run:
bundle help install
and that should print the installation help - and that means bundler is installed!
Install Ruby on Rails
You probably already know about it, but Rails is just another Ruby Gem. To install Rails, run the following command.
Note that we use
gem command here, not the
gem install rails
That will install the latest version of Ruby on Rails on the machine. However, that is not always desired. You might be using an earlier version of Rails. To install the specific version of Rails, run this:
gem install rails -v 5.1
That will install Ruby on Rails version 5.1
How to know which rails version you are on
Run the following command on your terminal to learn which version of rails was installed.
If you followed a tutorial from somewhere else and already have a project but your are not sure which version of Rails you are on then
cd to your project directory on Terminal and run
rails console command. The output should look similar to:
$ rails console Running via Spring preloader in process 7917 Loading development environment (Rails 5.2.1) irb(main):001:0>
Notice the line
Loading development environment (Rails 5.2.1). You have your rails version here. You can use this version number with
gem install command, like so:
gem install rails 5.2.1.