Ruby gem安装失败,因为它找不到Homebrew安装的openssl。

huangapple go评论71阅读模式
英文:

Ruby gem install fails because it can't find openssl installed by Homebrew

问题

尝试安装依赖openssl的Ruby gem时,出现以下错误之一:

```text
fatal error: 'openssl/sha.h' 文件未找到
#include <openssl/sha.h>

如果我已经通过Homebrew安装了openssl,路径分别为 /opt/homebrew/Cellar/openssl@1.1/opt/homebrew/Cellar/openssl@3,应该如何正确安装它呢?


<details>
<summary>英文:</summary>

When I try to install a Ruby gem that depends on openssl, I&#39;m getting (among other log lines):

```text
fatal error: &#39;openssl/sha.h&#39; file not found
#include &lt;openssl/sha.h&gt;

What is the right way to install it, if I have openssl installed via Homebrew at /opt/homebrew/Cellar/openssl@1.1 and at /opt/homebrew/Cellar/openssl@3.

答案1

得分: 1

这是它的工作方式:

$ gem install eventmachine -- --with-openssl-dir=/opt/homebrew/Cellar/openssl@1.1/1.1.1u/

目录/opt/homebrew/Cellar/openssl@1.1/1.1.1u/是Homebrew安装OpenSSL 1.1的位置。也适用于/opt/homebrew/Cellar/openssl@3/3.1.0/

一个标准的方法,据我了解,如下:

$ rvm pkg install openssl
$ rvm reinstall ruby-3.2.1 --with-openssl-dir=$HOME/.rvm/usr
$ gem install eventmachine

如果希望让Ruby使用Homebrew安装的openssl:

$ brew install openssl@1.1
$ rvm reinstall ruby-3.2.1 --with-openssl-dir=/opt/homebrew/Cellar/openssl@1.1/1.1.1u
$ gem install eventmachine

我不得不将这个放入~/.profile(在运行rvm reinstall之前!):

export CPPFLAGS="{$CPPFLAGS} -I/opt/homebrew/Cellar/openssl@1.1/1.1.1u/include"
英文:

This is how it worked:

$ gem install eventmachine -- --with-openssl-dir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1u/

The directory /opt/homebrew/Cellar/openssl@1.1/1.1.1u/ is where Homebrew installed OpenSSL 1.1. Also works with /opt/homebrew/Cellar/openssl@3/3.1.0/.

A canonical method, as I understand, is the following:

$ rvm pkg install openssl
$ rvm reinstall ruby-3.2.1 --with-openssl-dir=$HOME/.rvm/usr
$ gem install eventmachine

If it's desired to make Ruby use openssl installed by Homebrew:

$ brew install openssl@1.1
$ rvm reinstall ruby-3.2.1 --with-openssl-dir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1u
$ gem install eventmachine

I had to put this into ~/.profile (before running rvm reinstall!):

export CPPFLAGS=&quot;${CPPFLAGS} -I/opt/homebrew/Cellar/openssl@1.1/1.1.1u/include&quot;

huangapple
  • 本文由 发表于 2023年6月26日 05:31:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76552492.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定