Changing the install directory of RubyGems on Windows

622 Views Asked by At

For some reason, RubyGems keeps installing gems in the directory of the old Scoop Ruby installation that I've wiped. Can I change the directory? I'm trying to find all my options before going straight to WSL. Thank you.

1

There are 1 best solutions below

0
On

The location of installed gems is determined by two things:

  1. What is compiled into the Ruby executable.
    On gem env this is INSTALLATION DIRECTORY, unless... (see below).

  2. The GEM_HOME environment variable which will override the default INSTALLATION DIRECTORY.

So, if you want to change INSTALLATION DIRECTORY, then you have two choices for a fix:

  1. Install another Ruby version which will have a different default INSTALLATION DIRECTORY (determined at compile time).
  2. Set the GEM_HOME environment variable to any location that you prefer.

A related env variable is GEM_PATH, which will list all locations where Ruby will look for gems. The lookup folders will be listed in gem env under GEM PATHS, and can be altered by yourself by setting the GEM_PATH env variable on your machine.

This way the combination of INSTALLATION DIRECTORY, GEM_HOME and GEM_PATH, determines how Ruby installs and where it finds its gems.