title: Fix openssl@3 error when installing Ruby with RVM on macOS Monterey
body: <p>Tried multiple solutions:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/15185661/update-openssl-on-os-x-with-homebrew">SO</a></li>
  <li><a href="https://github.com/rvm/rvm/issues/4484" rel="nofollow noreferrer">RVM</a> GitHub (also <a href="https://github.com/rvm/rvm/issues/4484#issuecomment-484393897" rel="nofollow noreferrer">participated</a> in the discussions)</li>
  </ul>
  <p>Actually, fail to install another Ruby version (3.1.0 is installed without issues) on Apple M1 chip macOS Monterey.</p>
  <p>So here are installed versions details:</p>
  <pre><code>➜  ~ which openssl
  /opt/homebrew/opt/openssl@3/bin/openssl
  ➜  ~ openssl version -a
  OpenSSL 3.0.1 14 Dec 2021 (Library: OpenSSL 3.0.1 14 Dec 2021)
  built on: Tue Dec 14 16:16:25 2021 UTC
  platform: darwin64-arm64-cc
  options:  bn(64,64)
  compiler: clang -fPIC -arch arm64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -D_REENTRANT -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
  OPENSSLDIR: &quot;/opt/homebrew/etc/openssl@3&quot;
  ENGINESDIR: &quot;/opt/homebrew/Cellar/openssl@3/3.0.1/lib/engines-3&quot;
  MODULESDIR: &quot;/opt/homebrew/Cellar/openssl@3/3.0.1/lib/ossl-modules&quot;
  Seeding source: os-specific
  CPUINFO: OPENSSL_armcap=0x7f
  </code></pre>
  <p>Here are the lines added to the <code>.zshrc</code> file following the <code>openssl</code> setup:</p>
  <pre><code>export PATH=&quot;/opt/homebrew/opt/openssl@3/bin:$PATH&quot;
  export LDFLAGS=&quot;-L/opt/homebrew/opt/openssl@3/lib&quot;
  export CPPFLAGS=&quot;-I/opt/homebrew/opt/openssl@3/include&quot;
  export PKG_CONFIG_PATH=&quot;/opt/homebrew/opt/openssl@3/lib/pkgconfig&quot;
  
  # Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
  export PATH=&quot;$PATH:$HOME/.rvm/bin&quot;
  </code></pre>
  <p>Used RVM version:</p>
  <pre><code>➜  ~ rvm -v
  rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
  </code></pre>
  <p>When installing a Ruby version (no matter, 3.0.0 or lower, for example, 2.6.5), it raises the error:</p>
  <pre><code>➜  ~ rvm install 2.6.5 --with-openssl-dir=`brew --prefix openssl`
  ruby-2.6.5 - #removing src/ruby-2.6.5 - please wait
  Checking requirements for osx.
  Certificates bundle '/opt/homebrew/etc/openssl@1.1/cert.pem' is already up to date.
  Requirements installation successful.
  Installing Ruby from source to: /Users/serguei/.rvm/rubies/ruby-2.6.5, this may take a while depending on your cpu(s)...
  ruby-2.6.5 - #downloading ruby-2.6.5, this may take a while depending on your connection...
  ruby-2.6.5 - #extracting ruby-2.6.5 to /Users/serguei/.rvm/src/ruby-2.6.5 - please wait
  ruby-2.6.5 - #configuring - please wait
  ruby-2.6.5 - #post-configuration - please wait
  ruby-2.6.5 - #compiling - please wait
  Error running '__rvm_make -j8',
  please read /Users/serguei/.rvm/log/1647291878_ruby-2.6.5/make.log
  
  There has been an error while running make. Halting the installation.
  </code></pre>
  <p>Here is the content of the created log file:</p>
  <pre><code>+__rvm_make:0&gt; make -j8
      BASERUBY = /Users/serguei/.rvm/rubies/ruby-3.1.0/bin/ruby --disable=gems
      CC = gcc
      LD = ld
      LDSHARED = gcc -dynamiclib
      CFLAGS = -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens   -fno-common -pipe 
      XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -DCANONICALIZATION_FOR_MATHN
      CPPFLAGS = -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/openssl@1.1/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -I. -I.ext/include/-darwin21 -I./include -I. -I./enc/unicode/12.1.0 
      DLDFLAGS = -L/opt/homebrew/opt/openssl@3/lib -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/libksba/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/openssl@1.1/lib -install_name /Users/serguei/.rvm/rubies/ruby-2.6.5/lib/libruby.2.6.dylib -compatibility_version 2.6 -current_version 2.6.5  -fstack-protector-strong -framework Security -framework Foundation  -fstack-protector-strong -framework Security -framework Foundation  
      SOLIBS = -lpthread -ldl -lobjc
      LANG = 
      LC_ALL = 
      LC_CTYPE = UTF-8
  Apple clang version 13.1.6 (clang-1316.0.21.2)
  Target: arm64-apple-darwin21.4.0
  Thread model: posix
  InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  ...
  ast.c:132:19: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]
      rb_funcall(f, rb_intern(&quot;set_encoding&quot;), 2, rb_enc_from_encoding(enc), rb_str_new_cstr(&quot;-&quot;));
  ...
  2 warnings generated.
  linking shared-object cgi/escape.bundle
  6 warnings generated.
  linking shared-object psych.bundle
  4 warnings generated.
  linking shared-object zlib.bundle
  422 warnings generated.
  linking shared-object date_core.bundle
  make: *** [build-ext] Error 2
  +__rvm_make:0&gt; return 2
  </code></pre>
  <p>The only successfully installed version is <code>3.1.0</code>:</p>
  <pre><code>➜  ~ rvm list
  =* ruby-3.1.0 [ arm64 ]
  
  # =&gt; - current
  # =* - current &amp;&amp; default
  #  * - default
  </code></pre>
  <p>Any idea ?</p>