Gitpod is the only IDE that’s integrating seamlessly with Github. However, by default, they only provide the latest Ruby 2.5 and 2.6. It is good to always provide Ruby’s latest version. It’s an ideal approach. Unfortunately, the web development project is not that ideal. One of my client’s project is still requiring Ruby 2.3.6 for various reasons I can’t describe here. So, how to install Ruby 2.3.6 on Gitpod IDE?

In short, it’s not easy – at least for me. I spend about two hours playing and make it works. It’s not easy but it’s fun. Seriously.

Initialization

Add those two files into the Rails root folder:

.gitpod.yml

.gitpod.Dockerfile

Why I use Ubuntu 16.04 as the base image?

At the time I write this, the Gitpod default base image for Dockerfile (gitpod/workspace-full) is running Ubuntu 19.04. The problem is it’s no longer possible to install older rubies including 2.3.6 on this Ubuntu version. Here’s the reference on Stackoverflow.

If you insist on installing it, you will end up with such error: No binary rubies available for ubuntu/19.04/x86_64/ruby-2.3.6.

Based on my trials and errors, the latest Ubuntu version which allows me to install Ruby 2.3.6 is Ubuntu 16.04.

Let’s continue

Once you have those YML and Dockerfile in place, then commit and push it to the Github. After that, you can fire up the Gitpod IDE from there.

Install RVM

This is my favorite way to install ruby version. Here’s how I install RVM on Gitpod IDE:

Run:

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Wait until it finished.

Then, run:

curl -sSL https://get.rvm.io | bash

If everything goes smoothly, you’ll see something similar to this:

Before you install Ruby 2.3.6 on Gitpod, read this

Normally, you’ll continue with “rvm install 2.3.6”. But if you continue with that, you’ll see an error about permission denied. This because Gitpod IDE didn’t allow you to run any command with sudo. They said it’s for security reasons.

Why RVM is asking for sudo? Because RVM has a feature called autolibs. It will automatically install dependencies on your system. This is why it’s asking for sudo permission.

Instead of letting autolibs to automatically install any packages required, it will be helpful, in this case, to see the required packages instead of installing them. We can do it by running this command: rvm autolibs read-fail

After that, you’ll be able to run rvm install 2.3.6 without any errors. If there are any missing dependency packages, it will stop and tell you gracefully.

Add missing dependencies for RVM

To fix it, you’ll need to update the Dockerfile with these missing packages. Commit and push the change to Github (I did it directly on Github, honestly), then re-launch the Gitpod again. Sounds a bit complicated? Yes, but it’s just for the starters.

Once all of the missing dependencies are on the Dockerfile, you’ll never have to do this again. Ever. Then, your fellow developers in the future and your future self will say thank you, because all they have to do to get the Rails apps to get up and running is just firing up the Gitpod.

Why Gitpod? It sounds too complicated

Not really. Especially if you’re already familiar with how Docker works. It is even better if you know or have the list of all required packages/dependencies for your Rails project.

Setting up the .gitpod.Dockerfile once, and re-use it forever. If you need to install new packages, just add it to the Dockerfile and re-launch the Gitpod. It’s simple.

Conclusions

In short, to install Ruby 2.3.6 on Gitpod:

Put up all required packages on .gitpod.Dockerfile, commit and push it to Github

Fire up the Gitpod from Github.

Open the terminal inside Gitpod

Install rvm

Set up rvm autolibs as explained above

Install Ruby 2.3.6: rvm install 2.3.6

Key takeaways

Gitpod restricted the usage of sudo for security reasons.

But you’ll be able to run sudo on Dockerfile.

Installing old rubies won’t work with the default Gitpod base image for Docker. You need older Ubuntu as the base image.

More updates

After making some changes here and there, here’s the Dockerfile I come up. It’s better because there is no need to install RVM manually as I explained above.