A shim is a small library that intercepts and changes calls to another library, mainly to aid compatibility.
Maintaining multiple versions of a library is necessary to support your clients. Shim libraries translate old to new library calls before forwarding on to the new library.
Linux installations normally come with a single Ruby version. Ruby developers need to have different Ruby versions on their many active projects. Rbenv uses shims to solve this problem.
Running a Ruby command in Linux means checking for the executable in the path — which it searches from left to right. So, running the Ruby command
rails servermeans Linux finds and runs Rails, a Ruby executable, in the first directory.
Rbenv adds a
shims directory and loads it with shim scripts before prepending the Path. There is a shim script for every Ruby application and running a Ruby application now means running the matching shim script. So, running rails means executing the Rails script in the
shims directory and not the Rails application in
usr/local/bin. The script works out the required Ruby version and then runs its matching application, in this case Rails, under that expected Ruby version.
Microsoft uses shims to fake an application’s Windows calls. When an application makes a system call it goes through the ‘Import Address Table’.
You can change the table and replace the Windows call with a call to a shim. The shim in the example is a ’version-lie’ shim. The application thinks it’s on a Windows 7 machine.