OMG, I never would have thought that deploying a Ruby on Rails app would have been so incredibly difficult! Building the app and testing it on my laptop was very different than the deployment! Unlike other languages I’ve played with, Ruby was very version-specific. It is controlled using the .ruby-version
and Gemfile
in the main rails directory.
Windows Laptop Installation
Installing it on my Windows laptop was mostly straightforward. Kind of. Download the version that you want to use and run the install:
https://rubyinstaller.org/downloads/
The download will likely show a Command Prompt asking for you to choose between three options. I chose option #3. Press ‘3’. Wait. Once it shows the same list, simply press the enter key, and it is happy. Maybe. At this time, newer versions (3.2 and 3.3) were easy. Older versions (I had to deploy 3.1.4) ran into issues…
Alma Linux Installation
Linux installation was more complicated. As in, there were multiple times when I wanted to throw my laptop out the window onto the street, and then drive over it 5 times to ensure that it was obliterated.
Cleanup RVM
My Linux server is Alma Linux. On Linux, Ruby is best managed by the “Ruby Version Manager” (RVM). The first thing that I did was figure out which versions were on the system:
rvm -list
And then I removed the really old ones:
rvm remove ruby-2.5
There is a bunch of older information on how to use RVM online. I stumbled upon this older nomenclature repeatedly.
NOTE: There has been some confusion amongst new users as to the proper way to switch between Ruby versions. It is not required to include the ‘ruby-‘ portion of whatever is listed in the output of rvm list for installed rubies. This is just used to indicate the differences between, say, REE rubies, MRI rubies, etc. However, do note that when you are switching between an MRI, Rubinus, or REE, as an example, then you need to use the ree|ruby|rbx part. When you want to switch, just use the version number and any patch level. If it’s a -head version use the full string as it will not contain numbers. This also applies when setting a default Ruby.
Public Service Announcement
Here is where I went around in so many circles that… I think that the rest of my young hair is 100% grey. Ruby installation uses a library for YAML parsing. If its not already there, it tries to build the Psych model. This build has some kind of failure resulting in all ruby and gem installation “failures”. Sure, portions work, but it is not all happy, and ultimately, rails will not run. There were multiple suggestions online about running:
dnf install libyaml
dnf install libyaml-devel
yum install libyaml
yum install libyaml-devel
Gem install psych -v 4.0.6
Or adding to the Gem File:
gem "psych", "~> 4"
None of those actually made the errors that would show up in the next 3 steps ever go away. The ruby gem had to be installed at the yum level:
yum install rubygem-psych
Once that was done, it was a smooth installation.
RVM Ruby Installation
Actual ruby version installation:
rvm install 3.3.0
Just because it is installed does not mean that it will always be used. To ensure that version 3.3 is the globally always used version:
rvm --default use 3.3.0
Note: (more gray hairs here also): However, the version used on your development laptop and your Linux server must be identical. Furthermore, to integrate into the Apache Web server, you’ll need to use one of the few ruby versions supported by the Phusion Passenger version!
Final Rails Installation
The way that the rails gem is installed is identical for both Windows and Linux. During the Ruby installation, a Ruby Gem manager came with it. These are the final commands to get those set up:
bundle install [Command Prompt Run as Administrator]
gem install rails
Apache Web Server Settings
The Linux server will need extra settings. I wound up using Phusion Passenger. This became another frustrating moment: Phusion Passenger only supports a small limited amount of Ruby Versions! This became my final reason to go through the uphill battle of getting Ruby 3.3.0 installed on the Linux Server. Installing Passenger onto the server was (relatively) painless:
curl --fail -sSLo /etc/yum.repos.d/passenger.repo https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo
yum install -y passenger || sudo yum-config-manager --enable cr && sudo yum install -y passenger
passenger-config validate-install
gem install passenger
The last command was an interesting one. It actually took care of all the dependencies that Passenger would need. My eventual goal is to have Ruby AND Python AND Node.JS all running on the server, all in their own document roots of course.
passenger-install-apache2-module
Then I ran into the next issue: final integration into Apache. The thing is every single website I looked at made it seem really easy. All I needed to put into the httpd.conf should be:
LoadModule passenger_module /usr/local/rvm/gems/ruby-3.3.0/gems/passenger-6.0.20/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-3.3.0/gems/passenger-6.0.20
PassengerDefaultRuby /usr/local/rvm/gems/ruby-3.3.0/wrappers/ruby
</IfModule>
<VirtualHost *:80>
ServerName ruby-app.bornino.net
DocumentRoot /home/brian/ruby-app
<Directory /home/brian/ruby-app>
Allow from all
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
# Options -MultiViews
# Uncomment this if you're on Apache > 2.4:
Require all granted
</Directory>
</VirtualHost>
and then simply restart Apache…
systemctl restart httpd.service
Yeah. I wish it were that simple. I spent at least 4 hours trying to figure out why those hosts never came up in the browser. I kept getting the ‘This site can’t be reached. Check if there is a typo in ruby-app.bornino.net.’ response on the browser. Forget about any ruby code: I tried just a basic “Hello World” index.html file and never got anything to pull up.
Final Thoughts
My head hurts. At this time, I spent more time trying to deploy my small app than actually developing the app itself! I have a newfound appreciation for all System Administrators who have been able to overcome these crazy issues that I’ve faced. I have left the links to the GitHub repositories for that app and the others that I developed on their respective pages.