拒绝 link macOS 提供的软件:libiconv

Refusing to link macOS-provided software: libiconv

为了按照步骤 posted here 让 nokogiri 工作,我似乎无法 link iconv 正确。

当我运行命令

brew link libiconv

我收到以下错误:

Warning: Refusing to link macOS-provided software: libiconv
If you need to have libiconv first in your PATH run:
  echo 'export PATH="/usr/local/opt/libiconv/bin:$PATH"' >> ~/.bash_profile

For compilers to find libiconv you may need to set:
  export LDFLAGS="-L/usr/local/opt/libiconv/lib"
  export CPPFLAGS="-I/usr/local/opt/libiconv/include"

我已将上述路径添加到我的 bash 配置文件中,重新加载终端,重新启动终端,甚至尝试重新启动计算机,但错误仍然存​​在。我也试过重新安装 libiconv 但无济于事(见下面的输出)。

$ brew reinstall libiconv 
==> Reinstalling libiconv 
==> Downloading https://homebrew.bintray.com/bottles/libiconv-1.16.mojave.bottle.tar.gz
Already downloaded: /Users/sam/Library/Caches/Homebrew/downloads/203933f4d9f3c2f0463012d85013a6c01bdb89fc4d435341315b4537de1dba78--libiconv-1.16.mojave.bottle.tar.gz
==> Pouring libiconv-1.16.mojave.bottle.tar.gz
==> Caveats
libiconv is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have libiconv first in your PATH run:
  echo 'export PATH="/usr/local/opt/libiconv/bin:$PATH"' >> ~/.bash_profile

For compilers to find libiconv you may need to set:
  export LDFLAGS="-L/usr/local/opt/libiconv/lib"
  export CPPFLAGS="-I/usr/local/opt/libiconv/include"

==> Summary
  /usr/local/Cellar/libiconv/1.16: 30 files, 2.4MB

libiconvkeg-only.

❯ brew info libiconv
libiconv: stable 1.16 (bottled) [keg-only]
Conversion library
https://www.gnu.org/software/libiconv/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/libiconv.rb
==> Caveats
libiconv is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

在你给的post link中,不需要linking libiconv。因为只使用了真正的安装位置,而不是 linked 的位置。只需跳过此 link 步骤和 运行 以下命令,

# use the real installation location is not preferred, cause it will
# break you once the libiconv is upgraded to a new version
gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.16

# you'd better pass the dir "/usr/local/opt/libiconv", 
# which serves as a link to the real installation location.
gem install nokogiri -- --with-iconv-dir=/usr/local/opt/libiconv