So I woke up with a plan: Build an Application with React. Yes, it was finally time to learn React. Three years of building with Javascript and some of its libraries like Node Js, Vue, and Angular but never attempted React. I don't know the reason for my resistance to this now-discovered easy-to-use Library but I was finally going to build something with React and I was excited and curious to find out what it brings.
I searched Google for Applications I could build with React and saw an article Creating a Simple App with React.js by Emi Katsutka
I decided to follow the article through. Although I had previously read the documentation on React.com, I read it again, this time more seriously than before. Then, followed the steps required to install React. I found Emi’s article quite interesting until it was time to set up the backend with the Rails API.
I would have to install Ruby on Rails, a server-side web application framework written in Ruby. I have never used Ruby before and I thought it would be fun.
She had the Ruby On Rails documentation attached to the article. I read through the documentation and I tried to follow the guide to install the Rails framework on my MacBook Terminal. I verified that I had a version of Ruby on my MacBook as recommended in the documentation.
On the terminal
ruby -v
An important lesson I learned is to always read the full documentation of a product. Not just read but read to understand.
I am a reader but I can be an annoying reader sometimes. I skimmed through the documentation and skipped the required version of Ruby (2.7.0 or a later version) to install Rails. I had Ruby version 1.8.7 and went ahead to try the command for installing Rails gem install rails
and that was where my travails started.
As always, Stack overflow to the rescue.
In seconds I pasted the exact error I was getting into the stack search bar.
Error installing rails: there are no versions of activesupport (= 7.0.4) compatible with your ruby & rubygems. maybe try installing an older version of the gem you're looking for? activesupport requires ruby version >= 2.7.0. the current ruby version is 2.6.8.205.”
I could have gone back to check out the documentation for the latest version or if this error was predicted to be expected but I didn't. Please don't be like me 🥲.
Anyways, I got a solution in minutes from Stack. This user beautifully explained how to set up a ruby environment, install a separate version of Ruby and ability to switch between different versions by installing ruby-install with Homebrew.
brew install ruby-install
then
ruby-install ruby
After a successful installation, for some weird reasons, I kept getting the version of the previously installed ruby contrary to the latest version of ruby which the user promised I should get.
Then I came across another solution installing a rails version compatible with your ruby. The rule is simply you can't use any ruby version with the latest version of rails.
When you type the command "gem install rails", you will be getting the latest rails version which may not be compatible with your ruby version as in my case.
However, to install a compatible version of rails, you would need to specify the version gem install rails -v [specific version]
or gem install rails —version=[specific version]
You can find a comprehensive list of ruby and rails version compatibility here
I found mine which was rails 6.0.6. However, I got an error again.
This time it was a permission error.
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
Then I set out again to stack overflow, I saw different suggested solutions through the github.com/rbenv repository. I chose chanux’s issue on exporting a GEM_HOME, typing the command export GEM_HOME=“$HOME/.gem
on the terminal, that is, setting GEM_HOME to your user directory and it disabled the permission error.
So let me explain this error so you get more clarification. RubyGems is a package manager for the Ruby language that provides a standard format for distributing Ruby programs and libraries. Although you can specify the location to install your gems, the default path is $GEM_HOME for development and vendor/bundle when --deployment is used.
After endless back and forth trying to install my ruby gems in the HOME directory instead of the system-wide directory (/Library/Ruby/Gems/2.6.0) I found chanux's solution which worked.
However, I could also have used the command gem install --user-install gem_name
then add the /home/path/to/gems/bin to PATH, if it does not already exists. Mine was export PATH=$PATH:/home/username/.gem/ruby/2.6.0/bin
You can check Ruby Gems FAQs for further guidance.
Anyways, I tried installing the rails version compatible with my ruby again and Boy-Oh-Boy, and it worked. IT FINALLY WORKED!
I had my Rails installed.
I checked my rails version to be sure and I got my Rails 6.0.6 version looking right at me.
I closed my MacBook and offered a silent prayer. I could have done things differently. Most Importantly, I could have read through the Ruby documentation.
You never realize the bug you are hoping to solve is in the documentation you run away from. 90% of the time the solution is in the documentation so that was the primary lesson I took away from my over 4 hours of trying to install my Ruby on Rails.
I sure had a ruby time installing this framework. You can check out the Ruby Version Manager (RVM) for easy installation and management of different ruby environments.
Ever used the Ruby and Rails framework, tell me how your experience was installing this beautiful framework.