Understand shims

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-04-26

chromedriver failed to run today, and I had difficulty debugging. The central issue was that it was installed as an rbenv shim and I didn't understand how these shims worked.

1. rbenv works by inserting a directory of shims at the front of your PATH

~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin

Being at the front of the PATH, i.e. leftmost, means the shim gets run before anything else.

The code above simply means there is a folder ~/.rbenv/shims that has a bunch of commands. Usually these intercept calls to underlying commands of the same name.

For example, the folder had about 100 commands, such as foreman, rake, and chromedriver. When one such command is called, the shim figures out the correct ruby version for the directory.

2. What is present?

"Through a process called rehashing, rbenv maintains shims in that directory to match every Ruby command across every installed version of Ruby, gem, rake, rails, ruby, and so on."

So there are ruby commands from various ruby versions, some of which may have compatibility issues with the codebase I was debugging. I saw, for example, that chromedriver said it was for ruby 2.5, even though my project was ruby 2.5.3. By removing this shim (by means of wiping the no-longer-needed install of ruby 2.5), the problem was remedied.

3. General debugging

rbenv rehash may be necessary