DEV Community

loading...
Cover image for Upgrade to Ruby 3 - update projects 🔩

Upgrade to Ruby 3 - update projects 🔩

Michael
I'm a self-taught dev focused on websites and Python development. My friends call me the "Data Genie". When I get bored, I find tech to read about, write about and build things with.
・2 min read

Now, you should have Ruby 3 ready.

Your Ruby projects will have stale gems and lockfiles though, so you need to make changes to them.

I'm going to walk you through how to update your projects to get them using Ruby 3. This will be similar across projects but I will focus on Jekyll projects. I like to build websites using Jekyll as a static site generator. I have a demo here if you are interest - including an update to the Gemfile to support Ruby 3.

Repeat the steps below for each Ruby project of yours.

Remove old gems 🙅‍♂️ 💎

$ rm -rf vendor
Enter fullscreen mode Exit fullscreen mode

This is not strictly necessary, as 2.7 and 3.0 gems are kept in separate directories in the vendor directory. But if you are never going to use those old gems again, then you can reclaim some space now.

Remove lockfile 🙅‍♂️ 🗃

$ rm Gemfile.lock
Enter fullscreen mode Exit fullscreen mode

I found that that I got errors running Jekyll, unless I dropped the old lockfile and started over with a fresh set of the latest gems.

Install gems

$ bundle install
Enter fullscreen mode Exit fullscreen mode

Then commit your lockfile.

Install missing gems 🚛 📦

For Jekyll in Ruby 3, you'll get this error on serving.

Load error: cannot load such file – webrick
Enter fullscreen mode Exit fullscreen mode

Fix that by installing Webrick, as per Jekyll issue #8523. Perhaps this will be fixed in newer releases of Jekyll.

Run this to add the gem to your Gemfile and install it.

$ bundle add webrick
Enter fullscreen mode Exit fullscreen mode

Commit your lockfile.

Start Jekyll

Your Jekyll site should be ready to use now.

$ bundle exec jekyll serve --trace
Enter fullscreen mode Exit fullscreen mode

Thanks for reading. I hope that eases your journey to using Ruby 3.

Credits 📸

Cover image created with Google Jamboard.

Photo by Joshua Fuller on Unsplash

Discussion (1)

Collapse
jla profile image
Librebits

Sure... ThX again for sharing Michael.