Repository: pre-commit/pre-commit

Issue:
Ruby hooks cannot be installed when `gem` is globally configured with `--user-install`
### search tried in the issue tracker

gem, ruby

### describe your issue

On Arch Linux, `gem` is configured to always use `--user-install` via a global option set in `/etc/gemrc`: https://github.com/archlinux/svntogit-packages/blob/7a52ba210a99eee8df25ad27aa5700bc1f3f10d0/trunk/gemrc

This breaks Ruby tool installations for `pre-commit`, because it makes `gem` ignore `GEM_HOME`.

In a fresh `git` repo:
```console
$ ls -A
.git  .pre-commit-config.yaml  t.rb
$ file t.rb
t.rb: empty
$ pre-commit clean
[...]
$ pre-commit run rubocop -a
[INFO] Initializing environment for https://github.com/rubocop/rubocop.
[INFO] Installing environment for https://github.com/rubocop/rubocop.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
rubocop..................................................................Failed
- hook id: rubocop
- exit code: 1

Executable `rubocop` not found

$
```

This can also be reproduced in a fresh docker container using `archlinux:latest` and installing `python-virtualenv python-pip ruby git`.

Adding `--norc` (or `--no-install-user`) to the `gem install` invocation here https://github.com/pre-commit/pre-commit/blob/cc9d950601cd3eba27e8395a7edcd455262705d9/pre_commit/languages/ruby.py#L136-L143 fixes the issue for me (though I haven’t written any tests).

### pre-commit --version

pre-commit 2.19.0

### .pre-commit-config.yaml

```yaml
repos:
  - repo: https://github.com/rubocop/rubocop
    rev: v1.29.0
    hooks:
      - id: rubocop
```


### ~/.cache/pre-commit/pre-commit.log (if present)

not present


Discussion:
this has been encountered before -- we weren't able to add `--norc` because it breaks `gem` for older users: https://github.com/pre-commit/pre-commit/issues/418#issuecomment-259008663

perhaps it can be done now?  it was included in rubygems 2.5.2 which was released 2016-01-31 -- the previous limit we had was `--no-document` for rubygems 2.0.0
`--no-user-install` was added in 1.3.0: https://github.com/rubygems/rubygems/commit/72e384eedd4c6699a764baf64e599463b5b46d0c
yeah that seems fine -- do you want to submit a patch?

Resolving patch:
diff --git a/pre_commit/languages/ruby.py b/pre_commit/languages/ruby.py
--- a/pre_commit/languages/ruby.py
+++ b/pre_commit/languages/ruby.py
@@ -138,6 +138,7 @@ def install_environment(
                 (
                     'gem', 'install',
                     '--no-document', '--no-format-executable',
+                    '--no-user-install',
                     *prefix.star('.gem'), *additional_dependencies,
                 ),
             )


Test patch:
diff --git a/tests/repository_test.py b/tests/repository_test.py
--- a/tests/repository_test.py
+++ b/tests/repository_test.py
@@ -332,6 +332,13 @@ def test_run_a_ruby_hook(tempdir_factory, store):
     )
 
 
+def test_run_a_ruby_hook_with_user_install_set(tempdir_factory, store, tmpdir):
+    gemrc = tmpdir.join('gemrc')
+    gemrc.write('gem: --user-install\n')
+    with envcontext((('GEMRC', str(gemrc)),)):
+        test_run_a_ruby_hook(tempdir_factory, store)
+
+
 @xfailif_windows  # pragma: win32 no cover
 def test_run_versioned_ruby_hook(tempdir_factory, store):
     _test_hook_repo(