<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>w11th (老晖)</title>
    <link>https://ruby-china.org/w11th</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>更新 High Sierra 后遇到的几个坑</title>
      <description>&lt;p&gt;前段时间一个没忍住，把唯一的主力机更新了 High Sierra。更新完后一切正常，没有闪退，非有异常，APFS 还速度飞快，感觉非常良好。&lt;/p&gt;

&lt;p&gt;可是好日子没过两天，就碰到了一地鸡毛。昨天想新建一个 Ruby 2.3.3、Rails 5.0 的工程，先是 Ruby 编译不过，后来又是 nokogiri 和 mysql2，全部安装完了启动 Rails，以为松了一口气，结果监控文件改动的一直报错。本来想搞事情的，结果时间都浪费在前戏了。&lt;/p&gt;

&lt;p&gt;现在把这几个坑覆盘一下。说不定能有点用处，帮大家节省一点时间。&lt;/p&gt;
&lt;h4 id="1.  Ruby 编译不通过，提示 The Ruby openssl extension was not compiled."&gt;1.  Ruby 编译不通过，提示 &lt;code&gt;The Ruby openssl extension was not compiled.&lt;/code&gt;
&lt;/h4&gt;
&lt;p&gt;这次更新，High Sierra 把 SSL 库从 OpenSSL 0.9.8zh 切换到 LibreSSL。而且通过 homebrew 安装的 OpenSSL 也是 keg-only 的，并且禁止通过 &lt;code&gt;brew link openssl&lt;/code&gt; 添加软链接了（&lt;a href="https://stackoverflow.com/questions/38670295/homebrew-refusing-to-link-openssl" rel="nofollow" target="_blank" title=""&gt;StackOver Flow&lt;/a&gt;）。所以 Ruby 编译的时候就无法找到 OpenSSL 库。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;解决方法&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;用 homebrew 安装 OpenSSL，安装时指定 OpenSSL 库的位置。我用的是 rbenv，最后的命令如下：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/local/opt/openssl rbenv install 2.3.3
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id="2. Nokogiri 编译不通过，提示 Running 'compile' for libxml2 2.9.4... ERROR"&gt;2. Nokogiri 编译不通过，提示 &lt;code&gt;Running 'compile' for libxml2 2.9.4... ERROR&lt;/code&gt;
&lt;/h4&gt;
&lt;p&gt;详细的错误信息：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Running 'compile' for libxml2 2.9.4... ERROR, review '/Users/austin/.gem/ruby/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/tmp/x86_64-apple-darwin15.3.0/ports/libxml2/2.9.4/compile.log' to see what happened. Last lines are:
========================================================================
    unsigned short* in = (unsigned short*) inb;
                         ^~~~~~~~~~~~~~~~~~~~~
encoding.c:815:27: warning: cast from 'unsigned char *' to 'unsigned short *' increases required alignment from 1 to 2 [-Wcast-align]
    unsigned short* out = (unsigned short*) outb;
                          ^~~~~~~~~~~~~~~~~~~~~~
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nokogiri 在试图编译自己下载的 &lt;code&gt;libxml2&lt;/code&gt; 时出错了，后来搜索到了一个 &lt;a href="https://github.com/sparklemotion/nokogiri/issues/1483" rel="nofollow" target="_blank" title=""&gt;Issue&lt;/a&gt;，跟我遇到的状况是一样的。&lt;/p&gt;

&lt;p&gt;原因就是通过 homebrew 安装 xz，会同时安装一个包 &lt;code&gt;liblzma&lt;/code&gt;，它会覆盖掉系统默认的包。Nokogiri 使用这个包编译的时候就会出错。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;解决方法&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;方法 1： &lt;code&gt;brew unlink xz&lt;/code&gt; 然后再安装 Nokogiri。因为 xz 是很多软件的依赖（比如 ag），所以卸载还比较麻烦。安装前 &lt;code&gt;unlink&lt;/code&gt; 一下就好，安装完再 &lt;code&gt;link&lt;/code&gt; 回来。&lt;/p&gt;

&lt;p&gt;方法 2： &lt;code&gt;gem install nokogiri --use-system-libraries&lt;/code&gt; 使用系统包安装。&lt;/p&gt;
&lt;h4 id="3. Rails 工程更改文件后，文件监控系统报错： fsevent: running worker failed: wrong number of arguments (given 2, expected 1)"&gt;3. Rails 工程更改文件后，文件监控系统报错： &lt;code&gt;fsevent: running worker failed: wrong number of arguments (given 2, expected 1)&lt;/code&gt;
&lt;/h4&gt;
&lt;p&gt;详细的错误信息：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;E, [2017-06-30T12:58:08.490986 #14782] ERROR -- : fsevent: running worker failed: wrong number of arguments (given 2, expected 1):/Users/w11th/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/listen-3.0.8/lib/listen/adapter/base.rb:41:in `block (2 levels) in configure'
/Users/w11th/.rbenv/versions/2.4.1/gemsets/rails5.0/gems/rb-fsevent-0.10.1/lib/rb-fsevent/fsevent.rb:75:in `run'
/Users/w11th/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/listen-3.0.8/lib/listen/adapter/darwin.rb:68:in `_run_worker'
/Users/w11th/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/listen-3.0.8/lib/listen/adapter/darwin.rb:77:in `block (2 levels) in _run_workers_in_background'
/Users/w11th/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/listen-3.0.8/lib/listen/internals/thread_pool.rb:6:in `block in add' called from: /Users/w11th/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/listen-3.0.8/lib/listen/adapter/darwin.rb:67:in `_run_worker'
/Users/w11th/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/listen-3.0.8/lib/listen/adapter/darwin.rb:77:in `block (2 levels) in _run_workers_in_background'
/Users/w11th/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/listen-3.0.8/lib/listen/internals/thread_pool.rb:6:in `block in add'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;通过 Google 大法找到了相关的 &lt;a href="https://github.com/guard/listen/issues/431" rel="nofollow" target="_blank" title=""&gt;Issue&lt;/a&gt;。&lt;code&gt;listen&lt;/code&gt; 这个 gem 对 &lt;code&gt;fb-fsevent&lt;/code&gt; 的限定是 &lt;code&gt;'~&amp;gt; 0.9', '&amp;gt;= 0.9.4'&lt;/code&gt;，而最新版本的 &lt;code&gt;rb-fsevent&lt;/code&gt; 是 &lt;code&gt;0.10.0&lt;/code&gt;，这个版本目前有问题。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;解决方法&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;在新的 &lt;code&gt;listen&lt;/code&gt; 更新前在 Gemfile 里指定 &lt;code&gt;rb-fsevent&lt;/code&gt; 版本&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem "rb-fsevent", "0.9.8"
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>w11th</author>
      <pubDate>Fri, 30 Jun 2017 13:31:38 +0800</pubDate>
      <link>https://ruby-china.org/topics/33364</link>
      <guid>https://ruby-china.org/topics/33364</guid>
    </item>
    <item>
      <title>使用 ruby-china 的镜像源无法 update 到最新版本</title>
      <description>&lt;p&gt;以 &lt;code&gt;nokogir&lt;/code&gt; 为例，最新的版本是 &lt;code&gt;1.8.0&lt;/code&gt;，但是执行 &lt;code&gt;gem update&lt;/code&gt; 无法更新到最新版本。执行 &lt;code&gt;gem install&lt;/code&gt; 就可以安装最新版本。&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[5] pry(main)&amp;gt; Gem::SpecFetcher.fetcher.search_for_dependency Gem::Dependency.new 'nokogiri'
=&amp;gt; [[[#&amp;lt;Gem::NameTuple nokogiri, 1.7.1, ruby&amp;gt;, [Remote: https://gems.ruby-china.org API URI: https://gems.ruby-china.org]],
  [#&amp;lt;Gem::NameTuple nokogiri, 1.8.0, ruby&amp;gt;, [Remote: https://rubygems.org/ API URI: https://api.rubygems.org/]]],
 [#&amp;lt;Gem::PlatformMismatch:0x007f8ed9091720
   @name="nokogiri",
   @platforms=["x86-mswin32-60", "x86-mingw32", "x64-mingw32", "java", "x86-mswin32", "x64-mingw32", "x86-mswin32-60", "x86-mswin32", "java", "x86-mingw32"],
   @version=Gem::Version.new("1.6.1")&amp;gt;]]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;同样的接口 &lt;code&gt;rubygems.org&lt;/code&gt; 返回的是最新版本，&lt;code&gt;gems.ruby-china.org&lt;/code&gt; 要旧一些。&lt;/p&gt;</description>
      <author>w11th</author>
      <pubDate>Wed, 14 Jun 2017 14:32:31 +0800</pubDate>
      <link>https://ruby-china.org/topics/33230</link>
      <guid>https://ruby-china.org/topics/33230</guid>
    </item>
  </channel>
</rss>
