Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未能生成gem本机扩展-解决方案_Ruby On Rails_Ruby_Gem_Bundler - Fatal编程技术网

Ruby on rails 未能生成gem本机扩展-解决方案

Ruby on rails 未能生成gem本机扩展-解决方案,ruby-on-rails,ruby,gem,bundler,Ruby On Rails,Ruby,Gem,Bundler,当我安装gem时,它会失败,出现错误错误:无法构建gem本机扩展。 例如,当我尝试在新服务器上安装gems-json、eventmachine、mysql2时,几乎总是失败 注意:这是一个QA类型的问题,也就是说,请参阅下面我提出的解决方案或加入讨论。此错误通常发生在新创建的服务器上,因此,该错误自然意味着缺少某些依赖项 “转折点”是,错误本身通常会告诉我们缺少哪些依赖项,但我们浏览了一下描述,并尝试谷歌“未能构建gem…”。最好先检查错误输出 例如,在尝试在新机器上安装gem'json'时,让

当我安装gem
时,它会失败,出现错误
错误:无法构建gem本机扩展。

例如,当我尝试在新服务器上安装gems-json、eventmachine、mysql2时,几乎总是失败


注意:这是一个QA类型的问题,也就是说,请参阅下面我提出的解决方案或加入讨论。

此错误通常发生在新创建的服务器上,因此,该错误自然意味着缺少某些依赖项

“转折点”是,错误本身通常会告诉我们缺少哪些依赖项,但我们浏览了一下描述,并尝试谷歌“未能构建gem…”。最好先检查错误输出

例如,在尝试在新机器上安装gem'json'时,让我们看看输出:

user@server:~$ gem install json -v '1.8.3'
Fetching: json-1.8.3.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    .../.rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20151204-22068-1ek4f2f.rb extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling generator.c
linking shared-object json/ext/generator.so
/usr/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
make: *** [generator.so] Error 1

make failed, exit code 2

Gem files will remain installed in .../.rvm/gems/ruby-2.2.2/gems/json-1.8.3 for inspection.
Results logged to .../.rvm/gems/ruby-2.2.2/extensions/x86_64-linux/2.2.0/json-1.8.3/gem_make.out
检查错误后,您可以看到缺少的内容:

/usr/bin/ld: cannot find -lgmp
那么什么是lgmp?让我描述一下我的尝试和错误的道路,同时找出它。在谷歌搜索了一会儿后,我发现
lgmp
中的
l
代表库,而GMP是一个尚未安装在我的机器上的C库。我的下一个谷歌查询是“安装gmp ubuntu”,这让我安装了libgmp3 dev,问题就解决了

现在,让我们看看在新服务器上安装mysql2时的输出:

user@server:~$ gem install mysql2 -v '0.3.20'
Fetching: mysql2-0.3.20.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    .../.rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20151204-9782-1eobqf2.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... no
-----
libmysqlclient is missing. Trying again with extra runtime libraries...
-----
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
-----
libmysqlclient is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.
# SNIP
同样,在仔细查看时,您可以看到
libmysqlclient丢失了
,该错误甚至提供了最明显的解决方案:
您可能需要“apt get install libmysqlclient dev”或“yum install mysql devel”,然后重试。


我希望这将帮助开发人员更快地解决此类错误,而不必为每一个特定的gem故障(通常不会带来任何结果)搜索谷歌。

您可以到终端并将其写下来
sudo apt get install libmysqlclient dev

我希望这对你有帮助